Fix bug: the CurGameInfo instance being used to generate the list of

dicts passed when opening a game was based on defaults, not read in
from the game data.  Oops.  So now it's a two-step process: open the
data, read in the game info, generate list of dicts from that, and
open full game with list of dicts.  (TODO: optimize by caching game
data across multiple reads.)
This commit is contained in:
Andy2 2011-09-03 20:31:03 -07:00
parent 8087153b73
commit a3566bc063
2 changed files with 22 additions and 14 deletions

View file

@ -342,8 +342,6 @@ public class BoardActivity extends XWActivity
setContentView( R.layout.board );
m_timers = new TimerRunnable[4]; // needs to be in sync with
// XWTimerReason
m_gi = new CurGameInfo( this );
m_view = (BoardView)findViewById( R.id.board_view );
m_tradeButtons = findViewById( R.id.exchange_buttons );
m_exchCommmitButton = (Button)findViewById( R.id.exchange_commit );
@ -1171,20 +1169,19 @@ public class BoardActivity extends XWActivity
private void loadGame()
{
if ( 0 == m_jniGamePtr ) {
String[] dictNames = m_gi.dictNames();
String[] dictNames = GameUtils.dictNames( this, m_rowid );
GameUtils.DictPairs pairs = GameUtils.openDicts( this, dictNames );
if ( pairs.anyMissing( dictNames ) ) {
showDictGoneFinish();
} else {
String langName = m_gi.langName();
Assert.assertNull( m_gameLock );
m_gameLock = new GameUtils.GameLock( m_rowid, true ).lock();
byte[] stream = GameUtils.savedGame( this, m_gameLock );
m_gi = new CurGameInfo( this );
XwJNI.gi_from_stream( m_gi, stream );
String langName = m_gi.langName();
m_jniGamePtr = XwJNI.initJNI();
@ -1408,6 +1405,7 @@ public class BoardActivity extends XWActivity
XwJNI.game_dispose( m_jniGamePtr );
m_jniGamePtr = 0;
m_gi = null;
m_gameLock.unlock();
m_gameLock = null;

View file

@ -460,6 +460,23 @@ public class GameUtils {
}
}
public static String[] dictNames( Context context, long rowid,
int[] missingLang )
{
byte[] stream = savedGame( context, rowid );
CurGameInfo gi = new CurGameInfo( context );
XwJNI.gi_from_stream( gi, stream );
if ( null != missingLang ) {
missingLang[0] = gi.dictLang;
}
return gi.dictNames();
}
public static String[] dictNames( Context context, long rowid )
{
return dictNames( context, rowid, null );
}
public static boolean gameDictsHere( Context context, long rowid )
{
return gameDictsHere( context, rowid, null, null );
@ -471,17 +488,10 @@ public class GameUtils {
String[][] missingNames,
int[] missingLang )
{
byte[] stream = savedGame( context, rowid );
CurGameInfo gi = new CurGameInfo( context );
XwJNI.gi_from_stream( gi, stream );
final String[] dictNames = gi.dictNames();
String[] dictNames = dictNames( context, rowid, missingLang );
HashSet<String> missingSet;
String[] installed = dictList( context );
if ( null != missingLang ) {
missingLang[0] = gi.dictLang;
}
missingSet = new HashSet<String>( Arrays.asList( dictNames ) );
missingSet.remove( null );
missingSet.removeAll( Arrays.asList(installed) );