mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
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:
parent
e8b66e230c
commit
cd6aa8fe98
2 changed files with 44 additions and 25 deletions
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue