remove Runnable from DlgState

Can't be serializing Runnables, so replace with an Action that's sent
via onPosButton.
This commit is contained in:
Eric House 2017-02-09 09:08:03 -08:00
parent 470ee6eaa4
commit e69824ece0
4 changed files with 34 additions and 51 deletions

View file

@ -134,6 +134,10 @@ public class DlgDelegate {
DISABLE_RELAY_DO, DISABLE_RELAY_DO,
ASKED_PHONE_STATE, ASKED_PHONE_STATE,
PERMS_QUERY, PERMS_QUERY,
// Sent when not-again checkbox checked
SET_NA_DEFAULTNAME,
SET_GOT_LANGDICT,
} }
public static class ActionPair { public static class ActionPair {
@ -145,27 +149,10 @@ public class DlgDelegate {
public Object[] params; // null for now public Object[] params; // null for now
} }
// typesafe int, basically
public static class NAKey implements Runnable {
private Context m_context;
private int m_nakey;
public NAKey(int key) { m_nakey = key; }
boolean isSet( Context context ) {
m_context = context; // hack!!!
return XWPrefs.getPrefsBoolean( context, m_nakey, false );
}
@Override
public void run() {
Assert.assertNotNull( m_context );
XWPrefs.setPrefsBoolean( m_context, m_nakey, true );
}
}
public abstract class DlgDelegateBuilder { public abstract class DlgDelegateBuilder {
protected String m_msgString; protected String m_msgString;
protected NAKey m_nakey; protected int m_nakey;
protected Runnable m_onNA; protected Action m_onNA;
protected int m_posButton = android.R.string.ok; protected int m_posButton = android.R.string.ok;
protected int m_negButton = android.R.string.cancel; protected int m_negButton = android.R.string.cancel;
protected Action m_action; protected Action m_action;
@ -179,10 +166,10 @@ public class DlgDelegate {
{ this( getString(msgId), action );} { this( getString(msgId), action );}
public DlgDelegateBuilder setNAKey( int keyId ) public DlgDelegateBuilder setNAKey( int keyId )
{ m_nakey = new NAKey( keyId ); return this; } { m_nakey = keyId; return this; }
public DlgDelegateBuilder setOnNA( Runnable proc ) public DlgDelegateBuilder setOnNA( Action onNA )
{ m_onNA = proc; return this; } { m_onNA = onNA; return this; }
public DlgDelegateBuilder setPosButton( int id ) public DlgDelegateBuilder setPosButton( int id )
{ m_posButton = id; return this; } { m_posButton = id; return this; }
@ -483,15 +470,12 @@ public class DlgDelegate {
} }
} }
private void showConfirmThen( NAKey nakey, Runnable onNA, String msg, private void showConfirmThen( int nakey, Action onNA, String msg,
int posButton, int negButton, Action action, int posButton, int negButton, Action action,
int titleId, Object[] params ) int titleId, Object[] params )
{ {
if ( null != nakey ) { if ( 0 == nakey ||
Assert.assertNull( onNA ); ! XWPrefs.getPrefsBoolean( m_activity, nakey, false ) ) {
onNA = nakey; // so the run() method will be called to set the key
}
if ( null == nakey || !nakey.isSet( m_activity ) ) {
DlgState state = new DlgState( DlgID.CONFIRM_THEN ).setOnNA(onNA) DlgState state = new DlgState( DlgID.CONFIRM_THEN ).setOnNA(onNA)
.setMsg( msg ) .setMsg( msg )
.setPosButton( posButton ) .setPosButton( posButton )
@ -770,7 +754,8 @@ public class DlgDelegate {
XWPrefs.setPrefsBoolean( m_activity, state.m_prefsKey, XWPrefs.setPrefsBoolean( m_activity, state.m_prefsKey,
true ); true );
} else if ( null != state.m_onNAChecked ) { } else if ( null != state.m_onNAChecked ) {
state.m_onNAChecked.run(); XWActivity activity = (XWActivity)m_activity;
activity.onPosButton( state.m_onNAChecked, null);
} }
} }
} }

View file

@ -70,7 +70,8 @@ public class DlgDelegateAlert extends DialogFragment {
XWPrefs.setPrefsBoolean( getActivity(), m_state.m_prefsKey, XWPrefs.setPrefsBoolean( getActivity(), m_state.m_prefsKey,
true ); true );
} else if ( null != state.m_onNAChecked ) { } else if ( null != state.m_onNAChecked ) {
m_state.m_onNAChecked.run(); XWActivity activity = (XWActivity)getActivity();
activity.onPosButton( m_state.m_onNAChecked, null );
} }
} }
} }

View file

@ -36,7 +36,7 @@ public class DlgState implements Parcelable {
public int m_prefsKey; public int m_prefsKey;
// These can't be serialized!!!! // These can't be serialized!!!!
public Object[] m_params; public Object[] m_params;
public Runnable m_onNAChecked; public Action m_onNAChecked;
public int m_titleId; public int m_titleId;
public DlgState( DlgID dlgID ) public DlgState( DlgID dlgID )
@ -54,7 +54,7 @@ public class DlgState implements Parcelable {
{ m_params = params; return this; } { m_params = params; return this; }
public DlgState setActionPair( ActionPair pair ) public DlgState setActionPair( ActionPair pair )
{ m_pair = pair; return this; } { m_pair = pair; return this; }
public DlgState setOnNA( Runnable na ) public DlgState setOnNA( Action na )
{ m_onNAChecked = na; return this; } { m_onNAChecked = na; return this; }
public DlgState setPosButton( int id ) public DlgState setPosButton( int id )
{ m_posButton = id; return this; } { m_posButton = id; return this; }
@ -73,6 +73,7 @@ public class DlgState implements Parcelable {
out.writeInt( m_negButton ); out.writeInt( m_negButton );
out.writeInt( null == m_action ? -1 : m_action.ordinal() ); out.writeInt( null == m_action ? -1 : m_action.ordinal() );
out.writeInt( m_prefsKey ); out.writeInt( m_prefsKey );
out.writeInt( null == m_onNAChecked ? -1 : m_onNAChecked.ordinal() );
out.writeInt( m_titleId ); out.writeInt( m_titleId );
out.writeString( m_msg ); out.writeString( m_msg );
} }
@ -86,6 +87,8 @@ public class DlgState implements Parcelable {
int tmp = in.readInt(); int tmp = in.readInt();
Action action = 0 > tmp ? null : Action.values()[tmp]; Action action = 0 > tmp ? null : Action.values()[tmp];
int prefsKey = in.readInt(); int prefsKey = in.readInt();
tmp = in.readInt();
Action onNA = 0 > tmp ? null : Action.values()[tmp];
int titleId = in.readInt(); int titleId = in.readInt();
String msg = in.readString(); String msg = in.readString();
DlgState state = new DlgState(id) DlgState state = new DlgState(id)
@ -93,7 +96,8 @@ public class DlgState implements Parcelable {
.setPosButton( posButton ) .setPosButton( posButton )
.setNegButton( negButton ) .setNegButton( negButton )
.setAction( action ) .setAction( action )
.setPrefsKey( prefsKey ); .setPrefsKey( prefsKey )
.setOnNA( onNA );
return state; return state;
} }

View file

@ -50,7 +50,6 @@ import org.eehouse.android.xw4.DBUtils.GameGroupInfo;
import org.eehouse.android.xw4.DBUtils.SentInvitesInfo; import org.eehouse.android.xw4.DBUtils.SentInvitesInfo;
import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.DlgDelegate.ActionPair; import org.eehouse.android.xw4.DlgDelegate.ActionPair;
import org.eehouse.android.xw4.DlgDelegate.NAKey;
import org.eehouse.android.xw4.DwnldDelegate.DownloadFinishedListener; import org.eehouse.android.xw4.DwnldDelegate.DownloadFinishedListener;
import org.eehouse.android.xw4.DwnldDelegate.OnGotLcDictListener; import org.eehouse.android.xw4.DwnldDelegate.OnGotLcDictListener;
import org.eehouse.android.xw4.Perms23.Perm; import org.eehouse.android.xw4.Perms23.Perm;
@ -1377,6 +1376,15 @@ public class GamesListDelegate extends ListDelegateBase
} }
break; break;
case SET_NA_DEFAULTNAME:
XWPrefs.setPrefsBoolean( m_activity, R.string.key_notagain_dfltname,
true );
break;
case SET_GOT_LANGDICT:
XWPrefs.setPrefsBoolean( m_activity, R.string.key_got_langdict,
true );
break;
default: default:
handled = super.onPosButton( action, params ); handled = super.onPosButton( action, params );
} }
@ -2318,13 +2326,6 @@ public class GamesListDelegate extends ListDelegateBase
if ( 0 < code ) { if ( 0 < code ) {
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,
@ -2336,7 +2337,7 @@ public class GamesListDelegate extends ListDelegateBase
xlateLang( lang ) ); xlateLang( lang ) );
makeConfirmThenBuilder( msg, Action.DWNLD_LOC_DICT ) makeConfirmThenBuilder( msg, Action.DWNLD_LOC_DICT )
.setPosButton( R.string.button_download ) .setPosButton( R.string.button_download )
.setOnNA( onNA ) .setOnNA( Action.SET_GOT_LANGDICT )
.setParams( lang, name ) .setParams( lang, name )
.show(); .show();
} }
@ -2628,16 +2629,8 @@ public class GamesListDelegate extends ListDelegateBase
.getString( m_activity, R.string.not_again_dfltname_fmt, .getString( m_activity, R.string.not_again_dfltname_fmt,
name2 ); name2 );
Runnable onChecked = new Runnable() {
public void run() {
XWPrefs
.setPrefsBoolean( m_activity,
R.string.key_notagain_dfltname,
true );
}
};
makeConfirmThenBuilder( msg, Action.NEW_GAME_DFLT_NAME ) makeConfirmThenBuilder( msg, Action.NEW_GAME_DFLT_NAME )
.setOnNA( onChecked ) .setOnNA( Action.SET_NA_DEFAULTNAME )
.setNegButton( R.string.button_later ) .setNegButton( R.string.button_later )
.setParams( edit, doConfigure ) .setParams( edit, doConfigure )
.show(); .show();