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.)
This commit is contained in:
Andy2 2011-02-24 07:09:41 -08:00
parent 7910aed896
commit 9818a29f86
5 changed files with 50 additions and 29 deletions

View file

@ -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

View file

@ -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 )

View file

@ -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 );
}

View file

@ -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" );

View file

@ -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 )