mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-20 22:26:54 +01:00
preserve unsent chats across activity reload. Use pairs table rather
than creating a new one.
This commit is contained in:
parent
f05375273c
commit
9dc50c9aa8
2 changed files with 41 additions and 0 deletions
|
@ -138,6 +138,10 @@ public class ChatDelegate extends DelegateBase {
|
|||
finish();
|
||||
} else {
|
||||
s_visibleThis = this;
|
||||
String curMsg = DBUtils.getCurChat( m_activity, m_rowid, m_curPlayer );
|
||||
if ( null != curMsg && 0 < curMsg.length() ) {
|
||||
m_edit.setText( curMsg );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,6 +152,10 @@ public class ChatDelegate extends DelegateBase {
|
|||
m_jniThreadRef.release();
|
||||
}
|
||||
s_visibleThis = null;
|
||||
|
||||
String curText = m_edit.getText().toString();
|
||||
DBUtils.setCurChat( m_activity, m_rowid, m_curPlayer, curText );
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
|
|
@ -1150,6 +1150,8 @@ public class DBUtils {
|
|||
|
||||
// Delete chats too -- same sel as for invites
|
||||
db.delete( DBHelper.TABLE_NAME_CHAT, selInvites, null );
|
||||
|
||||
deleteCurChatsSync( db, rowid );
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
@ -1300,6 +1302,31 @@ public class DBUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static String formatCurChatKey( long rowid ) {
|
||||
return formatCurChatKey( rowid, -1 );
|
||||
}
|
||||
|
||||
private static String formatCurChatKey( long rowid, int player ) {
|
||||
String playerMatch = 0 <= player ? String.format( "%d", player ) : "%";
|
||||
String result = String.format("<<chat/%d/%s>>", rowid, playerMatch );
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getCurChat( Context context, long rowid, int player ) {
|
||||
String key = formatCurChatKey( rowid, player );
|
||||
return getStringFor( context, key, "" );
|
||||
}
|
||||
|
||||
public static void setCurChat( Context context, long rowid, int player, String text ) {
|
||||
String key = formatCurChatKey( rowid, player );
|
||||
setStringFor( context, key, text );
|
||||
}
|
||||
|
||||
private static void deleteCurChatsSync( SQLiteDatabase db, long rowid ) {
|
||||
String like = formatCurChatKey( rowid );
|
||||
delStringsLikeSync( db, like );
|
||||
}
|
||||
|
||||
public static class NeedsNagInfo {
|
||||
public long m_rowid;
|
||||
public long m_nextNag;
|
||||
|
@ -2304,6 +2331,12 @@ public class DBUtils {
|
|||
}
|
||||
}
|
||||
|
||||
private static void delStringsLikeSync( SQLiteDatabase db, String like )
|
||||
{
|
||||
String selection = String.format( "%s LIKE '%s'", DBHelper.KEY, like );
|
||||
db.delete( DBHelper.TABLE_NAME_PAIRS, selection, null );
|
||||
}
|
||||
|
||||
private static String getStringForSync( SQLiteDatabase db, String key, String dflt )
|
||||
{
|
||||
String selection = String.format( "%s = '%s'", DBHelper.KEY, key );
|
||||
|
|
Loading…
Reference in a new issue