mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-09 05:24:44 +01:00
fix problems recently introduced to GameConfig
This commit is contained in:
parent
d6b4070905
commit
2105c43987
6 changed files with 62 additions and 35 deletions
|
@ -174,7 +174,9 @@ public class DelegateBase implements DlgClickNotify,
|
||||||
|
|
||||||
protected boolean isFinishing()
|
protected boolean isFinishing()
|
||||||
{
|
{
|
||||||
return m_activity.isFinishing();
|
boolean result = m_activity.isFinishing();
|
||||||
|
// DbgUtils.logf( "%s.isFinishing() => %b", getClass().getSimpleName(), result );
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Intent getIntent()
|
protected Intent getIntent()
|
||||||
|
|
|
@ -207,6 +207,7 @@ public class DlgDelegate {
|
||||||
|
|
||||||
protected void showDialog( DlgID dlgID )
|
protected void showDialog( DlgID dlgID )
|
||||||
{
|
{
|
||||||
|
// DbgUtils.logf( "showDialog(%s)", dlgID.toString() );
|
||||||
if ( !m_activity.isFinishing() ) {
|
if ( !m_activity.isFinishing() ) {
|
||||||
s_pendings.put( dlgID, new WeakReference<DelegateBase>(m_dlgt) );
|
s_pendings.put( dlgID, new WeakReference<DelegateBase>(m_dlgt) );
|
||||||
m_activity.showDialog( dlgID.ordinal() );
|
m_activity.showDialog( dlgID.ordinal() );
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
,XWListItem.DeleteCallback
|
,XWListItem.DeleteCallback
|
||||||
,RefreshNamesTask.NoNameFound {
|
,RefreshNamesTask.NoNameFound {
|
||||||
|
|
||||||
private static final String INTENT_FORRESULT_ROWID = "forresult";
|
private static final String INTENT_FORRESULT_NEWGAME = "newgame";
|
||||||
|
|
||||||
private static final String WHICH_PLAYER = "WHICH_PLAYER";
|
private static final String WHICH_PLAYER = "WHICH_PLAYER";
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
private CheckBox m_joinPublicCheck;
|
private CheckBox m_joinPublicCheck;
|
||||||
private CheckBox m_gameLockedCheck;
|
private CheckBox m_gameLockedCheck;
|
||||||
private boolean m_isLocked;
|
private boolean m_isLocked;
|
||||||
|
private boolean m_haveClosed;
|
||||||
private LinearLayout m_publicRoomsSet;
|
private LinearLayout m_publicRoomsSet;
|
||||||
private LinearLayout m_privateRoomsSet;
|
private LinearLayout m_privateRoomsSet;
|
||||||
|
|
||||||
|
@ -88,7 +89,7 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
private Spinner m_roomChoose;
|
private Spinner m_roomChoose;
|
||||||
// private Button m_configureButton;
|
// private Button m_configureButton;
|
||||||
private long m_rowid;
|
private long m_rowid;
|
||||||
private boolean m_forResult;
|
private boolean m_isNewGame;
|
||||||
private CurGameInfo m_gi;
|
private CurGameInfo m_gi;
|
||||||
private CurGameInfo m_giOrig;
|
private CurGameInfo m_giOrig;
|
||||||
private JNIThread m_jniThread;
|
private JNIThread m_jniThread;
|
||||||
|
@ -226,9 +227,13 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
public void onDismiss( DialogInterface di )
|
public void onDismiss( DialogInterface di )
|
||||||
{
|
{
|
||||||
GameConfigDelegate self = curThis();
|
GameConfigDelegate self = curThis();
|
||||||
if ( self.m_gi.forceRemoteConsistent() ) {
|
if ( null != self
|
||||||
|
&& self.m_gi.forceRemoteConsistent() ) {
|
||||||
self.showToast( R.string.forced_consistent );
|
self.showToast( R.string.forced_consistent );
|
||||||
self.loadPlayersList();
|
self.loadPlayersList();
|
||||||
|
} else {
|
||||||
|
DbgUtils.logf( "GameConfigDelegate.onDismiss(): "
|
||||||
|
+ "no visible self" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -242,7 +247,7 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
GameConfigDelegate self = curThis();
|
GameConfigDelegate self = curThis();
|
||||||
self.applyChanges( true );
|
self.applyChanges( true );
|
||||||
if ( DlgID.CONFIRM_CHANGE_PLAY == dlgID ) {
|
if ( DlgID.CONFIRM_CHANGE_PLAY == dlgID ) {
|
||||||
self.launchGame();
|
self.launchGame( true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -254,7 +259,7 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
dlpos = new DialogInterface.OnClickListener() {
|
dlpos = new DialogInterface.OnClickListener() {
|
||||||
public void onClick( DialogInterface dlg,
|
public void onClick( DialogInterface dlg,
|
||||||
int whichButton ) {
|
int whichButton ) {
|
||||||
curThis().launchGame();
|
curThis().finishAndLaunch();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
@ -266,7 +271,7 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
dialog.setOnDismissListener( new DialogInterface.
|
dialog.setOnDismissListener( new DialogInterface.
|
||||||
OnDismissListener() {
|
OnDismissListener() {
|
||||||
public void onDismiss( DialogInterface di ) {
|
public void onDismiss( DialogInterface di ) {
|
||||||
curThis().finish();
|
curThis().closeNoSave();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@ -479,7 +484,7 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
m_rowid = args.getLong( GameUtils.INTENT_KEY_ROWID, DBUtils.ROWID_NOTFOUND );
|
m_rowid = args.getLong( GameUtils.INTENT_KEY_ROWID, DBUtils.ROWID_NOTFOUND );
|
||||||
Assert.assertTrue( DBUtils.ROWID_NOTFOUND != m_rowid );
|
Assert.assertTrue( DBUtils.ROWID_NOTFOUND != m_rowid );
|
||||||
m_forResult = args.getBoolean( INTENT_FORRESULT_ROWID, false );
|
m_isNewGame = args.getBoolean( INTENT_FORRESULT_NEWGAME, false );
|
||||||
|
|
||||||
m_connectSetRelay = findViewById( R.id.connect_set_relay );
|
m_connectSetRelay = findViewById( R.id.connect_set_relay );
|
||||||
|
|
||||||
|
@ -678,6 +683,8 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
public void dlgButtonClicked( Action action, int button, Object[] params )
|
public void dlgButtonClicked( Action action, int button, Object[] params )
|
||||||
{
|
{
|
||||||
boolean callSuper = false;
|
boolean callSuper = false;
|
||||||
|
Assert.assertTrue( curThis() == this );
|
||||||
|
|
||||||
if ( AlertDialog.BUTTON_POSITIVE == button ) {
|
if ( AlertDialog.BUTTON_POSITIVE == button ) {
|
||||||
switch( action ) {
|
switch( action ) {
|
||||||
case LOCKED_CHANGE_ACTION:
|
case LOCKED_CHANGE_ACTION:
|
||||||
|
@ -687,10 +694,10 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
Utils.launchSettings( m_activity );
|
Utils.launchSettings( m_activity );
|
||||||
break;
|
break;
|
||||||
case DELETE_AND_EXIT:
|
case DELETE_AND_EXIT:
|
||||||
if ( m_forResult ) {
|
if ( m_isNewGame ) {
|
||||||
deleteGame();
|
deleteGame();
|
||||||
}
|
}
|
||||||
finish();
|
closeNoSave();
|
||||||
break;
|
break;
|
||||||
case SET_ENABLE_PUBLIC:
|
case SET_ENABLE_PUBLIC:
|
||||||
XWPrefs.setPrefsBoolean( m_activity, R.string.key_enable_pubroom,
|
XWPrefs.setPrefsBoolean( m_activity, R.string.key_enable_pubroom,
|
||||||
|
@ -747,26 +754,19 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
// from here if there's no confirmation needed, or launch
|
// from here if there's no confirmation needed, or launch
|
||||||
// a new dialog whose OK button does the same thing.
|
// a new dialog whose OK button does the same thing.
|
||||||
saveChanges();
|
saveChanges();
|
||||||
|
|
||||||
if ( !localOnlyGame() && 0 == m_conTypes.size() ) {
|
if ( !localOnlyGame() && 0 == m_conTypes.size() ) {
|
||||||
showConfirmThen( R.string.config_no_connvia,
|
showConfirmThen( R.string.config_no_connvia,
|
||||||
R.string.button_discard,
|
R.string.button_discard,
|
||||||
R.string.button_edit,
|
R.string.button_edit,
|
||||||
Action.DELETE_AND_EXIT );
|
Action.DELETE_AND_EXIT );
|
||||||
} else if ( m_forResult ) {
|
} else if ( m_isNewGame || !m_gameStarted ) {
|
||||||
applyChanges( true );
|
saveAndClose( true );
|
||||||
Intent intent = new Intent();
|
|
||||||
intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_rowid );
|
|
||||||
setResult( Activity.RESULT_OK, intent );
|
|
||||||
finish();
|
|
||||||
} else if ( !m_gameStarted ) { // no confirm needed
|
|
||||||
applyChanges( true );
|
|
||||||
launchGame();
|
|
||||||
} else if ( m_giOrig.changesMatter(m_gi)
|
} else if ( m_giOrig.changesMatter(m_gi)
|
||||||
|| m_carOrig.changesMatter(m_car) ) {
|
|| m_carOrig.changesMatter(m_car) ) {
|
||||||
showDialog( DlgID.CONFIRM_CHANGE_PLAY );
|
showDialog( DlgID.CONFIRM_CHANGE_PLAY );
|
||||||
} else {
|
} else {
|
||||||
applyChanges( false );
|
finishAndLaunch();
|
||||||
launchGame();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -774,12 +774,42 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
}
|
}
|
||||||
} // onClick
|
} // onClick
|
||||||
|
|
||||||
|
private void saveAndClose( boolean forceNew )
|
||||||
|
{
|
||||||
|
DbgUtils.logf( "GameConfigDelegate.saveAndClose(forceNew=%b)",
|
||||||
|
forceNew );
|
||||||
|
applyChanges( forceNew );
|
||||||
|
|
||||||
|
finishAndLaunch();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void finishAndLaunch()
|
||||||
|
{
|
||||||
|
if ( !m_haveClosed ) {
|
||||||
|
m_haveClosed = true;
|
||||||
|
DbgUtils.logf( "GameConfigDelegate.finishAndLaunch()" );
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_rowid );
|
||||||
|
setResult( Activity.RESULT_OK, intent );
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void closeNoSave()
|
||||||
|
{
|
||||||
|
if ( !m_haveClosed ) {
|
||||||
|
m_haveClosed = true;
|
||||||
|
setResult( Activity.RESULT_CANCELED, null );
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean handleBackPressed()
|
protected boolean handleBackPressed()
|
||||||
{
|
{
|
||||||
boolean consumed = false;
|
boolean consumed = false;
|
||||||
if ( ! isFinishing() ) {
|
if ( ! isFinishing() ) {
|
||||||
if ( m_forResult ) {
|
if ( m_isNewGame ) {
|
||||||
deleteGame();
|
deleteGame();
|
||||||
} else {
|
} else {
|
||||||
saveChanges();
|
saveChanges();
|
||||||
|
@ -1200,13 +1230,13 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void launchGame()
|
private void launchGame( boolean forceNew )
|
||||||
{
|
{
|
||||||
if ( m_conTypes.contains( CommsConnType.COMMS_CONN_RELAY )
|
if ( m_conTypes.contains( CommsConnType.COMMS_CONN_RELAY )
|
||||||
&& 0 == m_car.ip_relay_invite.length() ) {
|
&& 0 == m_car.ip_relay_invite.length() ) {
|
||||||
showOKOnlyDialog( R.string.no_empty_rooms );
|
showOKOnlyDialog( R.string.no_empty_rooms );
|
||||||
} else {
|
} else {
|
||||||
GameUtils.launchGameAndFinish( getDelegator(), m_rowid );
|
saveAndClose( forceNew );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1237,11 +1267,11 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
|
|
||||||
public static void editForResult( Delegator delegator,
|
public static void editForResult( Delegator delegator,
|
||||||
RequestCode requestCode,
|
RequestCode requestCode,
|
||||||
long rowID )
|
long rowID, boolean newGame )
|
||||||
{
|
{
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putLong( GameUtils.INTENT_KEY_ROWID, rowID );
|
bundle.putLong( GameUtils.INTENT_KEY_ROWID, rowID );
|
||||||
bundle.putBoolean( INTENT_FORRESULT_ROWID, true );
|
bundle.putBoolean( INTENT_FORRESULT_NEWGAME, newGame );
|
||||||
|
|
||||||
if ( delegator.inDPMode() ) {
|
if ( delegator.inDPMode() ) {
|
||||||
delegator.addFragmentForResult( new GameConfigFrag( delegator ),
|
delegator.addFragmentForResult( new GameConfigFrag( delegator ),
|
||||||
|
|
|
@ -867,12 +867,6 @@ public class GameUtils {
|
||||||
launchGame( delegator, rowid, false );
|
launchGame( delegator, rowid, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void launchGameAndFinish( Delegator delegator, long rowid )
|
|
||||||
{
|
|
||||||
launchGame( delegator, rowid );
|
|
||||||
delegator.getActivity().finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class FeedUtilsImpl extends UtilCtxtImpl {
|
private static class FeedUtilsImpl extends UtilCtxtImpl {
|
||||||
private Context m_context;
|
private Context m_context;
|
||||||
private long m_rowid;
|
private long m_rowid;
|
||||||
|
|
|
@ -1695,7 +1695,7 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
case R.id.games_game_config:
|
case R.id.games_game_config:
|
||||||
GameConfigDelegate.editForResult( getDelegator(),
|
GameConfigDelegate.editForResult( getDelegator(),
|
||||||
RequestCode.CONFIG_GAME,
|
RequestCode.CONFIG_GAME,
|
||||||
selRowIDs[0] );
|
selRowIDs[0], false );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.games_game_move:
|
case R.id.games_game_move:
|
||||||
|
@ -2502,7 +2502,7 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
// configure it
|
// configure it
|
||||||
GameConfigDelegate.editForResult( getDelegator(),
|
GameConfigDelegate.editForResult( getDelegator(),
|
||||||
RequestCode.CONFIG_GAME,
|
RequestCode.CONFIG_GAME,
|
||||||
rowID );
|
rowID, true );
|
||||||
} else {
|
} else {
|
||||||
// launch it
|
// launch it
|
||||||
GameUtils.launchGame( getDelegator(), rowID );
|
GameUtils.launchGame( getDelegator(), rowID );
|
||||||
|
|
|
@ -282,9 +282,9 @@ public class MainActivity extends XWActivity
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
public void onBackStackChanged()
|
public void onBackStackChanged()
|
||||||
{
|
{
|
||||||
DbgUtils.logf( "MainActivity.onBackStackChanged()" );
|
|
||||||
// make sure the right-most are visible
|
// make sure the right-most are visible
|
||||||
int fragCount = getSupportFragmentManager().getBackStackEntryCount();
|
int fragCount = getSupportFragmentManager().getBackStackEntryCount();
|
||||||
|
DbgUtils.logf( "MainActivity.onBackStackChanged(); count now %d", fragCount );
|
||||||
if ( 0 == fragCount ) {
|
if ( 0 == fragCount ) {
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue