From f305cbb9fe0e731d0e93a4cef8dcd7900c83b972 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sun, 13 Oct 2013 21:26:59 -0700 Subject: [PATCH] On resume of GamesList, remove from selected set any game that no longer exists. --- .../src/org/eehouse/android/xw4/DBUtils.java | 27 +++++++++++++++++++ .../org/eehouse/android/xw4/GamesList.java | 16 ++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java index 3aa7893c1..6cf4ed192 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -1020,6 +1020,33 @@ public class DBUtils { return result; } + public static Set getAllGames( Context context ) + { + HashSet result = null; + initDB( context ); + String[] columns = { ROW_ID }; + synchronized( s_dbHelper ) { + SQLiteDatabase db = s_dbHelper.getReadableDatabase(); + Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns, + null, // selection + null, // args + null, // groupBy + null, // having + null + ); + int index = cursor.getColumnIndex( ROW_ID ); + result = new HashSet( cursor.getCount() ); + for ( int ii = 0; cursor.moveToNext(); ++ii ) { + long rowid = cursor.getInt( index ); + result.add( rowid ); + } + cursor.close(); + db.close(); + } + + return result; + } + public static long getGroupForGame( Context context, long rowid ) { long result = ROWID_NOTFOUND; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java index 97912b56f..9c1a9d840 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -50,6 +50,7 @@ import java.io.File; import java.util.Date; import java.util.HashSet; import java.util.Iterator; +import java.util.Set; // import android.telephony.PhoneStateListener; // import android.telephony.TelephonyManager; @@ -335,8 +336,6 @@ public class GamesList extends XWExpandableListActivity // scary, but worth playing with: // Assert.assertTrue( isTaskRoot() ); - loadSelectedRows(); - getBundledData( savedInstanceState ); setContentView(R.layout.game_list); @@ -421,6 +420,13 @@ public class GamesList extends XWExpandableListActivity // PhoneStateListener.LISTEN_DATA_CONNECTION_STATE ); } + @Override + protected void onResume() + { + super.onResume(); + loadSelectedRows(); + } + @Override protected void onPause() { @@ -1188,9 +1194,13 @@ public class GamesList extends XWExpandableListActivity { int keyID = R.string.key_selected_games; String[] asStrings = XWPrefs.getPrefsStringArray( this, keyID ); + Set allGames = DBUtils.getAllGames( this ); HashSet result = new HashSet(asStrings.length); for ( String str : asStrings ) { - result.add( Long.parseLong( str ) ); + long rowid = Long.parseLong( str ); + if ( allGames.contains( rowid ) ) { + result.add( rowid ); + } } m_selected = result; }