From 550795d3a127ce0c407b84b8d553feff3b0d0c15 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sat, 4 Sep 2021 15:19:40 -0700 Subject: [PATCH] don't lose track of what's open when device rotates GamesListDelegate is the wrong place to track open games (boards). Let's try doing it in BoardDelegate. --- .../eehouse/android/xw4/BoardDelegate.java | 27 +++++++++++++++++++ .../org/eehouse/android/xw4/GameListItem.java | 1 + .../android/xw4/GamesListDelegate.java | 17 +++--------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java index d83887bb2..6ab8b5df1 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java @@ -47,6 +47,7 @@ import android.widget.TextView; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -491,6 +492,7 @@ public class BoardDelegate extends DelegateBase m_rowid = args.getLong( GameUtils.INTENT_KEY_ROWID, -1 ); Log.i( TAG, "opening rowid %d", m_rowid ); m_overNotShown = true; + noteOpened( m_rowid ); } // init private void getLock() @@ -600,6 +602,7 @@ public class BoardDelegate extends DelegateBase closeIfFinishing( true ); releaseThreadOnce(); GamesListDelegate.boardDestroyed( m_rowid ); + noteClosed( m_rowid ); super.onDestroy(); } @@ -3037,6 +3040,30 @@ public class BoardDelegate extends DelegateBase } } + // This might need to map rowid->openCount so opens can stack + static Set sOpenRows = new HashSet<>(); + + private static void noteOpened( long rowid ) + { + Log.d( TAG, "noteOpened(%d)", rowid ); + Assert.assertTrueNR( !sOpenRows.contains(rowid) ); + sOpenRows.add( rowid ); + } + + private static void noteClosed( long rowid ) + { + Log.d( TAG, "noteClosed(%d)", rowid ); + Assert.assertTrueNR( sOpenRows.contains(rowid) ); + sOpenRows.remove( rowid ); + } + + static boolean gameIsOpen( long rowid ) + { + boolean result = sOpenRows.contains( rowid ); + Log.d( TAG, "gameIsOpen(%d) => %b", rowid, result ); + return result; + } + private static void setupRematchFor( Activity activity, GamePtr gamePtr, GameSummary summary, CurGameInfo gi ) { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameListItem.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameListItem.java index f9d1acf59..9dd056c83 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameListItem.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameListItem.java @@ -167,6 +167,7 @@ public class GameListItem extends LinearLayout } // View.OnClickListener interface + @Override public void onClick( View view ) { int id = view.getId(); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java index 60df6bbaf..45177f516 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java @@ -611,7 +611,6 @@ public class GamesListDelegate extends ListDelegateBase private int m_missingDictLang; private String m_nameField; private NetLaunchInfo m_netLaunchInfo; - private Set m_launchedGames; // prevent problems with double-taps private boolean m_menuPrepared; private String m_origTitle; private Button[] m_newGameButtons; @@ -624,7 +623,6 @@ public class GamesListDelegate extends ListDelegateBase { super( delegator, sis, R.layout.game_list, R.menu.games_list_menu ); m_activity = delegator.getActivity(); - m_launchedGames = new HashSet<>(); s_self = this; } @@ -1120,7 +1118,6 @@ public class GamesListDelegate extends ListDelegateBase protected void handleNewIntent( Intent intent ) { Log.d( TAG, "handleNewIntent(extras={%s})", DbgUtils.extrasToString( intent ) ); - m_launchedGames.clear(); Assert.assertNotNull( intent ); tryStartsFromIntent( intent ); } @@ -1259,8 +1256,6 @@ public class GamesListDelegate extends ListDelegateBase { if ( hasFocus ) { updateField(); - - m_launchedGames.clear(); // This is probably wrong!!! } } @@ -1294,7 +1289,6 @@ public class GamesListDelegate extends ListDelegateBase switch( change ) { case GAME_DELETED: m_adapter.removeGame( rowid ); - m_launchedGames.remove( rowid ); m_mySIS.selGames.remove( rowid ); invalidateOptionsMenuIf(); break; @@ -1328,7 +1322,7 @@ public class GamesListDelegate extends ListDelegateBase private void openWithChecks( long rowid, GameSummary summary ) { - if ( ! m_launchedGames.contains( rowid ) ) { + if ( ! BoardDelegate.gameIsOpen( rowid ) ) { if ( Quarantine.safeToOpen( rowid ) ) { makeNotAgainBuilder( R.string.not_again_newselect, R.string.key_notagain_newselect, @@ -1702,7 +1696,7 @@ public class GamesListDelegate extends ListDelegateBase // currently open enable = 0 < nGamesSelected; for ( long row : m_mySIS.selGames ) { - enable = enable && !m_launchedGames.contains( row ); + enable = enable && !BoardDelegate.gameIsOpen( row ); } Utils.setItemVisible( menu, R.id.games_game_delete, enable ); Utils.setItemVisible( menu, R.id.games_game_reset, enable ); @@ -1922,7 +1916,7 @@ public class GamesListDelegate extends ListDelegateBase enable = BuildConfig.DEBUG || XWPrefs.getDebugEnabled( m_activity ); Utils.setItemVisible( menu, R.id.games_game_markbad, enable ); - enable = !m_launchedGames.contains( rowID ); + enable = !BoardDelegate.gameIsOpen( rowID ); Utils.setItemVisible( menu, R.id.games_game_delete, enable ); Utils.setItemVisible( menu, R.id.games_game_reset, enable ); } else { @@ -2847,8 +2841,7 @@ public class GamesListDelegate extends ListDelegateBase { if ( DBUtils.ROWID_NOTFOUND == rowid ) { Log.d( TAG, "launchGame(): dropping bad rowid" ); - } else if ( ! m_launchedGames.contains( rowid ) ) { - m_launchedGames.add( rowid ); + } else if ( ! BoardDelegate.gameIsOpen( rowid ) ) { if ( m_adapter.inExpandedGroup( rowid ) ) { setSelGame( rowid ); } @@ -3057,8 +3050,6 @@ public class GamesListDelegate extends ListDelegateBase public static void boardDestroyed( long rowid ) { if ( null != s_self ) { - // remove likely a no-op: launching clears the set, but shouldn't - s_self.m_launchedGames.remove( rowid ); s_self.invalidateOptionsMenuIf(); } }