On resume of GamesList, remove from selected set any game that no

longer exists.
This commit is contained in:
Eric House 2013-10-13 21:26:59 -07:00
parent a6d8806a7c
commit f305cbb9fe
2 changed files with 40 additions and 3 deletions

View file

@ -1020,6 +1020,33 @@ public class DBUtils {
return result;
}
public static Set<Long> getAllGames( Context context )
{
HashSet<Long> 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<Long>( 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;

View file

@ -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<Long> allGames = DBUtils.getAllGames( this );
HashSet<Long> result = new HashSet<Long>(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;
}