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.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,
selection, null, null, null, null );
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
Utils.logf( "got rowid: %d",
cursor.getLong( cursor.getColumnIndex(ROW_ID) ) );
summary = new GameSummary();
summary.nMoves = cursor.getInt(cursor.
getColumnIndex(DBHelper.NUM_MOVES));
@ -119,6 +116,11 @@ public class DBUtils {
summary.missingPlayers =
cursor.getInt(cursor.
getColumnIndex(DBHelper.MISSINGPLYRS));
summary.
setPlayerSummary( cursor.
getString( cursor.
getColumnIndex( DBHelper.
PLAYERS ) ) );
summary.turn =
cursor.getInt(cursor.
getColumnIndex(DBHelper.TURN));

View file

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