mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-27 09:58:45 +01:00
add new columns to GameSummary db and use for better summary
This commit is contained in:
parent
863ef90115
commit
5052c05390
5 changed files with 94 additions and 32 deletions
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue