From c271cb2fdd3609f2e251147b7a37f0a235b495be Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 17 Feb 2011 07:14:58 -0800 Subject: [PATCH] add a clear-history menu to chat --- .../android/XWords4/res/menu/chat_menu.xml | 7 +++++ .../android/XWords4/res/values/strings.xml | 1 + .../org/eehouse/android/xw4/ChatActivity.java | 26 +++++++++++++++++++ .../src/org/eehouse/android/xw4/DBUtils.java | 19 ++++++++++++-- 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 xwords4/android/XWords4/res/menu/chat_menu.xml diff --git a/xwords4/android/XWords4/res/menu/chat_menu.xml b/xwords4/android/XWords4/res/menu/chat_menu.xml new file mode 100644 index 000000000..9ce17dcd1 --- /dev/null +++ b/xwords4/android/XWords4/res/menu/chat_menu.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 834bcaf98..02af1b2e1 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -402,6 +402,7 @@ Me: Not me: Send + Clear history Moves made New game moves have arrived 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 bcab62a61..e61fe4285 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ChatActivity.java @@ -28,6 +28,9 @@ import android.widget.EditText; import android.widget.TextView; import android.view.LayoutInflater; import android.view.View; +import android.view.Menu; +import android.view.MenuItem; +import android.view.MenuInflater; import android.widget.LinearLayout; public class ChatActivity extends XWActivity implements View.OnClickListener { @@ -64,6 +67,29 @@ public class ChatActivity extends XWActivity implements View.OnClickListener { ((Button)findViewById( R.id.send_button )).setOnClickListener( this ); } + @Override + public boolean onCreateOptionsMenu( Menu menu ) + { + MenuInflater inflater = getMenuInflater(); + inflater.inflate( R.menu.chat_menu, menu ); + return true; + } + + @Override + public boolean onOptionsItemSelected( MenuItem item ) + { + boolean handled = R.id.chat_menu_clear == item.getItemId(); + if ( handled ) { + DBUtils.clearChatHistory( this, m_path ); + LinearLayout layout = + (LinearLayout)findViewById( R.id.chat_history ); + layout.removeAllViews(); + } else { + handled = super.onOptionsItemSelected( item ); + } + return handled; + } + @Override public void onClick( View view ) { 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 8720c51ee..07e965e31 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -533,13 +533,28 @@ public class DBUtils { msg = cur + "\n" + msg; } + saveChatHistory( context, path, msg ); + } // appendChatHistory + + public static void clearChatHistory( Context context, String path ) + { + saveChatHistory( context, path, null ); + } + + private static void saveChatHistory( Context context, String path, + String history ) + { initDB( context ); synchronized( s_dbHelper ) { SQLiteDatabase db = s_dbHelper.getWritableDatabase(); String selection = DBHelper.FILE_NAME + "=\"" + path + "\""; ContentValues values = new ContentValues(); - values.put( DBHelper.CHAT_HISTORY, msg ); + if ( null != history ) { + values.put( DBHelper.CHAT_HISTORY, history ); + } else { + values.putNull( DBHelper.CHAT_HISTORY ); + } long timestamp = new Date().getTime(); values.put( DBHelper.LASTPLAY_TIME, timestamp ); @@ -548,7 +563,7 @@ public class DBUtils { values, selection, null ); db.close(); } - } // appendChatHistory + } private static String[] parsePlayers( final String players, int nPlayers ){ String[] result = null;