add a "do not show again" checkbox to confirmThen alerts, and use it

to offer that option to the alert asking if you want to download the
wordlist for your phone's language.
This commit is contained in:
Eric House 2015-03-30 19:23:12 -07:00
parent be017747b3
commit c330b53d89
6 changed files with 74 additions and 44 deletions

View file

@ -55,21 +55,21 @@ public final class R {
public static final int in_arrow=0x7f020012; public static final int in_arrow=0x7f020012;
public static final int in_arrow_active=0x7f020013; public static final int in_arrow_active=0x7f020013;
public static final int multigame__gen=0x7f020014; public static final int multigame__gen=0x7f020014;
public static final int new_group__gen=0x7f020015; public static final int multigame_new__gen=0x7f020015;
public static final int next_hint=0x7f020016; public static final int new_group__gen=0x7f020016;
public static final int origin=0x7f020017; public static final int next_hint=0x7f020017;
public static final int out_arrow=0x7f020018; public static final int origin=0x7f020018;
public static final int out_arrow_active=0x7f020019; public static final int out_arrow=0x7f020019;
public static final int prefs__gen=0x7f02001a; public static final int out_arrow_active=0x7f02001a;
public static final int prev_hint=0x7f02001b; public static final int prefs__gen=0x7f02001b;
public static final int refresh=0x7f02001c; public static final int prev_hint=0x7f02001c;
public static final int relabel__gen=0x7f02001d; public static final int refresh=0x7f02001d;
public static final int reset__gen=0x7f02001e; public static final int relabel__gen=0x7f02001e;
public static final int rightarrow=0x7f02001f; public static final int reset__gen=0x7f02001f;
public static final int save__gen=0x7f020020; public static final int rightarrow=0x7f020020;
public static final int search__gen=0x7f020021; public static final int save__gen=0x7f020021;
public static final int select_all__gen=0x7f020022; public static final int search__gen=0x7f020022;
public static final int send__gen=0x7f020023; public static final int select_all__gen=0x7f020023;
public static final int shuffle=0x7f020024; public static final int shuffle=0x7f020024;
public static final int sologame__gen=0x7f020025; public static final int sologame__gen=0x7f020025;
public static final int stat_notify_chat=0x7f020026; public static final int stat_notify_chat=0x7f020026;

View file

@ -386,13 +386,19 @@ public class DelegateBase implements DlgClickNotify,
protected void showConfirmThen( String msg, Action action, Object... params ) protected void showConfirmThen( String msg, Action action, Object... params )
{ {
m_dlgDelegate.showConfirmThen( msg, action, params ); m_dlgDelegate.showConfirmThen( null, msg, action, params );
}
protected void showConfirmThen( Runnable onNA, String msg, int posButton,
Action action, Object... params )
{
m_dlgDelegate.showConfirmThen( onNA, msg, posButton, action, params );
} }
protected void showConfirmThen( String msg, int posButton, Action action, protected void showConfirmThen( String msg, int posButton, Action action,
Object... params ) Object... params )
{ {
m_dlgDelegate.showConfirmThen( msg, posButton, action, params ); m_dlgDelegate.showConfirmThen( null, msg, posButton, action, params );
} }
protected void showConfirmThen( int msg, int posButton, int negButton, Action action ) protected void showConfirmThen( int msg, int posButton, int negButton, Action action )

View file

@ -329,47 +329,47 @@ public class DlgDelegate {
public void showConfirmThen( String msg, Action action ) public void showConfirmThen( String msg, Action action )
{ {
showConfirmThen( msg, R.string.button_ok, action, null ); showConfirmThen( null, msg, R.string.button_ok, action, null );
} }
public void showConfirmThen( int msgID, Action action ) public void showConfirmThen( int msgID, Action action )
{ {
showConfirmThen( getString( msgID ), R.string.button_ok, action, null ); showConfirmThen( null, getString( msgID ), R.string.button_ok, action, null );
} }
public void showConfirmThen( String msg, Action action, Object[] params ) public void showConfirmThen( Runnable onNA, String msg, Action action, Object[] params )
{ {
showConfirmThen( msg, R.string.button_ok, action, params ); showConfirmThen( onNA, msg, R.string.button_ok, action, params );
} }
public void showConfirmThen( String msg, int posButton, Action action ) public void showConfirmThen( Runnable onNA, String msg, int posButton, Action action )
{ {
showConfirmThen( msg, posButton, action, null ); showConfirmThen( onNA, msg, posButton, action, null );
} }
public void showConfirmThen( int msg, int posButton, int negButton, Action action ) public void showConfirmThen( int msg, int posButton, int negButton, Action action )
{ {
showConfirmThen( getString(msg), posButton, negButton, action, null ); showConfirmThen( null, getString(msg), posButton, negButton, action, null );
} }
public void showConfirmThen( int msg, int posButton, Action action, public void showConfirmThen( int msg, int posButton, Action action,
Object[] params ) Object[] params )
{ {
showConfirmThen( getString(msg), posButton, R.string.button_cancel, showConfirmThen( null, getString(msg), posButton, R.string.button_cancel,
action, params ); action, params );
} }
public void showConfirmThen( String msg, int posButton, Action action, public void showConfirmThen( Runnable onNA, String msg, int posButton, Action action,
Object[] params ) Object[] params )
{ {
showConfirmThen( msg, posButton, R.string.button_cancel, action, showConfirmThen( onNA, msg, posButton, R.string.button_cancel, action,
params ); params );
} }
public void showConfirmThen( String msg, int posButton, int negButton, public void showConfirmThen( Runnable onNA, String msg, int posButton,
Action action, Object[] params ) int negButton, Action action, Object[] params )
{ {
DlgState state = new DlgState( DlgID.CONFIRM_THEN, msg, posButton, DlgState state = new DlgState( DlgID.CONFIRM_THEN, onNA, msg, posButton,
negButton, action, 0, params ); negButton, action, 0, params );
addState( state ); addState( state );
showDialog( DlgID.CONFIRM_THEN ); showDialog( DlgID.CONFIRM_THEN );
@ -582,13 +582,17 @@ public class DlgDelegate {
private Dialog createConfirmThenDialog( DlgState state, DlgID dlgID ) private Dialog createConfirmThenDialog( DlgState state, DlgID dlgID )
{ {
OnClickListener lstnr = mkCallbackClickListener( state, null ); NotAgainView naView = (NotAgainView)
LocUtils.inflate( m_activity, R.layout.not_again_view );
naView.setMessage( state.m_msg );
naView.setShowNACheckbox( null != state.m_onNAChecked );
OnClickListener lstnr = mkCallbackClickListener( state, naView );
AlertDialog.Builder builder = LocUtils.makeAlertBuilder( m_activity ); AlertDialog.Builder builder = LocUtils.makeAlertBuilder( m_activity )
builder.setTitle( R.string.query_title ); .setTitle( R.string.query_title )
builder.setMessage( state.m_msg ); .setView( naView )
builder.setPositiveButton( state.m_posButton, lstnr ); .setPositiveButton( state.m_posButton, lstnr )
builder.setNegativeButton( state.m_negButton, lstnr ); .setNegativeButton( state.m_negButton, lstnr );
Dialog dialog = builder.create(); Dialog dialog = builder.create();
return setCallbackDismissListener( dialog, state, dlgID ); return setCallbackDismissListener( dialog, state, dlgID );
@ -708,8 +712,12 @@ public class DlgDelegate {
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() ) { if ( null != naView && naView.getChecked() ) {
if ( 0 != state.m_prefsKey ) {
XWPrefs.setPrefsBoolean( m_activity, state.m_prefsKey, XWPrefs.setPrefsBoolean( m_activity, state.m_prefsKey,
true ); 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 ) {

View file

@ -35,6 +35,7 @@ public class DlgState implements Parcelable {
public ActionPair m_pair = null; public ActionPair m_pair = null;
public int m_prefsKey; public int m_prefsKey;
public Object[] m_params; public Object[] m_params;
public Runnable m_onNAChecked;
public DlgState( DlgID dlgID, String msg, Action action ) public DlgState( DlgID dlgID, String msg, Action action )
{ {
@ -63,14 +64,15 @@ public class DlgState implements Parcelable {
public DlgState( DlgID dlgID, String msg, int posButton, public DlgState( DlgID dlgID, String msg, int posButton,
Action action, int prefsKey, Object[] params ) Action action, int prefsKey, Object[] params )
{ {
this( dlgID, msg, posButton, R.string.button_cancel, this( dlgID, null, msg, posButton, R.string.button_cancel,
action, prefsKey, params ); action, prefsKey, params );
} }
public DlgState( DlgID dlgID, String msg, int posButton, int negButton, public DlgState( DlgID dlgID, Runnable onNA, String msg, int posButton, int negButton,
Action action, int prefsKey, Object[] params ) Action action, int prefsKey, Object[] params )
{ {
m_id = dlgID; m_id = dlgID;
m_onNAChecked = onNA;
m_msg = msg; m_msg = msg;
m_posButton = posButton; m_posButton = posButton;
m_negButton = negButton; m_negButton = negButton;
@ -112,7 +114,7 @@ public class DlgState implements Parcelable {
Action action = 0 > tmp ? null : Action.values()[tmp]; Action action = 0 > tmp ? null : Action.values()[tmp];
int prefsKey = in.readInt(); int prefsKey = in.readInt();
String msg = in.readString(); String msg = in.readString();
return new DlgState( id, msg, posButton, negButton, action, prefsKey, null ); return new DlgState( id, null, msg, posButton, negButton, action, prefsKey, null );
} }
public DlgState[] newArray(int size) { public DlgState[] newArray(int size) {

View file

@ -1903,14 +1903,21 @@ public class GamesListDelegate extends ListDelegateBase
int code = LocUtils.codeForLangCode( m_activity, lc ); int code = LocUtils.codeForLangCode( m_activity, lc );
String[] names = DictLangCache.getHaveLang( m_activity, code ); String[] names = DictLangCache.getHaveLang( m_activity, code );
if ( 0 == names.length ) { if ( 0 == names.length ) {
final Runnable onNA = new Runnable() {
public void run() {
XWPrefs.setPrefsBoolean( m_activity, R.string
.key_got_langdict,
true );
}
};
OnGotLcDictListener lstnr = new OnGotLcDictListener() { OnGotLcDictListener lstnr = new OnGotLcDictListener() {
public void gotDictInfo( boolean success, String lang, public void gotDictInfo( boolean success, String lang,
String name ) { String name ) {
if ( success ) { if ( success ) {
String msg = getString( R.string.confirm_get_locdict_fmt, lang ); String msg = getString( R.string.confirm_get_locdict_fmt, lang );
showConfirmThen( msg, R.string.button_download, showConfirmThen( onNA, msg, R.string.button_download,
Action.DWNLD_LOC_DICT, lang, Action.DWNLD_LOC_DICT,
name ); lang, name );
} }
} }
}; };

View file

@ -22,6 +22,7 @@ package org.eehouse.android.xw4;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
@ -42,4 +43,10 @@ public class NotAgainView extends LinearLayout {
CheckBox cbx = (CheckBox)findViewById( R.id.not_again_check ); CheckBox cbx = (CheckBox)findViewById( R.id.not_again_check );
return cbx.isChecked(); return cbx.isChecked();
} }
public void setShowNACheckbox( boolean show )
{
findViewById( R.id.not_again_check )
.setVisibility( show ? View.VISIBLE : View.GONE );
}
} }