From 9818a29f8610bf55b6304427448aa4f48f787174 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 24 Feb 2011 07:09:41 -0800 Subject: [PATCH] Use bitvector (an int) instead of an enum for flags noting what arrived in the background. When notification that game's over arrives, add it to the flags, then on game open show the game over dialog (in addition to raising chat activity and possibly showing recent move.) --- .../eehouse/android/xw4/BoardActivity.java | 17 +++++----- .../src/org/eehouse/android/xw4/DBUtils.java | 16 ++++----- .../eehouse/android/xw4/GameListAdapter.java | 2 +- .../org/eehouse/android/xw4/GameUtils.java | 33 +++++++++++++++---- .../eehouse/android/xw4/jni/GameSummary.java | 11 +++++-- 5 files changed, 50 insertions(+), 29 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java index c13daa152..432be8fd6 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -1091,16 +1091,15 @@ public class BoardActivity extends XWActivity { m_toolbar.orientChanged( isLandscape ); populateToolbar(); - - switch( DBUtils.getHasMsgs( m_path ) ) { - case MSG_LEVEL_CHAT: + int flags = DBUtils.getMsgFlags( m_path ); + if ( 0 != (GameSummary.MSG_FLAGS_CHAT & flags) ) { startChatActivity(); - // FALLTHRU - case MSG_LEVEL_TURN: - // clear it if non-NONE - DBUtils.setHasMsgs( m_path, - GameSummary.MsgLevel.MSG_LEVEL_NONE ); - break; + } + if ( 0 != (GameSummary.MSG_FLAGS_GAMEOVER & flags) ) { + m_jniThread.handle( JNIThread.JNICmd.CMD_POST_OVER ); + } + if ( 0 != flags ) { + DBUtils.setMsgFlags( m_path, GameSummary.MSG_FLAGS_NONE ); } } } // loadGame 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 c6347dc4d..188ddc342 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -158,8 +158,7 @@ public class DBUtils { col = cursor.getColumnIndex( DBHelper.HASMSGS ); if ( col >= 0 ) { - summary.pendingMsgLevel = - GameSummary.MsgLevel.values()[cursor.getInt( col )]; + summary.pendingMsgLevel = cursor.getInt( col ); } } cursor.close(); @@ -244,14 +243,14 @@ public class DBUtils { return result; } - public static void setHasMsgs( String path, GameSummary.MsgLevel level ) + public static void setMsgFlags( String path, int flags ) { synchronized( s_dbHelper ) { SQLiteDatabase db = s_dbHelper.getWritableDatabase(); String selection = DBHelper.FILE_NAME + "=\"" + path + "\""; ContentValues values = new ContentValues(); - values.put( DBHelper.HASMSGS, level.ordinal() ); + values.put( DBHelper.HASMSGS, flags ); int result = db.update( DBHelper.TABLE_NAME_SUM, values, selection, null ); @@ -261,9 +260,9 @@ public class DBUtils { } } - public static GameSummary.MsgLevel getHasMsgs( String path ) + public static int getMsgFlags( String path ) { - GameSummary.MsgLevel result = GameSummary.MsgLevel.MSG_LEVEL_NONE; + int flags = GameSummary.MSG_FLAGS_NONE; synchronized( s_dbHelper ) { SQLiteDatabase db = s_dbHelper.getReadableDatabase(); String selection = DBHelper.FILE_NAME + "=\"" + path + "\""; @@ -271,14 +270,13 @@ public class DBUtils { Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns, selection, null, null, null, null ); if ( 1 == cursor.getCount() && cursor.moveToFirst() ) { - int level = cursor.getInt( cursor + flags = cursor.getInt( cursor .getColumnIndex(DBHelper.HASMSGS)); - result = GameSummary.MsgLevel.values()[level]; } cursor.close(); db.close(); } - return result; + return flags; } public static String getPathFor( Context context, String relayID ) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java index 370b12df2..b206f19b4 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java @@ -108,7 +108,7 @@ public class GameListAdapter extends XWListAdapter { View marker = layout.findViewById( R.id.msg_marker ); marker.setVisibility( summary.pendingMsgLevel - == GameSummary.MsgLevel.MSG_LEVEL_NONE + == GameSummary.MSG_FLAGS_NONE ? View.GONE : View.VISIBLE ); m_viewsCache.put( path, layout ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java index da433756b..a32791c30 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -108,9 +108,13 @@ public class GameUtils { if ( null != feedImpl ) { if ( feedImpl.m_gotChat ) { - summary.pendingMsgLevel = GameSummary.MsgLevel.MSG_LEVEL_CHAT; - } else if ( feedImpl.m_gotMsg ) { - summary.pendingMsgLevel = GameSummary.MsgLevel.MSG_LEVEL_TURN; + summary.pendingMsgLevel |= GameSummary.MSG_FLAGS_CHAT; + } + if ( feedImpl.m_gotMsg ) { + summary.pendingMsgLevel |= GameSummary.MSG_FLAGS_TURN; + } + if ( feedImpl.m_gameOver ) { + summary.pendingMsgLevel |= GameSummary.MSG_FLAGS_GAMEOVER; } } @@ -405,12 +409,14 @@ public class GameUtils { private String m_path; public boolean m_gotMsg; public boolean m_gotChat; + public boolean m_gameOver; public FeedUtilsImpl( Context context, String path ) { m_context = context; m_path = path; m_gotMsg = false; + m_gameOver = false; } public void showChat( String msg ) { @@ -421,6 +427,11 @@ public class GameUtils { { m_gotMsg = true; } + + public void notifyGameOver() + { + m_gameOver = true; + } } public static boolean feedMessages( Context context, String relayID, @@ -442,12 +453,20 @@ public class GameUtils { XwJNI.game_getGi( gamePtr, gi ); saveGame( context, gamePtr, gi, path, false ); summarizeAndClose( context, path, gamePtr, gi, feedImpl ); + + int flags = GameSummary.MSG_FLAGS_NONE; if ( feedImpl.m_gotChat ) { - DBUtils.setHasMsgs( path, GameSummary.MsgLevel.MSG_LEVEL_CHAT ); - draw = true; - } else if ( feedImpl.m_gotMsg ) { - DBUtils.setHasMsgs( path, GameSummary.MsgLevel.MSG_LEVEL_TURN ); + flags |= GameSummary.MSG_FLAGS_CHAT; + } + if ( feedImpl.m_gotMsg ) { + flags |= GameSummary.MSG_FLAGS_TURN; + } + if ( feedImpl.m_gameOver ) { + flags |= GameSummary.MSG_FLAGS_GAMEOVER; + } + if ( GameSummary.MSG_FLAGS_NONE != flags ) { draw = true; + DBUtils.setMsgFlags( path, flags ); } } Utils.logf( "feedMessages=>%s", draw?"true":"false" ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java index 2dfd96032..76d217338 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java @@ -29,7 +29,12 @@ import org.eehouse.android.xw4.R; * in CurGameInfo */ public class GameSummary { - public enum MsgLevel { MSG_LEVEL_NONE, MSG_LEVEL_TURN, MSG_LEVEL_CHAT }; + + public static final int MSG_FLAGS_NONE = 0; + public static final int MSG_FLAGS_TURN = 1; + public static final int MSG_FLAGS_CHAT = 2; + public static final int MSG_FLAGS_GAMEOVER = 4; + public static final int MSG_FLAGS_ALL = 7; public int nMoves; public int turn; @@ -44,7 +49,7 @@ public class GameSummary { public String roomName; public String relayID; public int seed; - public MsgLevel pendingMsgLevel; + public int pendingMsgLevel; public long modtime; public int dictLang; @@ -55,7 +60,7 @@ public class GameSummary { private CurGameInfo m_gi; public GameSummary(){ - pendingMsgLevel = MsgLevel.MSG_LEVEL_NONE; + pendingMsgLevel = 0; } public GameSummary( CurGameInfo gi )