mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +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 class DBUtils {
|
||||||
public static final int ROWID_NOTFOUND = -1;
|
public static final int ROWID_NOTFOUND = -1;
|
||||||
|
public static final int GROUPID_UNSPEC = -1;
|
||||||
|
|
||||||
private static final String DICTS_SEP = ",";
|
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,
|
public static GameLock saveNewGame( Context context, byte[] bytes,
|
||||||
long groupID )
|
long groupID )
|
||||||
{
|
{
|
||||||
|
Assert.assertTrue( GROUPID_UNSPEC != groupID );
|
||||||
GameLock lock = null;
|
GameLock lock = null;
|
||||||
|
|
||||||
initDB( context );
|
initDB( context );
|
||||||
|
@ -807,7 +803,7 @@ public class DBUtils {
|
||||||
updateRow( context, DBHelper.TABLE_NAME_SUM, rowid, values );
|
updateRow( context, DBHelper.TABLE_NAME_SUM, rowid, values );
|
||||||
|
|
||||||
setCached( rowid, null ); // force reread
|
setCached( rowid, null ); // force reread
|
||||||
if ( -1 != rowid ) { // Means new game?
|
if ( ROWID_NOTFOUND != rowid ) { // Means new game?
|
||||||
notifyListeners( rowid, false );
|
notifyListeners( rowid, false );
|
||||||
}
|
}
|
||||||
invalGroupsCache();
|
invalGroupsCache();
|
||||||
|
@ -817,7 +813,7 @@ public class DBUtils {
|
||||||
public static byte[] loadGame( Context context, GameLock lock )
|
public static byte[] loadGame( Context context, GameLock lock )
|
||||||
{
|
{
|
||||||
long rowid = lock.getRowid();
|
long rowid = lock.getRowid();
|
||||||
Assert.assertTrue( -1 != rowid );
|
Assert.assertTrue( ROWID_NOTFOUND != rowid );
|
||||||
byte[] result = getCached( rowid );
|
byte[] result = getCached( rowid );
|
||||||
if ( null == result ) {
|
if ( null == result ) {
|
||||||
initDB( context );
|
initDB( context );
|
||||||
|
@ -869,7 +865,7 @@ public class DBUtils {
|
||||||
|
|
||||||
public static int getVisID( Context context, long rowid )
|
public static int getVisID( Context context, long rowid )
|
||||||
{
|
{
|
||||||
int result = -1;
|
int result = ROWID_NOTFOUND;
|
||||||
initDB( context );
|
initDB( context );
|
||||||
synchronized( s_dbHelper ) {
|
synchronized( s_dbHelper ) {
|
||||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||||
|
@ -1004,9 +1000,9 @@ public class DBUtils {
|
||||||
|
|
||||||
Iterator<Long> iter = result.keySet().iterator();
|
Iterator<Long> iter = result.keySet().iterator();
|
||||||
while ( iter.hasNext() ) {
|
while ( iter.hasNext() ) {
|
||||||
Long id = iter.next();
|
Long groupID = iter.next();
|
||||||
GameGroupInfo ggi = result.get( id );
|
GameGroupInfo ggi = result.get( groupID );
|
||||||
readTurnInfo( db, id, ggi );
|
readTurnInfo( db, groupID, ggi );
|
||||||
}
|
}
|
||||||
|
|
||||||
db.close();
|
db.close();
|
||||||
|
@ -1016,13 +1012,31 @@ public class DBUtils {
|
||||||
return s_groupsCache;
|
return s_groupsCache;
|
||||||
} // getGroups
|
} // 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 )
|
GameGroupInfo ggi )
|
||||||
{
|
{
|
||||||
String[] columns = { DBHelper.LASTMOVE, DBHelper.GIFLAGS,
|
String[] columns = { DBHelper.LASTMOVE, DBHelper.GIFLAGS,
|
||||||
DBHelper.TURN };
|
DBHelper.TURN };
|
||||||
String orderBy = DBHelper.LASTMOVE;
|
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,
|
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||||
selection,
|
selection,
|
||||||
null, // args
|
null, // args
|
||||||
|
@ -1100,7 +1114,7 @@ public class DBUtils {
|
||||||
|
|
||||||
public static long getGroupForGame( Context context, long rowid )
|
public static long getGroupForGame( Context context, long rowid )
|
||||||
{
|
{
|
||||||
long result = ROWID_NOTFOUND;
|
long result = GROUPID_UNSPEC;
|
||||||
initDB( context );
|
initDB( context );
|
||||||
String[] columns = { DBHelper.GROUPID };
|
String[] columns = { DBHelper.GROUPID };
|
||||||
String selection = String.format( ROW_ID_FMT, rowid );
|
String selection = String.format( ROW_ID_FMT, rowid );
|
||||||
|
@ -1125,7 +1139,7 @@ public class DBUtils {
|
||||||
|
|
||||||
public static long addGroup( Context context, String name )
|
public static long addGroup( Context context, String name )
|
||||||
{
|
{
|
||||||
long rowid = ROWID_NOTFOUND;
|
long rowid = GROUPID_UNSPEC;
|
||||||
if ( null != name && 0 < name.length() ) {
|
if ( null != name && 0 < name.length() ) {
|
||||||
HashMap<Long,GameGroupInfo> gameInfo = getGroups( context );
|
HashMap<Long,GameGroupInfo> gameInfo = getGroups( context );
|
||||||
if ( null == gameInfo.get( name ) ) {
|
if ( null == gameInfo.get( name ) ) {
|
||||||
|
@ -1185,10 +1199,11 @@ public class DBUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change group id of a game
|
// 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();
|
ContentValues values = new ContentValues();
|
||||||
values.put( DBHelper.GROUPID, groupid );
|
values.put( DBHelper.GROUPID, groupID );
|
||||||
updateRow( context, DBHelper.TABLE_NAME_SUM, gameid, values );
|
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_KEY_ROWID = "rowid";
|
||||||
public static final String INTENT_FORRESULT_ROWID = "forresult";
|
public static final String INTENT_FORRESULT_ROWID = "forresult";
|
||||||
|
|
||||||
private static final long GROUPID_UNSPEC = -1;
|
|
||||||
private static Integer s_minScreen;
|
private static Integer s_minScreen;
|
||||||
|
|
||||||
public static class NoSuchGameException extends RuntimeException {
|
public static class NoSuchGameException extends RuntimeException {
|
||||||
|
@ -376,21 +375,15 @@ public class GameUtils {
|
||||||
return DBUtils.saveGame( context, lock, bytes, setCreate );
|
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 );
|
return DBUtils.saveNewGame( context, bytes, groupID );
|
||||||
}
|
|
||||||
|
|
||||||
public static long saveNew( Context context, CurGameInfo gi )
|
|
||||||
{
|
|
||||||
return saveNew( context, gi, GROUPID_UNSPEC );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long saveNew( Context context, CurGameInfo gi, long groupID )
|
public static long saveNew( Context context, CurGameInfo gi, long groupID )
|
||||||
{
|
{
|
||||||
if ( GROUPID_UNSPEC == groupID ) {
|
Assert.assertTrue( DBUtils.GROUPID_UNSPEC != groupID );
|
||||||
groupID = XWPrefs.getDefaultNewGameGroup( context );
|
|
||||||
}
|
|
||||||
|
|
||||||
long rowid = DBUtils.ROWID_NOTFOUND;
|
long rowid = DBUtils.ROWID_NOTFOUND;
|
||||||
byte[] bytes = XwJNI.gi_to_stream( gi );
|
byte[] bytes = XwJNI.gi_to_stream( gi );
|
||||||
|
@ -464,7 +457,7 @@ public class GameUtils {
|
||||||
|
|
||||||
public static long makeNewNetGame( Context context, NetLaunchInfo info )
|
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.inviteID, info.lang, info.dict,
|
||||||
info.nPlayersT );
|
info.nPlayersT );
|
||||||
}
|
}
|
||||||
|
@ -473,8 +466,8 @@ public class GameUtils {
|
||||||
CommsAddrRec addr, int lang,
|
CommsAddrRec addr, int lang,
|
||||||
int nPlayersT, int nPlayersH )
|
int nPlayersT, int nPlayersH )
|
||||||
{
|
{
|
||||||
return makeNewBTGame( context, GROUPID_UNSPEC, gameID, addr, lang,
|
return makeNewBTGame( context, DBUtils.GROUPID_UNSPEC, gameID, addr,
|
||||||
nPlayersT, nPlayersH );
|
lang, nPlayersT, nPlayersH );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long makeNewBTGame( Context context, long groupID,
|
public static long makeNewBTGame( Context context, long groupID,
|
||||||
|
@ -496,7 +489,7 @@ public class GameUtils {
|
||||||
int lang, String dict, int nPlayersT,
|
int lang, String dict, int nPlayersT,
|
||||||
int nPlayersH )
|
int nPlayersH )
|
||||||
{
|
{
|
||||||
return makeNewSMSGame( context, GROUPID_UNSPEC, gameID, addr,
|
return makeNewSMSGame( context, DBUtils.GROUPID_UNSPEC, gameID, addr,
|
||||||
lang, dict, nPlayersT, nPlayersH );
|
lang, dict, nPlayersT, nPlayersH );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ public class GamesList extends XWExpandableListActivity
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final int[] DEBUG_ITEMS = {
|
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_storedb,
|
||||||
R.id.games_menu_checkupdates,
|
R.id.games_menu_checkupdates,
|
||||||
};
|
};
|
||||||
|
@ -483,11 +483,12 @@ public class GamesList extends XWExpandableListActivity
|
||||||
// DBUtils.DBChangeListener interface
|
// DBUtils.DBChangeListener interface
|
||||||
public void gameSaved( final long rowid, final boolean countChanged )
|
public void gameSaved( final long rowid, final boolean countChanged )
|
||||||
{
|
{
|
||||||
post( new Runnable() {
|
runOnUiThread( new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if ( countChanged ) {
|
if ( countChanged ) {
|
||||||
onContentChanged();
|
onContentChanged();
|
||||||
} else {
|
} else {
|
||||||
|
Assert.assertTrue( 0 <= rowid );
|
||||||
m_adapter.inval( rowid );
|
m_adapter.inval( rowid );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -727,7 +728,7 @@ public class GamesList extends XWExpandableListActivity
|
||||||
boolean changeContent = false;
|
boolean changeContent = false;
|
||||||
boolean dropSels = false;
|
boolean dropSels = false;
|
||||||
int groupPos = getSelGroupPos();
|
int groupPos = getSelGroupPos();
|
||||||
long groupID = -1;
|
long groupID = DBUtils.GROUPID_UNSPEC;
|
||||||
if ( 0 <= groupPos ) {
|
if ( 0 <= groupPos ) {
|
||||||
groupID = m_adapter.getGroupIDFor( groupPos );
|
groupID = m_adapter.getGroupIDFor( groupPos );
|
||||||
}
|
}
|
||||||
|
@ -820,7 +821,8 @@ public class GamesList extends XWExpandableListActivity
|
||||||
byte[] stream = GameUtils.savedGame( GamesList.this,
|
byte[] stream = GameUtils.savedGame( GamesList.this,
|
||||||
selRowIDs[0] );
|
selRowIDs[0] );
|
||||||
GameLock lock =
|
GameLock lock =
|
||||||
GameUtils.saveNewGame( GamesList.this, stream );
|
GameUtils.saveNewGame( GamesList.this, stream,
|
||||||
|
getSaveGroup() );
|
||||||
DBUtils.saveSummary( GamesList.this, lock, smry );
|
DBUtils.saveSummary( GamesList.this, lock, smry );
|
||||||
m_selGames.add( lock.getRowid() );
|
m_selGames.add( lock.getRowid() );
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
@ -1053,6 +1055,9 @@ public class GamesList extends XWExpandableListActivity
|
||||||
|
|
||||||
private void startNewGameActivity( long groupID )
|
private void startNewGameActivity( long groupID )
|
||||||
{
|
{
|
||||||
|
if ( DBUtils.GROUPID_UNSPEC == groupID ) {
|
||||||
|
groupID = getSaveGroup();
|
||||||
|
}
|
||||||
NewGameActivity.startActivity( this, groupID );
|
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 )
|
public static void onGameDictDownload( Context context, Intent intent )
|
||||||
{
|
{
|
||||||
intent.setClass( context, GamesList.class );
|
intent.setClass( context, GamesList.class );
|
||||||
|
|
|
@ -79,6 +79,7 @@ public class NewGameActivity extends XWActivity {
|
||||||
getBundledData( savedInstanceState );
|
getBundledData( savedInstanceState );
|
||||||
|
|
||||||
m_groupID = getIntent().getLongExtra( GROUPID_EXTRA, -1 );
|
m_groupID = getIntent().getLongExtra( GROUPID_EXTRA, -1 );
|
||||||
|
Assert.assertTrue( -1 != m_groupID );
|
||||||
|
|
||||||
setContentView( R.layout.new_game );
|
setContentView( R.layout.new_game );
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ import android.text.TextUtils;
|
||||||
import com.google.android.gcm.GCMRegistrar;
|
import com.google.android.gcm.GCMRegistrar;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
public class XWPrefs {
|
public class XWPrefs {
|
||||||
|
|
||||||
public static boolean getSMSEnabled( Context context )
|
public static boolean getSMSEnabled( Context context )
|
||||||
|
@ -302,11 +304,12 @@ public class XWPrefs {
|
||||||
public static long getDefaultNewGameGroup( Context context )
|
public static long getDefaultNewGameGroup( Context context )
|
||||||
{
|
{
|
||||||
return getPrefsLong( context, R.string.key_default_group,
|
return getPrefsLong( context, R.string.key_default_group,
|
||||||
DBUtils.ROWID_NOTFOUND );
|
DBUtils.GROUPID_UNSPEC );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setDefaultNewGameGroup( Context context, long val )
|
public static void setDefaultNewGameGroup( Context context, long val )
|
||||||
{
|
{
|
||||||
|
Assert.assertTrue( DBUtils.GROUPID_UNSPEC != val );
|
||||||
setPrefsLong( context, R.string.key_default_group, val );
|
setPrefsLong( context, R.string.key_default_group, val );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue