diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java index e5eaea728..2acd3ae5b 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java @@ -28,12 +28,16 @@ public class DBHelper extends SQLiteOpenHelper { public static final String TABLE_NAME = "summaries"; private static final String DB_NAME = "xwdb"; - private static final int DB_VERSION = 1; + private static final int DB_VERSION = 2; public static final String FILE_NAME = "FILE_NAME"; public static final String NUM_MOVES = "NUM_MOVES"; public static final String GAME_OVER = "GAME_OVER"; public static final String SNAPSHOT = "SNAPSHOT"; + public static final String CONTYPE = "CONTYPE"; + public static final String ROOMNAME = "ROOMNAME"; + public static final String SMSPHONE = "SMSPHONE"; + public DBHelper( Context context ) { @@ -47,7 +51,12 @@ public class DBHelper extends SQLiteOpenHelper { + FILE_NAME + " TEXT PRIMARY KEY," + NUM_MOVES + " INTEGER," + GAME_OVER + " INTEGER," - + SNAPSHOT + " BLOB" + + + CONTYPE + " INTEGER," + + ROOMNAME + " TEXT," + + SMSPHONE + " TEXT," + + + SNAPSHOT + " BLOB" + ");" ); } @@ -55,5 +64,7 @@ public class DBHelper extends SQLiteOpenHelper { public void onUpgrade( SQLiteDatabase db, int oldVersion, int newVersion ) { Utils.logf( "onUpgrade: old: %d; new: %d", oldVersion, newVersion ); + db.execSQL( "DROP TABLE " + TABLE_NAME + ";" ); + onCreate( db ); } } 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 82a9e478e..c2bd2a8f7 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListAdapter.java @@ -60,25 +60,9 @@ public class GameListAdapter implements ListAdapter { CurGameInfo gi = new CurGameInfo( m_context ); XwJNI.gi_from_stream( gi, stream ); - String summaryTxt = gi.summary( m_context ); - GameSummary summary = Utils.getSummary( m_context, path ); - if ( null != summary ) { - String state = "\nState: "; - if ( summary.nMoves < 0 ) { - state += "Configured"; - } else if ( summary.gameOver ) { - state += "Game over"; - } else { - state += "In play"; - } - summaryTxt += state; + String summaryTxt = gi.summarize( m_context, summary ); - if ( summary.nMoves >= 0 ) { - summaryTxt += String.format( " Moves played: %d", - summary.nMoves ); - } - } view.setText( summaryTxt ); } return view; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java index b7e465cc6..71fbc0084 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java @@ -455,7 +455,10 @@ public class Utils { GameSummary summary = new GameSummary(); SQLiteDatabase db = m_dbHelper.getReadableDatabase(); - String[] columns = { DBHelper.NUM_MOVES, DBHelper.GAME_OVER }; + String[] columns = { DBHelper.NUM_MOVES, DBHelper.GAME_OVER, + DBHelper.CONTYPE, DBHelper.ROOMNAME, + DBHelper.SMSPHONE + }; String selection = DBHelper.FILE_NAME + "=\"" + file + "\""; Cursor cursor = db.query( DBHelper.TABLE_NAME, columns, selection, @@ -467,6 +470,20 @@ public class Utils { int tmp = cursor.getInt(cursor. getColumnIndex(DBHelper.GAME_OVER)); summary.gameOver = tmp == 0 ? false : true; + + int col = cursor.getColumnIndex( DBHelper.CONTYPE ); + if ( col >= 0 ) { + tmp = cursor.getInt( col ); + summary.conType = CommsAddrRec.CommsConnType.values()[tmp]; + col = cursor.getColumnIndex( DBHelper.ROOMNAME ); + if ( col >= 0 ) { + summary.roomName = cursor.getString( col ); + } + col = cursor.getColumnIndex( DBHelper.SMSPHONE ); + if ( col >= 0 ) { + summary.smsPhone = cursor.getString( col ); + } + } } cursor.close(); db.close(); @@ -503,6 +520,13 @@ public class Utils { values.put( DBHelper.NUM_MOVES, summary.nMoves ); values.put( DBHelper.GAME_OVER, summary.gameOver ); + if ( null != summary.conType ) { + values.put( DBHelper.CONTYPE, summary.conType.ordinal() ); + Utils.logf( "wrote CONTYPE" ); + values.put( DBHelper.ROOMNAME, summary.roomName ); + values.put( DBHelper.SMSPHONE, summary.smsPhone ); + } + Utils.logf( "saveSummary: nMoves=%d", summary.nMoves ); try { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CurGameInfo.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CurGameInfo.java index 81d01eb90..43d0e8ed9 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CurGameInfo.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CurGameInfo.java @@ -209,10 +209,11 @@ public class CurGameInfo { return names; } - public String summary( Context context ) + public String summarize( Context context, GameSummary summary ) { StringBuffer sb = new StringBuffer(); String vsString = context.getString( R.string.vs ); + String tmp; int ii; for ( ii = 0; ; ) { sb.append( players[ii].name ); @@ -221,21 +222,59 @@ public class CurGameInfo { } sb.append( String.format( " %s ", vsString ) ); } + + if ( null != summary ) { + DeviceRole role = serverRole; + if ( role != DeviceRole.SERVER_STANDALONE ) { + if ( null != summary.conType ) { + boolean isHost = role == DeviceRole.SERVER_ISSERVER; + boolean justListening = false; + int roleID = isHost ? R.string.role_host : R.string.role_guest; + String via; + int summaryID; + switch ( summary.conType ) { + case COMMS_CONN_RELAY: + via = summary.roomName; + summaryID = R.string.summary_fmt_relay; + break; + case COMMS_CONN_SMS: + via = summary.smsPhone; + summaryID = R.string.summary_fmt_sms; + justListening = isHost; + break; + default: + summaryID = 0; + via = null; + Assert.fail(); + } + String fmt = context.getString( justListening? + R.string.summary_fmt_listening + : summaryID ); + String roleStr = context.getString( roleID ); + if ( justListening ) { + tmp = String.format( fmt, roleStr ); + } else { + tmp = String.format( fmt, roleStr, via ); + } + sb.append( tmp ); + } + } + + + if ( summary.gameOver ) { + tmp = context.getString( R.string.gameOver ); + } else { + tmp = String.format( context.getString(R.string.movesf), + summary.nMoves ); + } + sb.append( String.format( context.getString(R.string.statef), + tmp ) ); + } + sb.append( String.format("\n%s %s", context.getString( R.string.dictionary ), dictName ) ); - DeviceRole role = serverRole; - if ( serverRole != DeviceRole.SERVER_STANDALONE ) { - sb.append( "\n" ) - .append( context.getString( R.string.role_label ) ) - .append( ": " ); - if ( role == DeviceRole.SERVER_ISSERVER ) { - sb.append( context.getString( R.string.role_host ) ); - } else { - sb.append( context.getString( R.string.role_guest ) ); - } - } return sb.toString(); } 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 a93c2cd36..033eb4fda 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 @@ -20,10 +20,14 @@ package org.eehouse.android.xw4.jni; + /** Info we want to access when the game's closed that's not available * in CurGameInfo */ public class GameSummary { public int nMoves; public boolean gameOver; + public CommsAddrRec.CommsConnType conType; + public String roomName; + public String smsPhone; }