From 3350ca19b783827803532bc5a9c9d3076f8f1ad9 Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 4 Jan 2021 21:26:12 -0800 Subject: [PATCH] use same (new) dialog for solo games --- .../android/xw4/GamesListDelegate.java | 72 +++++-------------- .../eehouse/android/xw4/NewWithKnowns.java | 32 ++++++--- .../main/res/layout/new_game_with_knowns.xml | 14 +++- .../app/src/main/res/values/strings.xml | 5 +- 4 files changed, 55 insertions(+), 68 deletions(-) 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 e44d8f8ab..8ee61f69c 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 @@ -867,16 +867,12 @@ public class GamesListDelegate extends ListDelegateBase case GAMES_LIST_NEWGAME: boolean solo = (Boolean)params[0]; - if ( solo ) { - dialog = mkNewSoloGameDialog(); - } else { - dialog = mkNewNetGameDialog(); - if ( XwJNI.hasKnownPlayers() ) { - makeNotAgainBuilder( R.string.not_again_quicknetgame, - R.string.key_na_quicknetgame ) - .setTitle( R.string.new_feature_title ) - .show(); - } + dialog = mkNewNetGameDialog( solo ); + if ( !solo && XwJNI.hasKnownPlayers() ) { + makeNotAgainBuilder( R.string.not_again_quicknetgame, + R.string.key_na_quicknetgame ) + .setTitle( R.string.new_feature_title ) + .show(); } break; @@ -918,49 +914,16 @@ public class GamesListDelegate extends ListDelegateBase return dialog; } // makeDialog - private Dialog mkNewSoloGameDialog() - { - final LinearLayout view = (LinearLayout) - LocUtils.inflate( m_activity, R.layout.msg_label_and_edit ); - final EditWClear edit = (EditWClear)view.findViewById( R.id.edit ); - edit.setText( GameUtils.makeDefaultName( m_activity ) ); - - String msg = getString( R.string.new_game_message ); - TextView tmpEdit = (TextView)view.findViewById( R.id.msg ); - tmpEdit.setText( msg ); - - OnClickListener lstnr = new OnClickListener() { - public void onClick( DialogInterface dlg, int item ) { - String name = edit.getText().toString(); - curThis().makeThenLaunchOrConfigure( name, true, false ); - } - }; - - AlertDialog.Builder ab = makeAlertBuilder() - .setView( view ) - .setTitle( R.string.new_game ) - .setIcon( R.drawable.ic_sologame ) - .setPositiveButton( R.string.newgame_configure_first, lstnr ); - OnClickListener lstnr2 = new OnClickListener() { - public void onClick( DialogInterface dlg, int item ) { - String name = edit.getText().toString(); - curThis().makeThenLaunchOrConfigure( name, false, false ); - } - }; - ab.setNegativeButton( R.string.use_defaults, lstnr2 ); - return ab.create(); - } - - private Dialog mkNewNetGameDialog() + private Dialog mkNewNetGameDialog( final boolean standalone ) { // String[] names = XwJNI.kplr_getPlayers(); final NewWithKnowns view = (NewWithKnowns) LocUtils.inflate( m_activity, R.layout.new_game_with_knowns ); - view.setGameName( GameUtils.makeDefaultName( m_activity ) ); + view.configure( standalone, GameUtils.makeDefaultName( m_activity ) ); AlertDialog.Builder ab = makeAlertBuilder() .setView( view ) - .setTitle( R.string.new_game_networked ) - .setIcon( R.drawable.ic_multigame ) + .setTitle( standalone ? R.string.new_game : R.string.new_game_networked ) + .setIcon( standalone ? R.drawable.ic_sologame: R.drawable.ic_multigame ) .setPositiveButton( android.R.string.cancel, new OnClickListener() { @Override public void onClick( DialogInterface dlg, int item ) { @@ -968,20 +931,21 @@ public class GamesListDelegate extends ListDelegateBase @Override public void onUseKnown( String knownName, String gameName ) { + Assert.assertTrueNR( !standalone ); CommsAddrRec addr = XwJNI.kplr_getAddr( knownName ); if ( null != addr ) { launchLikeRematch( addr, gameName ); } } @Override - public void onInviteLater( String gameName ) + public void onStartGame( String gameName, boolean solo, + boolean configFirst ) { - curThis().makeThenLaunchOrConfigure( gameName, false, false ); - } - @Override - public void onConfigureFirst( String gameName ) - { - curThis().makeThenLaunchOrConfigure( gameName, true, false ); + Assert.assertTrueNR( solo == standalone ); + Assert.assertTrueNR( solo == m_mySIS.nextIsSolo ); + curThis().makeThenLaunchOrConfigure( gameName, + configFirst, + false ); } } ); } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NewWithKnowns.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NewWithKnowns.java index fb0a00921..5a15ad66a 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NewWithKnowns.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NewWithKnowns.java @@ -46,14 +46,14 @@ public class NewWithKnowns extends LinearLayout public interface ButtonCallbacks { void onUseKnown( String knownName, String gameName ); - void onInviteLater( String gameName ); - void onConfigureFirst( String gameName ); + void onStartGame( String gameName, boolean solo, boolean configFirst ); } private ButtonChangeListener mListener; private String mCurKnown; private int mCurRadio; private Spinner mNamesSpinner; + private boolean mStandalone; public NewWithKnowns( Context cx, AttributeSet as ) { @@ -66,9 +66,11 @@ public class NewWithKnowns extends LinearLayout mListener = listener; } - void setGameName( String gameName ) + void configure( boolean standalone, String gameName ) { - boolean hasKnowns = XwJNI.hasKnownPlayers(); + mStandalone = standalone; + boolean hasKnowns = !standalone && XwJNI.hasKnownPlayers(); + int[] toHide; if ( hasKnowns ) { String[] knowns = XwJNI.kplr_getPlayers(); mCurKnown = DBUtils.getStringFor( getContext(), KP_NAME_KEY, @@ -89,11 +91,16 @@ public class NewWithKnowns extends LinearLayout break; } } + toHide = new int[]{ R.id.radio_default, R.id.choose_expl_default, + }; } else { - int[] toHide = { R.id.radio_known, R.id.names, R.id.expl_known }; - for ( int resID : toHide ) { - findViewById(resID).setVisibility( View.GONE ); - } + toHide = new int[]{ R.id.radio_known, R.id.names, R.id.expl_known, + R.id.radio_unknown, R.id.choose_expl_new, + }; + } + + for ( int resID : toHide ) { + findViewById(resID).setVisibility(View.GONE); } EditWClear et = (EditWClear)findViewById( R.id.name_edit ); @@ -112,12 +119,14 @@ public class NewWithKnowns extends LinearLayout procs.onUseKnown( mCurKnown, gameName ); break; case R.id.radio_unknown: - procs.onInviteLater( gameName ); + case R.id.radio_default: + procs.onStartGame( gameName, mStandalone, false ); break; case R.id.radio_configure: - procs.onConfigureFirst( gameName ); + procs.onStartGame( gameName, mStandalone, true ); break; default: + Assert.failDbg(); break; } } @@ -165,11 +174,14 @@ public class NewWithKnowns extends LinearLayout .getString( context, R.string.newgame_invite_fmt, mCurKnown ); break; case R.id.radio_unknown: + case R.id.radio_default: resId = R.string.newgame_open_game; break; case R.id.radio_configure: resId = R.string.newgame_configure_game; break; + default: + Assert.failDbg(); } if ( 0 != resId ) { diff --git a/xwords4/android/app/src/main/res/layout/new_game_with_knowns.xml b/xwords4/android/app/src/main/res/layout/new_game_with_knowns.xml index 6744ecedc..db81b546f 100644 --- a/xwords4/android/app/src/main/res/layout/new_game_with_knowns.xml +++ b/xwords4/android/app/src/main/res/layout/new_game_with_knowns.xml @@ -15,11 +15,23 @@ android:layout_height="wrap_content" > + + + + + - diff --git a/xwords4/android/app/src/main/res/values/strings.xml b/xwords4/android/app/src/main/res/values/strings.xml index 350b1c8a5..e94bb88b7 100644 --- a/xwords4/android/app/src/main/res/values/strings.xml +++ b/xwords4/android/app/src/main/res/values/strings.xml @@ -2208,9 +2208,6 @@ New one-device game New networked game %1$s - Would you like to create this game - using default settings?\n\nOr would you like to configure it - first? This game must be configured before it can be opened. Use defaults @@ -2672,6 +2669,8 @@ “%1$s” to “%2$s”. Is “%2$s” already in use? + Start a solo game using the + current defaults Start a game with somebody new, sending an invitation via email, SMS, or even a QR code OR start a game with somebody you’ve