Rather than ask player for name on app install, ask every time he

creates a new game (but with a don't-ask-again check to avoid
annoying.) Make changes to DlgDelegate to support.
This commit is contained in:
Eric House 2015-11-23 07:51:31 -08:00
parent 0b0bd02e79
commit 97f24973e4
9 changed files with 842 additions and 760 deletions

File diff suppressed because it is too large Load diff

View file

@ -129,6 +129,7 @@
<string name="key_invite_multi">key_invite_multi</string> <string name="key_invite_multi">key_invite_multi</string>
<string name="key_notagain_enablepublic">key_notagain_enablepublic</string> <string name="key_notagain_enablepublic">key_notagain_enablepublic</string>
<string name="key_na_rematch_two_only">key_notagain_rematch_two_only</string> <string name="key_na_rematch_two_only">key_notagain_rematch_two_only</string>
<string name="key_notagain_dfltname">key_notagain_dfltname</string>
<string name="key_na_comms_bt">key_na_comms_bt</string> <string name="key_na_comms_bt">key_na_comms_bt</string>
<string name="key_na_comms_sms">key_na_comms_sms</string> <string name="key_na_comms_sms">key_na_comms_sms</string>

View file

@ -1720,12 +1720,11 @@
--> -->
<!-- Welcome dialog title --> <!-- Welcome dialog title -->
<string name="default_name_title">Welcome</string> <string name="default_name_title">Default player name</string>
<!-- Welcome dialog text --> <!-- Welcome dialog text -->
<string name="default_name_message">Thanks for installing <string name="default_name_message">Please enter your name
Crosswords!\n\nFeel free to enter your name here. It will be used here. It will be used when creating new games. (You can change it
when creating new games. (You can change it later in the \"New later in the \"New game default\" section of Settings.)</string>
game default\" section of Settings.)</string>
<!-- <!--
########################################################### ###########################################################
@ -2623,4 +2622,8 @@
<string name="list_item_select">Select</string> <string name="list_item_select">Select</string>
<string name="list_item_deselect">De-select</string> <string name="list_item_deselect">De-select</string>
<string name="not_again_dfltname_fmt">You are using the default
player name \"%1$s\". Would you like to personalize with your own
name before you create this game?</string>
</resources> </resources>

View file

@ -1478,12 +1478,11 @@
########################################################### ###########################################################
--> -->
<!-- Welcome dialog title --> <!-- Welcome dialog title -->
<string name="default_name_title">Emoclew</string> <string name="default_name_title">Tluafed reyalp eman</string>
<!-- Welcome dialog text --> <!-- Welcome dialog text -->
<string name="default_name_message">Sknaht rof gnillatsni <string name="default_name_message">Esaelp retne ruoy eman
!sdrowssorc\n\nLeef eerf ot retne ruoy eman ereh. Ti lliw eb desu ereh. Ti lliw eb desu nehw gnitaerc wen semag. uOy( nac egnahc ti
nehw gnitaerc wen semag. uOy( nac egnahc ti retal ni eht \"Wen retal ni eht \"Wen emag tluafed\" noitces fo Sgnittes.)</string>
emag tluafed\" noitces fo Sgnittes.)</string>
<!-- <!--
########################################################### ###########################################################
# :Dialogs: # :Dialogs:
@ -2241,4 +2240,7 @@
<string name="processing_games">Gnissecorp semag</string> <string name="processing_games">Gnissecorp semag</string>
<string name="list_item_select">Tceles</string> <string name="list_item_select">Tceles</string>
<string name="list_item_deselect">Tceles-ed</string> <string name="list_item_deselect">Tceles-ed</string>
<string name="not_again_dfltname_fmt">Uoy era gnisu eht tluafed
reyalp eman \"%1$s\". Dluow uoy ekil ot ezilanosrep htiw ruoy nwo
eman erofeb uoy etaerc siht ?emag</string>
</resources> </resources>

View file

@ -1478,12 +1478,11 @@
########################################################### ###########################################################
--> -->
<!-- Welcome dialog title --> <!-- Welcome dialog title -->
<string name="default_name_title">WELCOME</string> <string name="default_name_title">DEFAULT PLAYER NAME</string>
<!-- Welcome dialog text --> <!-- Welcome dialog text -->
<string name="default_name_message">THANKS FOR INSTALLING <string name="default_name_message">PLEASE ENTER YOUR NAME
CROSSWORDS!\n\nFEEL FREE TO ENTER YOUR NAME HERE. IT WILL BE USED HERE. IT WILL BE USED WHEN CREATING NEW GAMES. (YOU CAN CHANGE IT
WHEN CREATING NEW GAMES. (YOU CAN CHANGE IT LATER IN THE \"NEW LATER IN THE \"NEW GAME DEFAULT\" SECTION OF SETTINGS.)</string>
GAME DEFAULT\" SECTION OF SETTINGS.)</string>
<!-- <!--
########################################################### ###########################################################
# :Dialogs: # :Dialogs:
@ -2241,4 +2240,7 @@
<string name="processing_games">PROCESSING GAMES</string> <string name="processing_games">PROCESSING GAMES</string>
<string name="list_item_select">SELECT</string> <string name="list_item_select">SELECT</string>
<string name="list_item_deselect">DE-SELECT</string> <string name="list_item_deselect">DE-SELECT</string>
<string name="not_again_dfltname_fmt">YOU ARE USING THE DEFAULT
PLAYER NAME \"%1$s\". WOULD YOU LIKE TO PERSONALIZE WITH YOUR OWN
NAME BEFORE YOU CREATE THIS GAME?</string>
</resources> </resources>

View file

@ -436,6 +436,13 @@ public class DelegateBase implements DlgClickNotify,
m_dlgDelegate.showConfirmThen( msgID, action ); m_dlgDelegate.showConfirmThen( msgID, action );
} }
public void showConfirmThen( Runnable onNA, String msg, int posButton,
int negButton, Action action, Object... params )
{
m_dlgDelegate.showConfirmThen( onNA, msg, posButton, negButton, action,
params );
}
protected boolean post( Runnable runnable ) protected boolean post( Runnable runnable )
{ {
return m_dlgDelegate.post( runnable ); return m_dlgDelegate.post( runnable );

View file

@ -65,6 +65,7 @@ public class DlgDelegate {
NEW_GAME_PRESSED, NEW_GAME_PRESSED,
SET_HIDE_NEWGAME_BUTTONS, SET_HIDE_NEWGAME_BUTTONS,
DWNLD_LOC_DICT, DWNLD_LOC_DICT,
NEW_GAME_DFLT_NAME,
// BoardDelegate // BoardDelegate
UNDO_LAST_ACTION, UNDO_LAST_ACTION,
@ -561,7 +562,7 @@ public class DlgDelegate {
private Dialog createNotAgainDialog( final DlgState state, DlgID dlgID ) private Dialog createNotAgainDialog( final DlgState state, DlgID dlgID )
{ {
NotAgainView naView = (NotAgainView) final NotAgainView naView = (NotAgainView)
LocUtils.inflate( m_activity, R.layout.not_again_view ); LocUtils.inflate( m_activity, R.layout.not_again_view );
naView.setMessage( state.m_msg ); naView.setMessage( state.m_msg );
final OnClickListener lstnr_p = mkCallbackClickListener( state, naView ); final OnClickListener lstnr_p = mkCallbackClickListener( state, naView );
@ -571,18 +572,15 @@ public class DlgDelegate {
.setView( naView ) .setView( naView )
.setPositiveButton( android.R.string.ok, lstnr_p ); .setPositiveButton( android.R.string.ok, lstnr_p );
// Adding third button doesn't work for some reason. Either this
// feature goes away or the "do not show again" becomes a checkbox as
// many apps do it.
if ( null != state.m_pair ) { if ( null != state.m_pair ) {
final ActionPair more = state.m_pair; final ActionPair more = state.m_pair;
OnClickListener lstnr = new OnClickListener() { OnClickListener lstnr = new OnClickListener() {
public void onClick( DialogInterface dlg, int item ) { public void onClick( DialogInterface dlg, int item ) {
checkNotAgainCheck( state, naView );
m_clickCallback. m_clickCallback.
dlgButtonClicked( more.action, dlgButtonClicked( more.action,
AlertDialog.BUTTON_POSITIVE, AlertDialog.BUTTON_POSITIVE,
more.params ); more.params );
lstnr_p.onClick( dlg, AlertDialog.BUTTON_POSITIVE );
} }
}; };
builder.setNegativeButton( more.buttonStr, lstnr ); builder.setNegativeButton( more.buttonStr, lstnr );
@ -766,14 +764,7 @@ public class DlgDelegate {
OnClickListener cbkOnClickLstnr; OnClickListener cbkOnClickLstnr;
cbkOnClickLstnr = new OnClickListener() { cbkOnClickLstnr = new OnClickListener() {
public void onClick( DialogInterface dlg, int button ) { public void onClick( DialogInterface dlg, int button ) {
if ( null != naView && naView.getChecked() ) { checkNotAgainCheck( state, naView );
if ( 0 != state.m_prefsKey ) {
XWPrefs.setPrefsBoolean( m_activity, state.m_prefsKey,
true );
} else if ( null != state.m_onNAChecked ) {
state.m_onNAChecked.run();
}
}
if ( Action.SKIP_CALLBACK != state.m_action ) { if ( Action.SKIP_CALLBACK != state.m_action ) {
m_clickCallback.dlgButtonClicked( state.m_action, m_clickCallback.dlgButtonClicked( state.m_action,
@ -785,6 +776,18 @@ public class DlgDelegate {
return cbkOnClickLstnr; return cbkOnClickLstnr;
} }
private void checkNotAgainCheck( DlgState state, NotAgainView naView )
{
if ( null != naView && naView.getChecked() ) {
if ( 0 != state.m_prefsKey ) {
XWPrefs.setPrefsBoolean( m_activity, state.m_prefsKey,
true );
} else if ( null != state.m_onNAChecked ) {
state.m_onNAChecked.run();
}
}
}
private Dialog setCallbackDismissListener( final Dialog dialog, private Dialog setCallbackDismissListener( final Dialog dialog,
final DlgState state, final DlgState state,
DlgID dlgID ) DlgID dlgID )

View file

@ -592,6 +592,7 @@ public class GamesListDelegate extends ListDelegateBase
private Button[] m_newGameButtons; private Button[] m_newGameButtons;
private boolean m_haveShownGetDict; private boolean m_haveShownGetDict;
private Intent m_rematchIntent; private Intent m_rematchIntent;
private Object[] m_newGameParams;
public GamesListDelegate( ListDelegator delegator, Bundle sis ) public GamesListDelegate( ListDelegator delegator, Bundle sis )
{ {
@ -817,7 +818,7 @@ public class GamesListDelegate extends ListDelegateBase
} }
CommonPrefs.setDefaultPlayerName( m_activity, name ); CommonPrefs.setDefaultPlayerName( m_activity, name );
getDictForLangIf(); // hack!!! makeThenLaunchOrConfigure();
} }
}); });
break; break;
@ -828,12 +829,12 @@ public class GamesListDelegate extends ListDelegateBase
final EditText edit = (EditText)view.findViewById( R.id.edit ); final EditText edit = (EditText)view.findViewById( R.id.edit );
lstnr = new OnClickListener() { lstnr = new OnClickListener() {
public void onClick( DialogInterface dlg, int item ) { public void onClick( DialogInterface dlg, int item ) {
makeThenLaunchOrConfigure( edit, true ); makeThenLaunchOrConfigure( edit, true, false );
} }
}; };
lstnr2 = new OnClickListener() { lstnr2 = new OnClickListener() {
public void onClick( DialogInterface dlg, int item ) { public void onClick( DialogInterface dlg, int item ) {
makeThenLaunchOrConfigure( edit, false ); makeThenLaunchOrConfigure( edit, false, false );
} }
}; };
@ -915,6 +916,7 @@ public class GamesListDelegate extends ListDelegateBase
} }
} }
@Override
protected void init( Bundle savedInstanceState ) protected void init( Bundle savedInstanceState )
{ {
m_handler = new Handler(); m_handler = new Handler();
@ -950,9 +952,7 @@ public class GamesListDelegate extends ListDelegateBase
tryStartsFromIntent( getIntent() ); tryStartsFromIntent( getIntent() );
if ( !askDefaultNameIf() ) {
getDictForLangIf(); getDictForLangIf();
}
m_origTitle = getTitle(); m_origTitle = getTitle();
} // init } // init
@ -1213,6 +1213,10 @@ public class GamesListDelegate extends ListDelegateBase
reloadGame( newid ); reloadGame( newid );
break; break;
case SET_HIDE_NEWGAME_BUTTONS:
XWPrefs.setHideNewgameButtons(m_activity, true);
setupButtons();
// FALLTHRU
case NEW_GAME_PRESSED: case NEW_GAME_PRESSED:
handleNewGame( m_nextIsSolo ); handleNewGame( m_nextIsSolo );
break; break;
@ -1234,10 +1238,6 @@ public class GamesListDelegate extends ListDelegateBase
case CLEAR_SELS: case CLEAR_SELS:
clearSelections(); clearSelections();
break; break;
case SET_HIDE_NEWGAME_BUTTONS:
XWPrefs.setHideNewgameButtons( m_activity, true );
setupButtons();
break;
case DWNLD_LOC_DICT: case DWNLD_LOC_DICT:
String lang = (String)params[0]; String lang = (String)params[0];
String name = (String)params[1]; String name = (String)params[1];
@ -1263,9 +1263,18 @@ public class GamesListDelegate extends ListDelegateBase
}; };
DwnldDelegate.downloadDictInBack( m_activity, lang, name, lstnr ); DwnldDelegate.downloadDictInBack( m_activity, lang, name, lstnr );
break; break;
case NEW_GAME_DFLT_NAME:
m_newGameParams = params;
askDefaultName();
break;
default: default:
Assert.fail(); Assert.fail();
} }
} else if ( AlertDialog.BUTTON_NEGATIVE == which ) {
if ( Action.NEW_GAME_DFLT_NAME == action ) {
m_newGameParams = params;
makeThenLaunchOrConfigure();
}
} }
} }
@ -2066,17 +2075,12 @@ public class GamesListDelegate extends ListDelegateBase
} }
} }
private boolean askDefaultNameIf() private void askDefaultName()
{ {
boolean showing =
null == CommonPrefs.getDefaultPlayerName( m_activity, 0, false );
if ( showing ) {
String name = CommonPrefs.getDefaultPlayerName( m_activity, 0, true ); String name = CommonPrefs.getDefaultPlayerName( m_activity, 0, true );
CommonPrefs.setDefaultPlayerName( m_activity, name ); CommonPrefs.setDefaultPlayerName( m_activity, name );
showDialog( DlgID.GET_NAME ); showDialog( DlgID.GET_NAME );
} }
return showing;
}
private void getDictForLangIf() private void getDictForLangIf()
{ {
@ -2370,12 +2374,64 @@ public class GamesListDelegate extends ListDelegateBase
// return adapter; // return adapter;
} }
private void makeThenLaunchOrConfigure( EditText edit, boolean doConfigure ) // Returns true if user has what looks like a default name and has not
// said he wants us to stop bugging him about it.
private boolean askingChangeName( EditText edit, boolean doConfigure )
{ {
boolean asking = false;
boolean skipAsk = XWPrefs
.getPrefsBoolean( m_activity, R.string.key_notagain_dfltname,
false );
if ( ! skipAsk ) {
String name1 = CommonPrefs.getDefaultPlayerName( m_activity, 0,
false );
String name2 = CommonPrefs.getDefaultOriginalPlayerName( m_activity, 0 );
if ( null == name1 || name1.equals( name2 ) ) {
asking = true;
String msg = LocUtils
.getString( m_activity, R.string.not_again_dfltname_fmt,
name2 );
Runnable onChecked = new Runnable() {
public void run() {
XWPrefs
.setPrefsBoolean( m_activity,
R.string.key_notagain_dfltname,
true );
}
};
showConfirmThen( onChecked, msg, android.R.string.ok,
R.string.button_later, Action.NEW_GAME_DFLT_NAME,
edit, doConfigure );
}
}
return asking;
}
private boolean makeThenLaunchOrConfigure()
{
boolean handled = null != m_newGameParams;
if ( handled ) {
EditText edit = (EditText)m_newGameParams[0];
boolean doConfigure = (Boolean)m_newGameParams[1];
m_newGameParams = null;
makeThenLaunchOrConfigure( edit, doConfigure, true );
}
return handled;
}
private void makeThenLaunchOrConfigure( EditText edit, boolean doConfigure,
boolean skipAsk )
{
if ( skipAsk || !askingChangeName( edit, doConfigure ) ) {
String name = edit.getText().toString(); String name = edit.getText().toString();
long rowID; long rowID;
long groupID = 1 == m_selGroupIDs.size() long groupID = 1 == m_selGroupIDs.size()
? m_selGroupIDs.iterator().next() : DBUtils.GROUPID_UNSPEC; ? m_selGroupIDs.iterator().next() : DBUtils.GROUPID_UNSPEC;
// Ideally we'd check here whether user has set player name.
if ( m_nextIsSolo ) { if ( m_nextIsSolo ) {
rowID = GameUtils.saveNew( m_activity, rowID = GameUtils.saveNew( m_activity,
new CurGameInfo( m_activity ), new CurGameInfo( m_activity ),
@ -2392,6 +2448,7 @@ public class GamesListDelegate extends ListDelegateBase
GameUtils.launchGame( m_activity, rowID ); GameUtils.launchGame( m_activity, rowID );
} }
} }
}
public static void boardDestroyed( long rowid ) public static void boardDestroyed( long rowid )
{ {

View file

@ -171,6 +171,12 @@ public class CommonPrefs extends XWPrefs {
return value; return value;
} }
public static String getDefaultOriginalPlayerName( Context context,
int num )
{
return LocUtils.getString( context, R.string.player_fmt, num + 1 );
}
public static String getDefaultPlayerName( Context context, int num, public static String getDefaultPlayerName( Context context, int num,
boolean force ) boolean force )
{ {
@ -179,8 +185,7 @@ public class CommonPrefs extends XWPrefs {
result = null; // be consistent result = null; // be consistent
} }
if ( force && null == result ) { if ( force && null == result ) {
String fmt = LocUtils.getString( context, R.string.player_fmt ); result = getDefaultOriginalPlayerName( context, num );
result = String.format( fmt, num + 1 );
} }
return result; return result;
} }