From 1669687f191b543ef164fb11637502c32a143a39 Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 9 Sep 2013 19:31:17 -0700 Subject: [PATCH 1/2] wrap a bit more chat code in test so java can leave it out --- .../org/eehouse/android/xw4/ChatActivity.java | 47 +++++++------ .../src/org/eehouse/android/xw4/DBUtils.java | 67 ++++++++++--------- 2 files changed, 64 insertions(+), 50 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java index a76f94ba3..07cd83c01 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java @@ -40,32 +40,39 @@ public class ChatActivity extends XWActivity implements View.OnClickListener { @Override public void onCreate( Bundle savedInstanceState ) { - super.onCreate( savedInstanceState ); + if ( XWApp.CHAT_SUPPORTED ) { + super.onCreate( savedInstanceState ); - setContentView( R.layout.chat ); + setContentView( R.layout.chat ); - m_rowid = getIntent().getLongExtra( GameUtils.INTENT_KEY_ROWID, -1 ); + m_rowid = getIntent().getLongExtra( GameUtils.INTENT_KEY_ROWID, -1 ); - DBUtils.HistoryPair[] pairs = DBUtils.getChatHistory( this, m_rowid ); - if ( null != pairs ) { - LinearLayout layout = (LinearLayout)findViewById( R.id.chat_history ); - LayoutInflater factory = LayoutInflater.from( this ); + DBUtils.HistoryPair[] pairs = DBUtils.getChatHistory( this, m_rowid ); + if ( null != pairs ) { + LinearLayout layout = (LinearLayout) + findViewById( R.id.chat_history ); + LayoutInflater factory = LayoutInflater.from( this ); - for ( DBUtils.HistoryPair pair : pairs ) { - TextView view = - (TextView)factory.inflate( pair.sourceLocal - ? R.layout.chat_history_local - : R.layout.chat_history_remote, - null ); - view.setText( pair.msg ); - layout.addView( view ); + for ( DBUtils.HistoryPair pair : pairs ) { + TextView view = (TextView)factory + .inflate( pair.sourceLocal + ? R.layout.chat_history_local + : R.layout.chat_history_remote, + null ); + view.setText( pair.msg ); + layout.addView( view ); + } } + + ((Button)findViewById( R.id.send_button )) + .setOnClickListener( this ); + + setTitle( getString( R.string.chat_titlef, + GameUtils.getName( this, m_rowid ) ) ); + } else { + // Should really assert.... + finish(); } - - ((Button)findViewById( R.id.send_button )).setOnClickListener( this ); - - setTitle( getString( R.string.chat_titlef, - GameUtils.getName( this, m_rowid ) ) ); } @Override diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java index d375a45c6..e6d017677 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -847,15 +847,17 @@ public class DBUtils { public static HistoryPair[] getChatHistory( Context context, long rowid ) { HistoryPair[] result = null; - final String localPrefix = context.getString( R.string.chat_local_id ); - String history = getChatHistoryStr( context, rowid ); - if ( null != history ) { - String[] msgs = history.split( "\n" ); - result = new HistoryPair[msgs.length]; - for ( int ii = 0; ii < result.length; ++ii ) { - String msg = msgs[ii]; - boolean isLocal = msg.startsWith( localPrefix ); - result[ii] = new HistoryPair( msg, isLocal ); + if ( XWApp.CHAT_SUPPORTED ) { + final String localPrefix = context.getString( R.string.chat_local_id ); + String history = getChatHistoryStr( context, rowid ); + if ( null != history ) { + String[] msgs = history.split( "\n" ); + result = new HistoryPair[msgs.length]; + for ( int ii = 0; ii < result.length; ++ii ) { + String msg = msgs[ii]; + boolean isLocal = msg.startsWith( localPrefix ); + result[ii] = new HistoryPair( msg, isLocal ); + } } } return result; @@ -1107,21 +1109,24 @@ public class DBUtils { private static String getChatHistoryStr( Context context, long rowid ) { String result = null; - initDB( context ); - synchronized( s_dbHelper ) { - SQLiteDatabase db = s_dbHelper.getReadableDatabase(); + if ( XWApp.CHAT_SUPPORTED ) { + initDB( context ); + synchronized( s_dbHelper ) { + SQLiteDatabase db = s_dbHelper.getReadableDatabase(); - String[] columns = { DBHelper.CHAT_HISTORY }; - String selection = String.format( ROW_ID_FMT, rowid ); - Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns, - selection, null, null, null, null ); - if ( 1 == cursor.getCount() && cursor.moveToFirst() ) { - result = - cursor.getString( cursor - .getColumnIndex(DBHelper.CHAT_HISTORY)); + String[] columns = { DBHelper.CHAT_HISTORY }; + String selection = String.format( ROW_ID_FMT, rowid ); + Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns, + selection, null, null, null, null ); + if ( 1 == cursor.getCount() && cursor.moveToFirst() ) { + result = + cursor.getString( cursor + .getColumnIndex(DBHelper + .CHAT_HISTORY)); + } + cursor.close(); + db.close(); } - cursor.close(); - db.close(); } return result; } @@ -1129,16 +1134,18 @@ public class DBUtils { public static void appendChatHistory( Context context, long rowid, String msg, boolean local ) { - Assert.assertNotNull( msg ); - int id = local ? R.string.chat_local_id : R.string.chat_other_id; - msg = context.getString( id ) + msg; + if ( XWApp.CHAT_SUPPORTED ) { + Assert.assertNotNull( msg ); + int id = local ? R.string.chat_local_id : R.string.chat_other_id; + msg = context.getString( id ) + msg; - String cur = getChatHistoryStr( context, rowid ); - if ( null != cur ) { - msg = cur + "\n" + msg; + String cur = getChatHistoryStr( context, rowid ); + if ( null != cur ) { + msg = cur + "\n" + msg; + } + + saveChatHistory( context, rowid, msg ); } - - saveChatHistory( context, rowid, msg ); } // appendChatHistory public static void clearChatHistory( Context context, long rowid ) From a1300e9fe24b3e0d5c8ba49c35cea0c4185ae861 Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 9 Sep 2013 19:45:09 -0700 Subject: [PATCH 2/2] can't use & in the changes file --- xwords4/android/XWords4/res/raw/changes | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xwords4/android/XWords4/res/raw/changes b/xwords4/android/XWords4/res/raw/changes index 7019c3ddc..c64504047 100644 --- a/xwords4/android/XWords4/res/raw/changes +++ b/xwords4/android/XWords4/res/raw/changes @@ -12,8 +12,8 @@
  • Fix menu missing on some tablets
  • Disable in-game Chat feature. (It has bugs that cause games to - stop syncing moves. I&ll fix eventually. Let me know if you - use this feature and I&ll up the priority.)
  • + stop syncing moves. I'll fix eventually. Let me know if you + use this feature and I'll up the priority.)
  • Fix crash triggered by resignation