mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-05 20:45:49 +01:00
pass context into GameSummary constructor rather than into methods
that need it. No behavior change.
This commit is contained in:
parent
28c78a0a6a
commit
47bdec4eda
5 changed files with 22 additions and 20 deletions
|
@ -107,7 +107,7 @@ public class DBUtils {
|
||||||
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() ) {
|
||||||
summary = new GameSummary();
|
summary = new GameSummary( context );
|
||||||
summary.nMoves = cursor.getInt(cursor.
|
summary.nMoves = cursor.getInt(cursor.
|
||||||
getColumnIndex(DBHelper.NUM_MOVES));
|
getColumnIndex(DBHelper.NUM_MOVES));
|
||||||
summary.nPlayers =
|
summary.nPlayers =
|
||||||
|
@ -223,7 +223,7 @@ public class DBUtils {
|
||||||
values.put( DBHelper.TURN, summary.turn );
|
values.put( DBHelper.TURN, summary.turn );
|
||||||
values.put( DBHelper.GIFLAGS, summary.giflags() );
|
values.put( DBHelper.GIFLAGS, summary.giflags() );
|
||||||
values.put( DBHelper.PLAYERS,
|
values.put( DBHelper.PLAYERS,
|
||||||
summary.summarizePlayers(context) );
|
summary.summarizePlayers() );
|
||||||
values.put( DBHelper.DICTLANG, summary.dictLang );
|
values.put( DBHelper.DICTLANG, summary.dictLang );
|
||||||
values.put( DBHelper.GAME_OVER, summary.gameOver );
|
values.put( DBHelper.GAME_OVER, summary.gameOver );
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ public class GameListAdapter extends XWListAdapter {
|
||||||
} else {
|
} else {
|
||||||
//Assert.assertNotNull( summary );
|
//Assert.assertNotNull( summary );
|
||||||
|
|
||||||
String state = summary.summarizeState( m_context );
|
String state = summary.summarizeState();
|
||||||
|
|
||||||
TextView view = (TextView)layout.findViewById( R.id.game_name );
|
TextView view = (TextView)layout.findViewById( R.id.game_name );
|
||||||
if ( hideTitle ) {
|
if ( hideTitle ) {
|
||||||
|
@ -168,7 +168,7 @@ public class GameListAdapter extends XWListAdapter {
|
||||||
View tmp = m_factory.inflate( R.layout.player_list_elem,
|
View tmp = m_factory.inflate( R.layout.player_list_elem,
|
||||||
null );
|
null );
|
||||||
view = (TextView)tmp.findViewById( R.id.item_name );
|
view = (TextView)tmp.findViewById( R.id.item_name );
|
||||||
view.setText( summary.summarizePlayer( m_context, ii ) );
|
view.setText( summary.summarizePlayer( ii ) );
|
||||||
view = (TextView)tmp.findViewById( R.id.item_score );
|
view = (TextView)tmp.findViewById( R.id.item_score );
|
||||||
view.setText( String.format( " %d", summary.scores[ii] ) );
|
view.setText( String.format( " %d", summary.scores[ii] ) );
|
||||||
if ( summary.isNextToPlay( ii ) ) {
|
if ( summary.isNextToPlay( ii ) ) {
|
||||||
|
@ -200,7 +200,7 @@ public class GameListAdapter extends XWListAdapter {
|
||||||
marker.setImageResource( iconID );
|
marker.setImageResource( iconID );
|
||||||
|
|
||||||
view = (TextView)layout.findViewById( R.id.role );
|
view = (TextView)layout.findViewById( R.id.role );
|
||||||
String roleSummary = summary.summarizeRole( m_context );
|
String roleSummary = summary.summarizeRole();
|
||||||
if ( null != roleSummary ) {
|
if ( null != roleSummary ) {
|
||||||
view.setText( roleSummary );
|
view.setText( roleSummary );
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -258,7 +258,7 @@ public class GameUtils {
|
||||||
int gamePtr, CurGameInfo gi,
|
int gamePtr, CurGameInfo gi,
|
||||||
FeedUtilsImpl feedImpl )
|
FeedUtilsImpl feedImpl )
|
||||||
{
|
{
|
||||||
GameSummary summary = new GameSummary( gi );
|
GameSummary summary = new GameSummary( context, gi );
|
||||||
XwJNI.game_summarize( gamePtr, summary );
|
XwJNI.game_summarize( gamePtr, summary );
|
||||||
|
|
||||||
if ( null != feedImpl ) {
|
if ( null != feedImpl ) {
|
||||||
|
@ -984,7 +984,7 @@ public class GameUtils {
|
||||||
|
|
||||||
saveGame( context, gamePtr, gi, lock, false );
|
saveGame( context, gamePtr, gi, lock, false );
|
||||||
|
|
||||||
GameSummary summary = new GameSummary( gi );
|
GameSummary summary = new GameSummary( context, gi );
|
||||||
XwJNI.game_summarize( gamePtr, summary );
|
XwJNI.game_summarize( gamePtr, summary );
|
||||||
DBUtils.saveSummary( context, lock, summary );
|
DBUtils.saveSummary( context, lock, summary );
|
||||||
|
|
||||||
|
|
|
@ -59,14 +59,16 @@ public class GameSummary {
|
||||||
private int m_giFlags;
|
private int m_giFlags;
|
||||||
private String m_playersSummary;
|
private String m_playersSummary;
|
||||||
private CurGameInfo m_gi;
|
private CurGameInfo m_gi;
|
||||||
|
private Context m_context;
|
||||||
|
|
||||||
public GameSummary(){
|
public GameSummary( Context context ) {
|
||||||
|
m_context = context;
|
||||||
pendingMsgLevel = 0;
|
pendingMsgLevel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameSummary( CurGameInfo gi )
|
public GameSummary( Context context, CurGameInfo gi )
|
||||||
{
|
{
|
||||||
this();
|
this( context );
|
||||||
nPlayers = gi.nPlayers;
|
nPlayers = gi.nPlayers;
|
||||||
dictLang = gi.dictLang;
|
dictLang = gi.dictLang;
|
||||||
serverRole = gi.serverRole;
|
serverRole = gi.serverRole;
|
||||||
|
@ -78,7 +80,7 @@ public class GameSummary {
|
||||||
return null != relayID;
|
return null != relayID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String summarizePlayers( Context context )
|
public String summarizePlayers()
|
||||||
{
|
{
|
||||||
String result;
|
String result;
|
||||||
if ( null == m_gi ) {
|
if ( null == m_gi ) {
|
||||||
|
@ -110,25 +112,25 @@ public class GameSummary {
|
||||||
m_playersSummary = summary;
|
m_playersSummary = summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String summarizeState( Context context )
|
public String summarizeState()
|
||||||
{
|
{
|
||||||
String result = null;
|
String result = null;
|
||||||
if ( gameOver ) {
|
if ( gameOver ) {
|
||||||
result = context.getString( R.string.gameOver );
|
result = m_context.getString( R.string.gameOver );
|
||||||
} else {
|
} else {
|
||||||
result = String.format( context.getString(R.string.movesf),
|
result = String.format( m_context.getString(R.string.movesf),
|
||||||
nMoves );
|
nMoves );
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String summarizeRole( Context context )
|
public String summarizeRole()
|
||||||
{
|
{
|
||||||
String result = null;
|
String result = null;
|
||||||
if ( isRelayGame() ) {
|
if ( isRelayGame() ) {
|
||||||
Assert.assertTrue( CommsAddrRec.CommsConnType.COMMS_CONN_RELAY
|
Assert.assertTrue( CommsAddrRec.CommsConnType.COMMS_CONN_RELAY
|
||||||
== conType );
|
== conType );
|
||||||
String fmt = context.getString( R.string.summary_fmt_relay );
|
String fmt = m_context.getString( R.string.summary_fmt_relay );
|
||||||
result = String.format( fmt, roomName );
|
result = String.format( fmt, roomName );
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -175,14 +177,14 @@ public class GameSummary {
|
||||||
m_giFlags = flags;
|
m_giFlags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String summarizePlayer( Context context, int indx )
|
public String summarizePlayer( int indx )
|
||||||
{
|
{
|
||||||
String player = players[indx];
|
String player = players[indx];
|
||||||
int formatID = 0;
|
int formatID = 0;
|
||||||
if ( !isLocal(indx) ) {
|
if ( !isLocal(indx) ) {
|
||||||
boolean isMissing = 0 != ((1 << indx) & missingPlayers);
|
boolean isMissing = 0 != ((1 << indx) & missingPlayers);
|
||||||
if ( isMissing ) {
|
if ( isMissing ) {
|
||||||
player = context.getString( R.string.missing_player );
|
player = m_context.getString( R.string.missing_player );
|
||||||
} else {
|
} else {
|
||||||
formatID = R.string.str_nonlocal_namef;
|
formatID = R.string.str_nonlocal_namef;
|
||||||
}
|
}
|
||||||
|
@ -191,7 +193,7 @@ public class GameSummary {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 0 != formatID ) {
|
if ( 0 != formatID ) {
|
||||||
String format = context.getString( formatID );
|
String format = m_context.getString( formatID );
|
||||||
player = String.format( format, player );
|
player = String.format( format, player );
|
||||||
}
|
}
|
||||||
return player;
|
return player;
|
||||||
|
|
|
@ -264,7 +264,7 @@ public class JNIThread extends Thread {
|
||||||
XwJNI.server_do( m_jniGamePtr );
|
XwJNI.server_do( m_jniGamePtr );
|
||||||
|
|
||||||
XwJNI.game_getGi( m_jniGamePtr, m_gi );
|
XwJNI.game_getGi( m_jniGamePtr, m_gi );
|
||||||
GameSummary summary = new GameSummary( m_gi );
|
GameSummary summary = new GameSummary( m_context, m_gi );
|
||||||
XwJNI.game_summarize( m_jniGamePtr, summary );
|
XwJNI.game_summarize( m_jniGamePtr, summary );
|
||||||
byte[] state = XwJNI.game_saveToStream( m_jniGamePtr, null );
|
byte[] state = XwJNI.game_saveToStream( m_jniGamePtr, null );
|
||||||
GameUtils.saveGame( m_context, state, m_lock, false );
|
GameUtils.saveGame( m_context, state, m_lock, false );
|
||||||
|
|
Loading…
Add table
Reference in a new issue