mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-06 05:24:46 +01:00
add a clear-history menu to chat
This commit is contained in:
parent
b3ffb4895b
commit
c271cb2fdd
4 changed files with 51 additions and 2 deletions
7
xwords4/android/XWords4/res/menu/chat_menu.xml
Normal file
7
xwords4/android/XWords4/res/menu/chat_menu.xml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:id="@+id/chat_menu_clear"
|
||||||
|
android:title="@string/chat_menu_clear"
|
||||||
|
/>
|
||||||
|
</menu>
|
|
@ -402,6 +402,7 @@
|
||||||
<string name="chat_local_id">Me: </string>
|
<string name="chat_local_id">Me: </string>
|
||||||
<string name="chat_other_id">Not me: </string>
|
<string name="chat_other_id">Not me: </string>
|
||||||
<string name="chat_send">Send</string>
|
<string name="chat_send">Send</string>
|
||||||
|
<string name="chat_menu_clear">Clear history</string>
|
||||||
|
|
||||||
<string name="notify_title">Moves made</string>
|
<string name="notify_title">Moves made</string>
|
||||||
<string name="notify_body">New game moves have arrived</string>
|
<string name="notify_body">New game moves have arrived</string>
|
||||||
|
|
|
@ -28,6 +28,9 @@ import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.MenuInflater;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
public class ChatActivity extends XWActivity implements View.OnClickListener {
|
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 );
|
((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
|
@Override
|
||||||
public void onClick( View view )
|
public void onClick( View view )
|
||||||
{
|
{
|
||||||
|
|
|
@ -533,13 +533,28 @@ public class DBUtils {
|
||||||
msg = cur + "\n" + msg;
|
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 );
|
initDB( context );
|
||||||
synchronized( s_dbHelper ) {
|
synchronized( s_dbHelper ) {
|
||||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||||
|
|
||||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||||
ContentValues values = new ContentValues();
|
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();
|
long timestamp = new Date().getTime();
|
||||||
values.put( DBHelper.LASTPLAY_TIME, timestamp );
|
values.put( DBHelper.LASTPLAY_TIME, timestamp );
|
||||||
|
@ -548,7 +563,7 @@ public class DBUtils {
|
||||||
values, selection, null );
|
values, selection, null );
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
} // appendChatHistory
|
}
|
||||||
|
|
||||||
private static String[] parsePlayers( final String players, int nPlayers ){
|
private static String[] parsePlayers( final String players, int nPlayers ){
|
||||||
String[] result = null;
|
String[] result = null;
|
||||||
|
|
Loading…
Reference in a new issue