mark game as synced -- having messages -- if the only messages to

arrive had to do with chat.  Clear that flag when opening game, not
when saving it.
This commit is contained in:
Andy2 2011-02-18 18:06:27 -08:00
parent 94a7361e99
commit 31348d978e
5 changed files with 38 additions and 10 deletions

View file

@ -1105,6 +1105,8 @@ public class BoardActivity extends XWActivity {
== Configuration.ORIENTATION_LANDSCAPE; == Configuration.ORIENTATION_LANDSCAPE;
m_toolbar.orientChanged( isLandscape ); m_toolbar.orientChanged( isLandscape );
populateToolbar(); populateToolbar();
DBUtils.setHasMsgs( m_path, false );
} }
} // loadGame } // loadGame

View file

@ -187,7 +187,6 @@ public class DBUtils {
values.put( DBHelper.DICTLANG, summary.dictLang ); values.put( DBHelper.DICTLANG, summary.dictLang );
values.put( DBHelper.DICTNAME, summary.dictName ); values.put( DBHelper.DICTNAME, summary.dictName );
values.put( DBHelper.GAME_OVER, summary.gameOver ); values.put( DBHelper.GAME_OVER, summary.gameOver );
values.put( DBHelper.HASMSGS, 0 );
if ( null != summary.scores ) { if ( null != summary.scores ) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
@ -237,14 +236,14 @@ public class DBUtils {
return result; return result;
} }
public static void setHasMsgs( String relayID ) public static void setHasMsgs( String path, boolean hasMsgs )
{ {
synchronized( s_dbHelper ) { synchronized( s_dbHelper ) {
SQLiteDatabase db = s_dbHelper.getWritableDatabase(); SQLiteDatabase db = s_dbHelper.getWritableDatabase();
String selection = DBHelper.RELAYID + "=\'" + relayID + "\'"; String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put( DBHelper.HASMSGS, 1 ); values.put( DBHelper.HASMSGS, hasMsgs ? 1 : 0 );
int result = db.update( DBHelper.TABLE_NAME_SUM, int result = db.update( DBHelper.TABLE_NAME_SUM,
values, selection, null ); values, selection, null );

View file

@ -94,9 +94,24 @@ public class GameUtils {
private static GameSummary summarizeAndClose( Context context, private static GameSummary summarizeAndClose( Context context,
String path, String path,
int gamePtr, CurGameInfo gi ) int gamePtr, CurGameInfo gi )
{
return summarizeAndClose( context, path, gamePtr, gi, null );
}
private static GameSummary summarizeAndClose( Context context,
String path,
int gamePtr, CurGameInfo gi,
FeedUtilsImpl feedImpl )
{ {
GameSummary summary = new GameSummary( gi ); GameSummary summary = new GameSummary( gi );
XwJNI.game_summarize( gamePtr, summary ); XwJNI.game_summarize( gamePtr, summary );
if ( null != feedImpl ) {
if ( feedImpl.m_gotMsg ) {
summary.msgsPending = true;
}
}
DBUtils.saveSummary( context, path, summary ); DBUtils.saveSummary( context, path, summary );
XwJNI.game_dispose( gamePtr ); XwJNI.game_dispose( gamePtr );
@ -381,15 +396,22 @@ public class GameUtils {
private static class FeedUtilsImpl extends UtilCtxtImpl { private static class FeedUtilsImpl extends UtilCtxtImpl {
private Context m_context; private Context m_context;
private String m_path; private String m_path;
public boolean m_gotMsg;
public FeedUtilsImpl( Context context, String path ) public FeedUtilsImpl( Context context, String path )
{ {
m_context = context; m_context = context;
m_path = path; m_path = path;
m_gotMsg = false;
} }
public void showChat( String msg ) public void showChat( String msg )
{ {
DBUtils.appendChatHistory( m_context, m_path, msg, false ); DBUtils.appendChatHistory( m_context, m_path, msg, false );
m_gotMsg = true;
}
public void turnChanged()
{
m_gotMsg = true;
} }
} }
@ -401,9 +423,8 @@ public class GameUtils {
if ( null != path ) { if ( null != path ) {
int gamePtr = XwJNI.initJNI(); int gamePtr = XwJNI.initJNI();
CurGameInfo gi = new CurGameInfo( context ); CurGameInfo gi = new CurGameInfo( context );
loadMakeGame( context, gamePtr, gi, FeedUtilsImpl feedImpl = new FeedUtilsImpl( context, path );
new FeedUtilsImpl(context, path), loadMakeGame( context, gamePtr, gi, feedImpl, path );
path );
for ( byte[] msg : msgs ) { for ( byte[] msg : msgs ) {
draw = XwJNI.game_receiveMessage( gamePtr, msg ) || draw; draw = XwJNI.game_receiveMessage( gamePtr, msg ) || draw;
@ -412,7 +433,11 @@ public class GameUtils {
// update gi to reflect changes due to messages // update gi to reflect changes due to messages
XwJNI.game_getGi( gamePtr, gi ); XwJNI.game_getGi( gamePtr, gi );
saveGame( context, gamePtr, gi, path, false ); saveGame( context, gamePtr, gi, path, false );
summarizeAndClose( context, path, gamePtr, gi ); summarizeAndClose( context, path, gamePtr, gi, feedImpl );
if ( feedImpl.m_gotMsg ) {
DBUtils.setHasMsgs( path, true );
draw = true;
}
} }
Utils.logf( "feedMessages=>%s", draw?"true":"false" ); Utils.logf( "feedMessages=>%s", draw?"true":"false" );
return draw; return draw;

View file

@ -195,7 +195,6 @@ public class NetUtils {
if ( null != msgs[ii] ) { if ( null != msgs[ii] ) {
if( GameUtils.feedMessages( context, ids[ii], if( GameUtils.feedMessages( context, ids[ii],
msgs[ii] ) ) { msgs[ii] ) ) {
DBUtils.setHasMsgs( ids[ii] );
idsWMsgs.add( ids[ii] ); idsWMsgs.add( ids[ii] );
} }
} }

View file

@ -51,10 +51,13 @@ public class GameSummary {
private CurGameInfo m_gi; private CurGameInfo m_gi;
public GameSummary(){} public GameSummary(){
msgsPending = false;
}
public GameSummary( CurGameInfo gi ) public GameSummary( CurGameInfo gi )
{ {
super();
nPlayers = gi.nPlayers; nPlayers = gi.nPlayers;
dictLang = gi.dictLang; dictLang = gi.dictLang;
dictName = gi.dictName; dictName = gi.dictName;