mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-09 05:24:44 +01:00
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:
parent
0b0bd02e79
commit
97f24973e4
9 changed files with 842 additions and 760 deletions
File diff suppressed because it is too large
Load diff
|
@ -129,6 +129,7 @@
|
|||
<string name="key_invite_multi">key_invite_multi</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_notagain_dfltname">key_notagain_dfltname</string>
|
||||
|
||||
<string name="key_na_comms_bt">key_na_comms_bt</string>
|
||||
<string name="key_na_comms_sms">key_na_comms_sms</string>
|
||||
|
|
|
@ -1720,12 +1720,11 @@
|
|||
-->
|
||||
|
||||
<!-- Welcome dialog title -->
|
||||
<string name="default_name_title">Welcome</string>
|
||||
<string name="default_name_title">Default player name</string>
|
||||
<!-- Welcome dialog text -->
|
||||
<string name="default_name_message">Thanks for installing
|
||||
Crosswords!\n\nFeel free to enter your name here. It will be used
|
||||
when creating new games. (You can change it later in the \"New
|
||||
game default\" section of Settings.)</string>
|
||||
<string name="default_name_message">Please enter your name
|
||||
here. It will be used when creating new games. (You can change it
|
||||
later in the \"New game default\" section of Settings.)</string>
|
||||
|
||||
<!--
|
||||
###########################################################
|
||||
|
@ -2623,4 +2622,8 @@
|
|||
|
||||
<string name="list_item_select">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>
|
||||
|
|
|
@ -1478,12 +1478,11 @@
|
|||
###########################################################
|
||||
-->
|
||||
<!-- Welcome dialog title -->
|
||||
<string name="default_name_title">Emoclew</string>
|
||||
<string name="default_name_title">Tluafed reyalp eman</string>
|
||||
<!-- Welcome dialog text -->
|
||||
<string name="default_name_message">Sknaht rof gnillatsni
|
||||
!sdrowssorc\n\nLeef eerf ot retne ruoy eman ereh. Ti lliw eb desu
|
||||
nehw gnitaerc wen semag. uOy( nac egnahc ti retal ni eht \"Wen
|
||||
emag tluafed\" noitces fo Sgnittes.)</string>
|
||||
<string name="default_name_message">Esaelp retne ruoy eman
|
||||
ereh. Ti lliw eb desu nehw gnitaerc wen semag. uOy( nac egnahc ti
|
||||
retal ni eht \"Wen emag tluafed\" noitces fo Sgnittes.)</string>
|
||||
<!--
|
||||
###########################################################
|
||||
# :Dialogs:
|
||||
|
@ -2241,4 +2240,7 @@
|
|||
<string name="processing_games">Gnissecorp semag</string>
|
||||
<string name="list_item_select">Tceles</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>
|
||||
|
|
|
@ -1478,12 +1478,11 @@
|
|||
###########################################################
|
||||
-->
|
||||
<!-- Welcome dialog title -->
|
||||
<string name="default_name_title">WELCOME</string>
|
||||
<string name="default_name_title">DEFAULT PLAYER NAME</string>
|
||||
<!-- Welcome dialog text -->
|
||||
<string name="default_name_message">THANKS FOR INSTALLING
|
||||
CROSSWORDS!\n\nFEEL FREE TO ENTER YOUR NAME HERE. IT WILL BE USED
|
||||
WHEN CREATING NEW GAMES. (YOU CAN CHANGE IT LATER IN THE \"NEW
|
||||
GAME DEFAULT\" SECTION OF SETTINGS.)</string>
|
||||
<string name="default_name_message">PLEASE ENTER YOUR NAME
|
||||
HERE. IT WILL BE USED WHEN CREATING NEW GAMES. (YOU CAN CHANGE IT
|
||||
LATER IN THE \"NEW GAME DEFAULT\" SECTION OF SETTINGS.)</string>
|
||||
<!--
|
||||
###########################################################
|
||||
# :Dialogs:
|
||||
|
@ -2241,4 +2240,7 @@
|
|||
<string name="processing_games">PROCESSING GAMES</string>
|
||||
<string name="list_item_select">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>
|
||||
|
|
|
@ -436,6 +436,13 @@ public class DelegateBase implements DlgClickNotify,
|
|||
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 )
|
||||
{
|
||||
return m_dlgDelegate.post( runnable );
|
||||
|
|
|
@ -65,6 +65,7 @@ public class DlgDelegate {
|
|||
NEW_GAME_PRESSED,
|
||||
SET_HIDE_NEWGAME_BUTTONS,
|
||||
DWNLD_LOC_DICT,
|
||||
NEW_GAME_DFLT_NAME,
|
||||
|
||||
// BoardDelegate
|
||||
UNDO_LAST_ACTION,
|
||||
|
@ -561,7 +562,7 @@ public class DlgDelegate {
|
|||
|
||||
private Dialog createNotAgainDialog( final DlgState state, DlgID dlgID )
|
||||
{
|
||||
NotAgainView naView = (NotAgainView)
|
||||
final NotAgainView naView = (NotAgainView)
|
||||
LocUtils.inflate( m_activity, R.layout.not_again_view );
|
||||
naView.setMessage( state.m_msg );
|
||||
final OnClickListener lstnr_p = mkCallbackClickListener( state, naView );
|
||||
|
@ -571,18 +572,15 @@ public class DlgDelegate {
|
|||
.setView( naView )
|
||||
.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 ) {
|
||||
final ActionPair more = state.m_pair;
|
||||
OnClickListener lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
checkNotAgainCheck( state, naView );
|
||||
m_clickCallback.
|
||||
dlgButtonClicked( more.action,
|
||||
AlertDialog.BUTTON_POSITIVE,
|
||||
more.params );
|
||||
lstnr_p.onClick( dlg, AlertDialog.BUTTON_POSITIVE );
|
||||
}
|
||||
};
|
||||
builder.setNegativeButton( more.buttonStr, lstnr );
|
||||
|
@ -766,14 +764,7 @@ public class DlgDelegate {
|
|||
OnClickListener cbkOnClickLstnr;
|
||||
cbkOnClickLstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int button ) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
checkNotAgainCheck( state, naView );
|
||||
|
||||
if ( Action.SKIP_CALLBACK != state.m_action ) {
|
||||
m_clickCallback.dlgButtonClicked( state.m_action,
|
||||
|
@ -785,6 +776,18 @@ public class DlgDelegate {
|
|||
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,
|
||||
final DlgState state,
|
||||
DlgID dlgID )
|
||||
|
|
|
@ -592,6 +592,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
private Button[] m_newGameButtons;
|
||||
private boolean m_haveShownGetDict;
|
||||
private Intent m_rematchIntent;
|
||||
private Object[] m_newGameParams;
|
||||
|
||||
public GamesListDelegate( ListDelegator delegator, Bundle sis )
|
||||
{
|
||||
|
@ -817,7 +818,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
}
|
||||
CommonPrefs.setDefaultPlayerName( m_activity, name );
|
||||
|
||||
getDictForLangIf(); // hack!!!
|
||||
makeThenLaunchOrConfigure();
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
@ -828,12 +829,12 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
final EditText edit = (EditText)view.findViewById( R.id.edit );
|
||||
lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
makeThenLaunchOrConfigure( edit, true );
|
||||
makeThenLaunchOrConfigure( edit, true, false );
|
||||
}
|
||||
};
|
||||
lstnr2 = new OnClickListener() {
|
||||
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 )
|
||||
{
|
||||
m_handler = new Handler();
|
||||
|
@ -950,9 +952,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
|
||||
tryStartsFromIntent( getIntent() );
|
||||
|
||||
if ( !askDefaultNameIf() ) {
|
||||
getDictForLangIf();
|
||||
}
|
||||
getDictForLangIf();
|
||||
|
||||
m_origTitle = getTitle();
|
||||
} // init
|
||||
|
@ -1213,6 +1213,10 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
reloadGame( newid );
|
||||
break;
|
||||
|
||||
case SET_HIDE_NEWGAME_BUTTONS:
|
||||
XWPrefs.setHideNewgameButtons(m_activity, true);
|
||||
setupButtons();
|
||||
// FALLTHRU
|
||||
case NEW_GAME_PRESSED:
|
||||
handleNewGame( m_nextIsSolo );
|
||||
break;
|
||||
|
@ -1234,10 +1238,6 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
case CLEAR_SELS:
|
||||
clearSelections();
|
||||
break;
|
||||
case SET_HIDE_NEWGAME_BUTTONS:
|
||||
XWPrefs.setHideNewgameButtons( m_activity, true );
|
||||
setupButtons();
|
||||
break;
|
||||
case DWNLD_LOC_DICT:
|
||||
String lang = (String)params[0];
|
||||
String name = (String)params[1];
|
||||
|
@ -1263,9 +1263,18 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
};
|
||||
DwnldDelegate.downloadDictInBack( m_activity, lang, name, lstnr );
|
||||
break;
|
||||
case NEW_GAME_DFLT_NAME:
|
||||
m_newGameParams = params;
|
||||
askDefaultName();
|
||||
break;
|
||||
default:
|
||||
Assert.fail();
|
||||
}
|
||||
} else if ( AlertDialog.BUTTON_NEGATIVE == which ) {
|
||||
if ( Action.NEW_GAME_DFLT_NAME == action ) {
|
||||
m_newGameParams = params;
|
||||
makeThenLaunchOrConfigure();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2066,16 +2075,11 @@ 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 );
|
||||
CommonPrefs.setDefaultPlayerName( m_activity, name );
|
||||
showDialog( DlgID.GET_NAME );
|
||||
}
|
||||
return showing;
|
||||
String name = CommonPrefs.getDefaultPlayerName( m_activity, 0, true );
|
||||
CommonPrefs.setDefaultPlayerName( m_activity, name );
|
||||
showDialog( DlgID.GET_NAME );
|
||||
}
|
||||
|
||||
private void getDictForLangIf()
|
||||
|
@ -2370,26 +2374,79 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
// 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 )
|
||||
{
|
||||
String name = edit.getText().toString();
|
||||
long rowID;
|
||||
long groupID = 1 == m_selGroupIDs.size()
|
||||
? m_selGroupIDs.iterator().next() : DBUtils.GROUPID_UNSPEC;
|
||||
if ( m_nextIsSolo ) {
|
||||
rowID = GameUtils.saveNew( m_activity,
|
||||
new CurGameInfo( m_activity ),
|
||||
groupID, name );
|
||||
} else {
|
||||
rowID = GameUtils.makeNewMultiGame( m_activity, groupID, name );
|
||||
}
|
||||
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;
|
||||
|
||||
if ( doConfigure ) {
|
||||
// configure it
|
||||
GameConfigDelegate.editForResult( m_activity, CONFIG_GAME, rowID );
|
||||
} else {
|
||||
// launch it
|
||||
GameUtils.launchGame( m_activity, rowID );
|
||||
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();
|
||||
long rowID;
|
||||
long groupID = 1 == m_selGroupIDs.size()
|
||||
? m_selGroupIDs.iterator().next() : DBUtils.GROUPID_UNSPEC;
|
||||
|
||||
// Ideally we'd check here whether user has set player name.
|
||||
|
||||
if ( m_nextIsSolo ) {
|
||||
rowID = GameUtils.saveNew( m_activity,
|
||||
new CurGameInfo( m_activity ),
|
||||
groupID, name );
|
||||
} else {
|
||||
rowID = GameUtils.makeNewMultiGame( m_activity, groupID, name );
|
||||
}
|
||||
|
||||
if ( doConfigure ) {
|
||||
// configure it
|
||||
GameConfigDelegate.editForResult( m_activity, CONFIG_GAME, rowID );
|
||||
} else {
|
||||
// launch it
|
||||
GameUtils.launchGame( m_activity, rowID );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -171,6 +171,12 @@ public class CommonPrefs extends XWPrefs {
|
|||
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,
|
||||
boolean force )
|
||||
{
|
||||
|
@ -179,8 +185,7 @@ public class CommonPrefs extends XWPrefs {
|
|||
result = null; // be consistent
|
||||
}
|
||||
if ( force && null == result ) {
|
||||
String fmt = LocUtils.getString( context, R.string.player_fmt );
|
||||
result = String.format( fmt, num + 1 );
|
||||
result = getDefaultOriginalPlayerName( context, num );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue