mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-22 07:28:16 +01:00
remove Runnable from DlgState
Can't be serializing Runnables, so replace with an Action that's sent via onPosButton.
This commit is contained in:
parent
470ee6eaa4
commit
e69824ece0
4 changed files with 34 additions and 51 deletions
|
@ -134,6 +134,10 @@ public class DlgDelegate {
|
|||
DISABLE_RELAY_DO,
|
||||
ASKED_PHONE_STATE,
|
||||
PERMS_QUERY,
|
||||
|
||||
// Sent when not-again checkbox checked
|
||||
SET_NA_DEFAULTNAME,
|
||||
SET_GOT_LANGDICT,
|
||||
}
|
||||
|
||||
public static class ActionPair {
|
||||
|
@ -145,27 +149,10 @@ public class DlgDelegate {
|
|||
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 {
|
||||
protected String m_msgString;
|
||||
protected NAKey m_nakey;
|
||||
protected Runnable m_onNA;
|
||||
protected int m_nakey;
|
||||
protected Action m_onNA;
|
||||
protected int m_posButton = android.R.string.ok;
|
||||
protected int m_negButton = android.R.string.cancel;
|
||||
protected Action m_action;
|
||||
|
@ -179,10 +166,10 @@ public class DlgDelegate {
|
|||
{ this( getString(msgId), action );}
|
||||
|
||||
public DlgDelegateBuilder setNAKey( int keyId )
|
||||
{ m_nakey = new NAKey( keyId ); return this; }
|
||||
{ m_nakey = keyId; return this; }
|
||||
|
||||
public DlgDelegateBuilder setOnNA( Runnable proc )
|
||||
{ m_onNA = proc; return this; }
|
||||
public DlgDelegateBuilder setOnNA( Action onNA )
|
||||
{ m_onNA = onNA; return this; }
|
||||
|
||||
public DlgDelegateBuilder setPosButton( int id )
|
||||
{ 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 titleId, Object[] params )
|
||||
{
|
||||
if ( null != nakey ) {
|
||||
Assert.assertNull( onNA );
|
||||
onNA = nakey; // so the run() method will be called to set the key
|
||||
}
|
||||
if ( null == nakey || !nakey.isSet( m_activity ) ) {
|
||||
if ( 0 == nakey ||
|
||||
! XWPrefs.getPrefsBoolean( m_activity, nakey, false ) ) {
|
||||
DlgState state = new DlgState( DlgID.CONFIRM_THEN ).setOnNA(onNA)
|
||||
.setMsg( msg )
|
||||
.setPosButton( posButton )
|
||||
|
@ -770,7 +754,8 @@ public class DlgDelegate {
|
|||
XWPrefs.setPrefsBoolean( m_activity, state.m_prefsKey,
|
||||
true );
|
||||
} else if ( null != state.m_onNAChecked ) {
|
||||
state.m_onNAChecked.run();
|
||||
XWActivity activity = (XWActivity)m_activity;
|
||||
activity.onPosButton( state.m_onNAChecked, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,8 @@ public class DlgDelegateAlert extends DialogFragment {
|
|||
XWPrefs.setPrefsBoolean( getActivity(), m_state.m_prefsKey,
|
||||
true );
|
||||
} else if ( null != state.m_onNAChecked ) {
|
||||
m_state.m_onNAChecked.run();
|
||||
XWActivity activity = (XWActivity)getActivity();
|
||||
activity.onPosButton( m_state.m_onNAChecked, null );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public class DlgState implements Parcelable {
|
|||
public int m_prefsKey;
|
||||
// These can't be serialized!!!!
|
||||
public Object[] m_params;
|
||||
public Runnable m_onNAChecked;
|
||||
public Action m_onNAChecked;
|
||||
public int m_titleId;
|
||||
|
||||
public DlgState( DlgID dlgID )
|
||||
|
@ -54,7 +54,7 @@ public class DlgState implements Parcelable {
|
|||
{ m_params = params; return this; }
|
||||
public DlgState setActionPair( ActionPair pair )
|
||||
{ m_pair = pair; return this; }
|
||||
public DlgState setOnNA( Runnable na )
|
||||
public DlgState setOnNA( Action na )
|
||||
{ m_onNAChecked = na; return this; }
|
||||
public DlgState setPosButton( int id )
|
||||
{ m_posButton = id; return this; }
|
||||
|
@ -73,6 +73,7 @@ public class DlgState implements Parcelable {
|
|||
out.writeInt( m_negButton );
|
||||
out.writeInt( null == m_action ? -1 : m_action.ordinal() );
|
||||
out.writeInt( m_prefsKey );
|
||||
out.writeInt( null == m_onNAChecked ? -1 : m_onNAChecked.ordinal() );
|
||||
out.writeInt( m_titleId );
|
||||
out.writeString( m_msg );
|
||||
}
|
||||
|
@ -86,6 +87,8 @@ public class DlgState implements Parcelable {
|
|||
int tmp = in.readInt();
|
||||
Action action = 0 > tmp ? null : Action.values()[tmp];
|
||||
int prefsKey = in.readInt();
|
||||
tmp = in.readInt();
|
||||
Action onNA = 0 > tmp ? null : Action.values()[tmp];
|
||||
int titleId = in.readInt();
|
||||
String msg = in.readString();
|
||||
DlgState state = new DlgState(id)
|
||||
|
@ -93,7 +96,8 @@ public class DlgState implements Parcelable {
|
|||
.setPosButton( posButton )
|
||||
.setNegButton( negButton )
|
||||
.setAction( action )
|
||||
.setPrefsKey( prefsKey );
|
||||
.setPrefsKey( prefsKey )
|
||||
.setOnNA( onNA );
|
||||
return state;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ import org.eehouse.android.xw4.DBUtils.GameGroupInfo;
|
|||
import org.eehouse.android.xw4.DBUtils.SentInvitesInfo;
|
||||
import org.eehouse.android.xw4.DlgDelegate.Action;
|
||||
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.OnGotLcDictListener;
|
||||
import org.eehouse.android.xw4.Perms23.Perm;
|
||||
|
@ -1377,6 +1376,15 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
}
|
||||
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:
|
||||
handled = super.onPosButton( action, params );
|
||||
}
|
||||
|
@ -2318,13 +2326,6 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
if ( 0 < code ) {
|
||||
String[] names = DictLangCache.getHaveLang( m_activity, code );
|
||||
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() {
|
||||
public void gotDictInfo( boolean success, String lang,
|
||||
|
@ -2336,7 +2337,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
xlateLang( lang ) );
|
||||
makeConfirmThenBuilder( msg, Action.DWNLD_LOC_DICT )
|
||||
.setPosButton( R.string.button_download )
|
||||
.setOnNA( onNA )
|
||||
.setOnNA( Action.SET_GOT_LANGDICT )
|
||||
.setParams( lang, name )
|
||||
.show();
|
||||
}
|
||||
|
@ -2628,16 +2629,8 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
.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 );
|
||||
}
|
||||
};
|
||||
makeConfirmThenBuilder( msg, Action.NEW_GAME_DFLT_NAME )
|
||||
.setOnNA( onChecked )
|
||||
.setOnNA( Action.SET_NA_DEFAULTNAME )
|
||||
.setNegButton( R.string.button_later )
|
||||
.setParams( edit, doConfigure )
|
||||
.show();
|
||||
|
|
Loading…
Reference in a new issue