fix crasher using Copy menuitem: when summary is copied out of a db it

doesn't have a gi, but it does have the summaries values copied in so
use those.
This commit is contained in:
Andy2 2011-08-05 22:38:01 -07:00
parent e8b66e230c
commit cd6aa8fe98
2 changed files with 44 additions and 25 deletions

View file

@ -102,14 +102,11 @@ public class DBUtils {
DBHelper.SCORES, DBHelper.HASMSGS, DBHelper.SCORES, DBHelper.HASMSGS,
DBHelper.LASTPLAY_TIME DBHelper.LASTPLAY_TIME
}; };
String selection = String.format( ROW_ID_FMT, lock.getRowid() ); String selection = String.format( ROW_ID_FMT, lock.getRowid() );
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns, Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
selection, null, null, null, null ); selection, null, null, null, null );
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) { if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
Utils.logf( "got rowid: %d",
cursor.getLong( cursor.getColumnIndex(ROW_ID) ) );
summary = new GameSummary(); summary = new GameSummary();
summary.nMoves = cursor.getInt(cursor. summary.nMoves = cursor.getInt(cursor.
getColumnIndex(DBHelper.NUM_MOVES)); getColumnIndex(DBHelper.NUM_MOVES));
@ -119,6 +116,11 @@ public class DBUtils {
summary.missingPlayers = summary.missingPlayers =
cursor.getInt(cursor. cursor.getInt(cursor.
getColumnIndex(DBHelper.MISSINGPLYRS)); getColumnIndex(DBHelper.MISSINGPLYRS));
summary.
setPlayerSummary( cursor.
getString( cursor.
getColumnIndex( DBHelper.
PLAYERS ) ) );
summary.turn = summary.turn =
cursor.getInt(cursor. cursor.getInt(cursor.
getColumnIndex(DBHelper.TURN)); getColumnIndex(DBHelper.TURN));

View file

@ -57,6 +57,7 @@ public class GameSummary {
public CurGameInfo.DeviceRole serverRole; public CurGameInfo.DeviceRole serverRole;
private int m_giFlags; private int m_giFlags;
private String m_playersSummary;
private CurGameInfo m_gi; private CurGameInfo m_gi;
public GameSummary(){ public GameSummary(){
@ -65,7 +66,7 @@ public class GameSummary {
public GameSummary( CurGameInfo gi ) public GameSummary( CurGameInfo gi )
{ {
super(); this();
nPlayers = gi.nPlayers; nPlayers = gi.nPlayers;
dictLang = gi.dictLang; dictLang = gi.dictLang;
serverRole = gi.serverRole; serverRole = gi.serverRole;
@ -79,22 +80,34 @@ public class GameSummary {
public String summarizePlayers( Context context ) public String summarizePlayers( Context context )
{ {
StringBuffer sb = new StringBuffer(); String result;
for ( int ii = 0; ; ) { if ( null == m_gi ) {
result = m_playersSummary;
} else {
StringBuffer sb = new StringBuffer();
for ( int ii = 0; ; ) {
int score = 0; int score = 0;
try { try {
// scores can be null, but I've seen array OOB too. // scores can be null, but I've seen array OOB too.
score = scores[ii]; score = scores[ii];
} catch ( Exception ex ){} } catch ( Exception ex ){}
sb.append( m_gi.players[ii].name ); sb.append( m_gi.players[ii].name );
if ( ++ii >= nPlayers ) { if ( ++ii >= nPlayers ) {
break; break;
}
sb.append( "\n" );
} }
sb.append( "\n" ); result = sb.toString();
m_playersSummary = result;
} }
return sb.toString(); return result;
}
public void setPlayerSummary( String summary )
{
m_playersSummary = summary;
} }
public String summarizeState( Context context ) public String summarizeState( Context context )
@ -134,14 +147,18 @@ public class GameSummary {
} }
public int giflags() { public int giflags() {
Assert.assertNotNull( m_gi ); int result;
int result = 0; if ( null == m_gi ) {
for ( int ii = 0; ii < m_gi.nPlayers; ++ii ) { result = m_giFlags;
if ( ! m_gi.players[ii].isLocal ) { } else {
result |= 2 << (ii * 2); result = 0;
} for ( int ii = 0; ii < m_gi.nPlayers; ++ii ) {
if ( m_gi.players[ii].isRobot() ) { if ( ! m_gi.players[ii].isLocal ) {
result |= 1 << (ii * 2); result |= 2 << (ii * 2);
}
if ( m_gi.players[ii].isRobot() ) {
result |= 1 << (ii * 2);
}
} }
} }
return result; return result;