when there's no default new-game group, get *some* group from the DB

and make that the default, with caution to avoid any -1==groupID games
saved by previous buggy versions
This commit is contained in:
Eric House 2013-11-15 06:50:34 -08:00
parent edadc962f8
commit 3ba470573d
2 changed files with 18 additions and 3 deletions

View file

@ -1112,12 +1112,21 @@ public class DBUtils {
return result; return result;
} }
// pass ROWID_NOTFOUND to get *any* group. Because there may be
// some hidden games stored with group = -1 thanks to
// recently-fixed bugs, be sure to skip them.
public static long getGroupForGame( Context context, long rowid ) public static long getGroupForGame( Context context, long rowid )
{ {
long result = GROUPID_UNSPEC; 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( "%s != %d", DBHelper.GROUPID,
DBUtils.GROUPID_UNSPEC );
if ( ROWID_NOTFOUND != rowid ) {
selection += " AND " + String.format( ROW_ID_FMT, rowid );
}
synchronized( s_dbHelper ) { synchronized( s_dbHelper ) {
SQLiteDatabase db = s_dbHelper.getReadableDatabase(); SQLiteDatabase db = s_dbHelper.getReadableDatabase();
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns, Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,

View file

@ -303,8 +303,14 @@ public class XWPrefs {
public static long getDefaultNewGameGroup( Context context ) public static long getDefaultNewGameGroup( Context context )
{ {
return getPrefsLong( context, R.string.key_default_group, long groupID = getPrefsLong( context, R.string.key_default_group,
DBUtils.GROUPID_UNSPEC ); DBUtils.GROUPID_UNSPEC );
if ( DBUtils.GROUPID_UNSPEC == groupID ) {
groupID =
DBUtils.getGroupForGame( context, DBUtils.ROWID_NOTFOUND );
setPrefsLong( context, R.string.key_default_group, groupID );
}
return groupID;
} }
public static void setDefaultNewGameGroup( Context context, long val ) public static void setDefaultNewGameGroup( Context context, long val )