mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
fix games created after reset of prefs from disappearing: they were
being saved with groupid of -1, so now when the default's not been sit choose and pass in the first group.
This commit is contained in:
parent
5826f080be
commit
53748e352a
5 changed files with 65 additions and 39 deletions
|
@ -55,6 +55,7 @@ import org.eehouse.android.xw4.DictUtils.DictLoc;
|
|||
|
||||
public class DBUtils {
|
||||
public static final int ROWID_NOTFOUND = -1;
|
||||
public static final int GROUPID_UNSPEC = -1;
|
||||
|
||||
private static final String DICTS_SEP = ",";
|
||||
|
||||
|
@ -754,15 +755,10 @@ public class DBUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static GameLock saveNewGame( Context context, byte[] bytes )
|
||||
{
|
||||
long groupID = XWPrefs.getDefaultNewGameGroup( context );
|
||||
return saveNewGame( context, bytes, groupID );
|
||||
}
|
||||
|
||||
public static GameLock saveNewGame( Context context, byte[] bytes,
|
||||
long groupID )
|
||||
{
|
||||
Assert.assertTrue( GROUPID_UNSPEC != groupID );
|
||||
GameLock lock = null;
|
||||
|
||||
initDB( context );
|
||||
|
@ -807,7 +803,7 @@ public class DBUtils {
|
|||
updateRow( context, DBHelper.TABLE_NAME_SUM, rowid, values );
|
||||
|
||||
setCached( rowid, null ); // force reread
|
||||
if ( -1 != rowid ) { // Means new game?
|
||||
if ( ROWID_NOTFOUND != rowid ) { // Means new game?
|
||||
notifyListeners( rowid, false );
|
||||
}
|
||||
invalGroupsCache();
|
||||
|
@ -817,7 +813,7 @@ public class DBUtils {
|
|||
public static byte[] loadGame( Context context, GameLock lock )
|
||||
{
|
||||
long rowid = lock.getRowid();
|
||||
Assert.assertTrue( -1 != rowid );
|
||||
Assert.assertTrue( ROWID_NOTFOUND != rowid );
|
||||
byte[] result = getCached( rowid );
|
||||
if ( null == result ) {
|
||||
initDB( context );
|
||||
|
@ -869,7 +865,7 @@ public class DBUtils {
|
|||
|
||||
public static int getVisID( Context context, long rowid )
|
||||
{
|
||||
int result = -1;
|
||||
int result = ROWID_NOTFOUND;
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
|
@ -1004,9 +1000,9 @@ public class DBUtils {
|
|||
|
||||
Iterator<Long> iter = result.keySet().iterator();
|
||||
while ( iter.hasNext() ) {
|
||||
Long id = iter.next();
|
||||
GameGroupInfo ggi = result.get( id );
|
||||
readTurnInfo( db, id, ggi );
|
||||
Long groupID = iter.next();
|
||||
GameGroupInfo ggi = result.get( groupID );
|
||||
readTurnInfo( db, groupID, ggi );
|
||||
}
|
||||
|
||||
db.close();
|
||||
|
@ -1016,13 +1012,31 @@ public class DBUtils {
|
|||
return s_groupsCache;
|
||||
} // getGroups
|
||||
|
||||
private static void readTurnInfo( SQLiteDatabase db, long id,
|
||||
// public static void unhideTo( Context context, long groupID )
|
||||
// {
|
||||
// Assert.assertTrue( GROUPID_UNSPEC != groupID );
|
||||
// initDB( context );
|
||||
// synchronized( s_dbHelper ) {
|
||||
// SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
// ContentValues values = new ContentValues();
|
||||
// values.put( DBHelper.GROUPID, groupID );
|
||||
// String selection = String.format( "%s = %d", DBHelper.GROUPID,
|
||||
// GROUPID_UNSPEC );
|
||||
// long result = db.update( DBHelper.TABLE_NAME_SUM,
|
||||
// values, selection, null );
|
||||
// db.close();
|
||||
|
||||
// notifyListeners( ROWID_NOTFOUND, true );
|
||||
// }
|
||||
// }
|
||||
|
||||
private static void readTurnInfo( SQLiteDatabase db, long groupID,
|
||||
GameGroupInfo ggi )
|
||||
{
|
||||
String[] columns = { DBHelper.LASTMOVE, DBHelper.GIFLAGS,
|
||||
DBHelper.TURN };
|
||||
String orderBy = DBHelper.LASTMOVE;
|
||||
String selection = String.format( "%s=%d", DBHelper.GROUPID, id );
|
||||
String selection = String.format( "%s=%d", DBHelper.GROUPID, groupID );
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection,
|
||||
null, // args
|
||||
|
@ -1100,7 +1114,7 @@ public class DBUtils {
|
|||
|
||||
public static long getGroupForGame( Context context, long rowid )
|
||||
{
|
||||
long result = ROWID_NOTFOUND;
|
||||
long result = GROUPID_UNSPEC;
|
||||
initDB( context );
|
||||
String[] columns = { DBHelper.GROUPID };
|
||||
String selection = String.format( ROW_ID_FMT, rowid );
|
||||
|
@ -1125,7 +1139,7 @@ public class DBUtils {
|
|||
|
||||
public static long addGroup( Context context, String name )
|
||||
{
|
||||
long rowid = ROWID_NOTFOUND;
|
||||
long rowid = GROUPID_UNSPEC;
|
||||
if ( null != name && 0 < name.length() ) {
|
||||
HashMap<Long,GameGroupInfo> gameInfo = getGroups( context );
|
||||
if ( null == gameInfo.get( name ) ) {
|
||||
|
@ -1185,10 +1199,11 @@ public class DBUtils {
|
|||
}
|
||||
|
||||
// Change group id of a game
|
||||
public static void moveGame( Context context, long gameid, long groupid )
|
||||
public static void moveGame( Context context, long gameid, long groupID )
|
||||
{
|
||||
Assert.assertTrue( GROUPID_UNSPEC != groupID );
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.GROUPID, groupid );
|
||||
values.put( DBHelper.GROUPID, groupID );
|
||||
updateRow( context, DBHelper.TABLE_NAME_SUM, gameid, values );
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ public class GameUtils {
|
|||
public static final String INTENT_KEY_ROWID = "rowid";
|
||||
public static final String INTENT_FORRESULT_ROWID = "forresult";
|
||||
|
||||
private static final long GROUPID_UNSPEC = -1;
|
||||
private static Integer s_minScreen;
|
||||
|
||||
public static class NoSuchGameException extends RuntimeException {
|
||||
|
@ -376,21 +375,15 @@ public class GameUtils {
|
|||
return DBUtils.saveGame( context, lock, bytes, setCreate );
|
||||
}
|
||||
|
||||
public static GameLock saveNewGame( Context context, byte[] bytes )
|
||||
public static GameLock saveNewGame( Context context, byte[] bytes,
|
||||
long groupID )
|
||||
{
|
||||
return DBUtils.saveNewGame( context, bytes );
|
||||
}
|
||||
|
||||
public static long saveNew( Context context, CurGameInfo gi )
|
||||
{
|
||||
return saveNew( context, gi, GROUPID_UNSPEC );
|
||||
return DBUtils.saveNewGame( context, bytes, groupID );
|
||||
}
|
||||
|
||||
public static long saveNew( Context context, CurGameInfo gi, long groupID )
|
||||
{
|
||||
if ( GROUPID_UNSPEC == groupID ) {
|
||||
groupID = XWPrefs.getDefaultNewGameGroup( context );
|
||||
}
|
||||
Assert.assertTrue( DBUtils.GROUPID_UNSPEC != groupID );
|
||||
|
||||
long rowid = DBUtils.ROWID_NOTFOUND;
|
||||
byte[] bytes = XwJNI.gi_to_stream( gi );
|
||||
|
@ -464,7 +457,7 @@ public class GameUtils {
|
|||
|
||||
public static long makeNewNetGame( Context context, NetLaunchInfo info )
|
||||
{
|
||||
return makeNewNetGame( context, GROUPID_UNSPEC, info.room,
|
||||
return makeNewNetGame( context, DBUtils.GROUPID_UNSPEC, info.room,
|
||||
info.inviteID, info.lang, info.dict,
|
||||
info.nPlayersT );
|
||||
}
|
||||
|
@ -473,8 +466,8 @@ public class GameUtils {
|
|||
CommsAddrRec addr, int lang,
|
||||
int nPlayersT, int nPlayersH )
|
||||
{
|
||||
return makeNewBTGame( context, GROUPID_UNSPEC, gameID, addr, lang,
|
||||
nPlayersT, nPlayersH );
|
||||
return makeNewBTGame( context, DBUtils.GROUPID_UNSPEC, gameID, addr,
|
||||
lang, nPlayersT, nPlayersH );
|
||||
}
|
||||
|
||||
public static long makeNewBTGame( Context context, long groupID,
|
||||
|
@ -496,7 +489,7 @@ public class GameUtils {
|
|||
int lang, String dict, int nPlayersT,
|
||||
int nPlayersH )
|
||||
{
|
||||
return makeNewSMSGame( context, GROUPID_UNSPEC, gameID, addr,
|
||||
return makeNewSMSGame( context, DBUtils.GROUPID_UNSPEC, gameID, addr,
|
||||
lang, dict, nPlayersT, nPlayersH );
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ public class GamesList extends XWExpandableListActivity
|
|||
};
|
||||
|
||||
private static final int[] DEBUG_ITEMS = {
|
||||
R.id.games_menu_loaddb,
|
||||
// R.id.games_menu_loaddb,
|
||||
R.id.games_menu_storedb,
|
||||
R.id.games_menu_checkupdates,
|
||||
};
|
||||
|
@ -483,11 +483,12 @@ public class GamesList extends XWExpandableListActivity
|
|||
// DBUtils.DBChangeListener interface
|
||||
public void gameSaved( final long rowid, final boolean countChanged )
|
||||
{
|
||||
post( new Runnable() {
|
||||
runOnUiThread( new Runnable() {
|
||||
public void run() {
|
||||
if ( countChanged ) {
|
||||
onContentChanged();
|
||||
} else {
|
||||
Assert.assertTrue( 0 <= rowid );
|
||||
m_adapter.inval( rowid );
|
||||
}
|
||||
}
|
||||
|
@ -727,7 +728,7 @@ public class GamesList extends XWExpandableListActivity
|
|||
boolean changeContent = false;
|
||||
boolean dropSels = false;
|
||||
int groupPos = getSelGroupPos();
|
||||
long groupID = -1;
|
||||
long groupID = DBUtils.GROUPID_UNSPEC;
|
||||
if ( 0 <= groupPos ) {
|
||||
groupID = m_adapter.getGroupIDFor( groupPos );
|
||||
}
|
||||
|
@ -820,7 +821,8 @@ public class GamesList extends XWExpandableListActivity
|
|||
byte[] stream = GameUtils.savedGame( GamesList.this,
|
||||
selRowIDs[0] );
|
||||
GameLock lock =
|
||||
GameUtils.saveNewGame( GamesList.this, stream );
|
||||
GameUtils.saveNewGame( GamesList.this, stream,
|
||||
getSaveGroup() );
|
||||
DBUtils.saveSummary( GamesList.this, lock, smry );
|
||||
m_selGames.add( lock.getRowid() );
|
||||
lock.unlock();
|
||||
|
@ -1053,6 +1055,9 @@ public class GamesList extends XWExpandableListActivity
|
|||
|
||||
private void startNewGameActivity( long groupID )
|
||||
{
|
||||
if ( DBUtils.GROUPID_UNSPEC == groupID ) {
|
||||
groupID = getSaveGroup();
|
||||
}
|
||||
NewGameActivity.startActivity( this, groupID );
|
||||
}
|
||||
|
||||
|
@ -1332,6 +1337,15 @@ public class GamesList extends XWExpandableListActivity
|
|||
}
|
||||
}
|
||||
|
||||
private long getSaveGroup()
|
||||
{
|
||||
long groupID = XWPrefs.getDefaultNewGameGroup( this );
|
||||
if ( DBUtils.GROUPID_UNSPEC == groupID ) {
|
||||
groupID = m_adapter.getGroupIDFor( 0 );
|
||||
}
|
||||
return groupID;
|
||||
}
|
||||
|
||||
public static void onGameDictDownload( Context context, Intent intent )
|
||||
{
|
||||
intent.setClass( context, GamesList.class );
|
||||
|
|
|
@ -79,6 +79,7 @@ public class NewGameActivity extends XWActivity {
|
|||
getBundledData( savedInstanceState );
|
||||
|
||||
m_groupID = getIntent().getLongExtra( GROUPID_EXTRA, -1 );
|
||||
Assert.assertTrue( -1 != m_groupID );
|
||||
|
||||
setContentView( R.layout.new_game );
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@ import android.text.TextUtils;
|
|||
import com.google.android.gcm.GCMRegistrar;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class XWPrefs {
|
||||
|
||||
public static boolean getSMSEnabled( Context context )
|
||||
|
@ -301,12 +303,13 @@ public class XWPrefs {
|
|||
|
||||
public static long getDefaultNewGameGroup( Context context )
|
||||
{
|
||||
return getPrefsLong( context, R.string.key_default_group,
|
||||
DBUtils.ROWID_NOTFOUND );
|
||||
return getPrefsLong( context, R.string.key_default_group,
|
||||
DBUtils.GROUPID_UNSPEC );
|
||||
}
|
||||
|
||||
public static void setDefaultNewGameGroup( Context context, long val )
|
||||
{
|
||||
Assert.assertTrue( DBUtils.GROUPID_UNSPEC != val );
|
||||
setPrefsLong( context, R.string.key_default_group, val );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue