mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
when launched after chat messages have been received, launch the chat
activity. This requires an enum be stored in the DB instead of a boolean.
This commit is contained in:
parent
31348d978e
commit
27bc89b684
5 changed files with 55 additions and 13 deletions
|
@ -1106,7 +1106,17 @@ public class BoardActivity extends XWActivity {
|
|||
m_toolbar.orientChanged( isLandscape );
|
||||
populateToolbar();
|
||||
|
||||
DBUtils.setHasMsgs( m_path, false );
|
||||
|
||||
switch( DBUtils.getHasMsgs( m_path ) ) {
|
||||
case MSG_LEVEL_CHAT:
|
||||
startChatActivity();
|
||||
// FALLTHRU
|
||||
case MSG_LEVEL_TURN:
|
||||
// clear it if non-NONE
|
||||
DBUtils.setHasMsgs( m_path,
|
||||
GameSummary.MsgLevel.MSG_LEVEL_NONE );
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // loadGame
|
||||
|
||||
|
|
|
@ -152,7 +152,8 @@ public class DBUtils {
|
|||
|
||||
col = cursor.getColumnIndex( DBHelper.HASMSGS );
|
||||
if ( col >= 0 ) {
|
||||
summary.msgsPending = 0 != cursor.getInt( col );
|
||||
summary.pendingMsgLevel =
|
||||
GameSummary.MsgLevel.values()[cursor.getInt( col )];
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
|
@ -236,14 +237,15 @@ public class DBUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static void setHasMsgs( String path, boolean hasMsgs )
|
||||
// 0 means none; 1 just moves; 2 chat
|
||||
public static void setHasMsgs( String path, GameSummary.MsgLevel level )
|
||||
{
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
|
||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.HASMSGS, hasMsgs ? 1 : 0 );
|
||||
values.put( DBHelper.HASMSGS, level.ordinal() );
|
||||
|
||||
int result = db.update( DBHelper.TABLE_NAME_SUM,
|
||||
values, selection, null );
|
||||
|
@ -252,6 +254,26 @@ public class DBUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static GameSummary.MsgLevel getHasMsgs( String path )
|
||||
{
|
||||
GameSummary.MsgLevel result = GameSummary.MsgLevel.MSG_LEVEL_NONE;
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
String selection = DBHelper.FILE_NAME + "=\"" + path + "\"";
|
||||
String[] columns = { DBHelper.HASMSGS };
|
||||
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
|
||||
.getColumnIndex(DBHelper.HASMSGS));
|
||||
result = GameSummary.MsgLevel.values()[level];
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getPathFor( Context context, String relayID )
|
||||
{
|
||||
String result = null;
|
||||
|
|
|
@ -107,8 +107,9 @@ public class GameListAdapter extends XWListAdapter {
|
|||
}
|
||||
|
||||
View marker = layout.findViewById( R.id.msg_marker );
|
||||
marker.setVisibility( summary.msgsPending?
|
||||
View.VISIBLE : View.GONE );
|
||||
marker.setVisibility( summary.pendingMsgLevel
|
||||
== GameSummary.MsgLevel.MSG_LEVEL_NONE
|
||||
? View.GONE : View.VISIBLE );
|
||||
m_viewsCache.put( path, layout );
|
||||
}
|
||||
|
||||
|
|
|
@ -107,8 +107,10 @@ public class GameUtils {
|
|||
XwJNI.game_summarize( gamePtr, summary );
|
||||
|
||||
if ( null != feedImpl ) {
|
||||
if ( feedImpl.m_gotMsg ) {
|
||||
summary.msgsPending = true;
|
||||
if ( feedImpl.m_gotChat ) {
|
||||
summary.pendingMsgLevel = GameSummary.MsgLevel.MSG_LEVEL_CHAT;
|
||||
} else if ( feedImpl.m_gotMsg ) {
|
||||
summary.pendingMsgLevel = GameSummary.MsgLevel.MSG_LEVEL_TURN;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -397,6 +399,7 @@ public class GameUtils {
|
|||
private Context m_context;
|
||||
private String m_path;
|
||||
public boolean m_gotMsg;
|
||||
public boolean m_gotChat;
|
||||
|
||||
public FeedUtilsImpl( Context context, String path )
|
||||
{
|
||||
|
@ -407,7 +410,7 @@ public class GameUtils {
|
|||
public void showChat( String msg )
|
||||
{
|
||||
DBUtils.appendChatHistory( m_context, m_path, msg, false );
|
||||
m_gotMsg = true;
|
||||
m_gotChat = true;
|
||||
}
|
||||
public void turnChanged()
|
||||
{
|
||||
|
@ -434,8 +437,11 @@ public class GameUtils {
|
|||
XwJNI.game_getGi( gamePtr, gi );
|
||||
saveGame( context, gamePtr, gi, path, false );
|
||||
summarizeAndClose( context, path, gamePtr, gi, feedImpl );
|
||||
if ( feedImpl.m_gotMsg ) {
|
||||
DBUtils.setHasMsgs( path, true );
|
||||
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 );
|
||||
draw = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ import org.eehouse.android.xw4.R;
|
|||
* in CurGameInfo
|
||||
*/
|
||||
public class GameSummary {
|
||||
public enum MsgLevel { MSG_LEVEL_NONE, MSG_LEVEL_TURN, MSG_LEVEL_CHAT };
|
||||
|
||||
public int nMoves;
|
||||
public int turn;
|
||||
public int giFlags;
|
||||
|
@ -42,17 +44,18 @@ public class GameSummary {
|
|||
public String roomName;
|
||||
public String relayID;
|
||||
public int seed;
|
||||
public boolean msgsPending;
|
||||
public MsgLevel pendingMsgLevel;
|
||||
public long modtime;
|
||||
|
||||
public int dictLang;
|
||||
public String dictName;
|
||||
public CurGameInfo.DeviceRole serverRole;
|
||||
|
||||
|
||||
private CurGameInfo m_gi;
|
||||
|
||||
public GameSummary(){
|
||||
msgsPending = false;
|
||||
pendingMsgLevel = MsgLevel.MSG_LEVEL_NONE;
|
||||
}
|
||||
|
||||
public GameSummary( CurGameInfo gi )
|
||||
|
|
Loading…
Reference in a new issue