From 5e6bb507b74fb861b88f030abd621e0dc30e0d54 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 3 Feb 2015 21:43:28 -0800 Subject: [PATCH] shift responsibility for deleting new game when config activity is cancelled from games list to config activity. Fixes race condition that on emulator, and less often on device, left a game highlighted after config was cancelled that should have been deleted. --- .../org/eehouse/android/xw4/DlgDelegate.java | 2 +- .../android/xw4/GameConfigDelegate.java | 43 +++++++++++++------ .../android/xw4/GamesListDelegate.java | 10 +---- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index ff2365074..5da39b8a6 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -87,7 +87,7 @@ public class DlgDelegate { // Game configs LOCKED_CHANGE_ACTION, - EXIT_NO_SAVE, + DELETE_AND_EXIT, // New Game NEW_GAME_ACTION, diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java index 9a092d0f9..d169d3bdc 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java @@ -558,7 +558,7 @@ public class GameConfigDelegate extends DelegateBase if ( XwJNI.game_hasComms( gamePtr ) ) { XwJNI.comms_getAddr( gamePtr, m_carOrig ); m_remoteAddrs = XwJNI.comms_getAddrs( gamePtr ); - } else if (DeviceRole.SERVER_STANDALONE != m_giOrig.serverRole){ + } else if ( !localOnlyGame() ) { String relayName = XWPrefs.getDefaultRelayHost( m_activity ); int relayPort = XWPrefs.getDefaultRelayPort( m_activity ); XwJNI.comms_getInitialAddr( m_carOrig, relayName, relayPort ); @@ -644,7 +644,8 @@ public class GameConfigDelegate extends DelegateBase case SMS_CONFIG_ACTION: Utils.launchSettings( m_activity ); break; - case EXIT_NO_SAVE: + case DELETE_AND_EXIT: + deleteGame(); finish(); break; default: @@ -652,7 +653,7 @@ public class GameConfigDelegate extends DelegateBase } } else if ( AlertDialog.BUTTON_NEGATIVE == button ) { switch ( action ) { - case EXIT_NO_SAVE: + case DELETE_AND_EXIT: showDialog( DlgID.CHANGE_CONN ); break; default: @@ -697,11 +698,11 @@ public class GameConfigDelegate extends DelegateBase // from here if there's no confirmation needed, or launch // a new dialog whose OK button does the same thing. saveChanges(); - if ( 0 == m_conTypes.size() ) { + if ( !localOnlyGame() && 0 == m_conTypes.size() ) { showConfirmThen( R.string.config_no_connvia, R.string.button_discard, R.string.button_edit, - Action.EXIT_NO_SAVE ); + Action.DELETE_AND_EXIT ); } else if ( m_forResult ) { applyChanges( true ); Intent intent = new Intent(); @@ -730,21 +731,35 @@ public class GameConfigDelegate extends DelegateBase if ( null == m_gameLock ) { // Do nothing; we're on our way out } else if ( keyCode == KeyEvent.KEYCODE_BACK ) { - saveChanges(); - if ( !m_gameStarted ) { // no confirm needed - applyChanges( true ); - } else if ( m_giOrig.changesMatter(m_gi) - || m_carOrig.changesMatter(m_car) ) { - showDialog( DlgID.CONFIRM_CHANGE ); - consumed = true; // don't dismiss activity yet! + if ( m_forResult ) { + deleteGame(); } else { - applyChanges( false ); + saveChanges(); + if ( !m_gameStarted ) { // no confirm needed + applyChanges( true ); + } else if ( m_giOrig.changesMatter(m_gi) + || m_carOrig.changesMatter(m_car) ) { + showDialog( DlgID.CONFIRM_CHANGE ); + consumed = true; // don't dismiss activity yet! + } else { + applyChanges( false ); + } } } return consumed; } + private void deleteGame() + { + Assert.assertTrue( m_forResult ); + if ( null != m_gameLock ) { + DBUtils.deleteGame( m_activity, m_gameLock ); + m_gameLock.unlock(); + m_gameLock = null; + } + } + private void loadPlayersList() { m_playerLayout.removeAllViews(); @@ -1178,7 +1193,7 @@ public class GameConfigDelegate extends DelegateBase private boolean localOnlyGame() { - return 0 == m_conTypes.size(); + return DeviceRole.SERVER_STANDALONE == m_giOrig.serverRole; } public static void editForResult( Activity parent, int requestCode, diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java index 477c85665..3b0bd0137 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java @@ -552,7 +552,6 @@ public class GamesListDelegate extends ListDelegateBase private String m_missingDict; private String m_missingDictName; private long m_missingDictRowId = DBUtils.ROWID_NOTFOUND; - private long m_configRowID = DBUtils.ROWID_NOTFOUND; private int m_missingDictMenuId; private String[] m_sameLangDicts; private int m_missingDictLang; @@ -1191,17 +1190,11 @@ public class GamesListDelegate extends ListDelegateBase } break; case CONFIG_GAME: - if ( cancelled ) { - if ( DBUtils.ROWID_NOTFOUND != m_configRowID ) { - long[] rowids = { m_configRowID }; - deleteGames( rowids ); - } - } else { + if ( !cancelled ) { long rowID = data.getLongExtra( GameUtils.INTENT_KEY_ROWID, DBUtils.ROWID_NOTFOUND ); GameUtils.launchGame( m_activity, rowID ); } - m_configRowID = DBUtils.ROWID_NOTFOUND; break; } } @@ -2105,7 +2098,6 @@ public class GamesListDelegate extends ListDelegateBase if ( doConfigure ) { // configure it - m_configRowID = rowID; GameConfigDelegate.editForResult( m_activity, CONFIG_GAME, rowID ); } else { // launch it