diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConfirmThenAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConfirmThenAlert.java index 7a79a56f6..080d4464c 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConfirmThenAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConfirmThenAlert.java @@ -40,20 +40,15 @@ public class ConfirmThenAlert extends DlgDelegateAlert { public ConfirmThenAlert() {} @Override - public Dialog onCreateDialog( Bundle sis ) + public void populateBuilder( Context context, DlgState state, + AlertDialog.Builder builder, + NotAgainView naView ) { - final Context context = getActivity(); - final DlgState state = getState( sis ); - - NotAgainView naView = (NotAgainView) - LocUtils.inflate( context, R.layout.not_again_view ); naView.setMessage( state.m_msg ); naView.setShowNACheckbox( null != state.m_onNAChecked ); OnClickListener lstnr = mkCallbackClickListener( naView ); - AlertDialog.Builder builder = LocUtils.makeAlertBuilder( context ) - .setTitle( state.m_titleId == 0 ? R.string.query_title : state.m_titleId ) - .setView( naView ) + builder.setTitle( state.m_titleId == 0 ? R.string.query_title : state.m_titleId ) .setPositiveButton( state.m_posButton, lstnr ) .setNegativeButton( state.m_negButton, lstnr ); @@ -62,6 +57,5 @@ public class ConfirmThenAlert extends DlgDelegateAlert { builder.setNeutralButton( pair.buttonStr, mkCallbackClickListener( pair, naView ) ); } - return builder.create(); } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java index 79cce8a34..3a1fa59b4 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java @@ -365,7 +365,8 @@ public class DlgDelegate { final Action action, ActionPair more, final Object[] params ) { - if ( XWPrefs.getPrefsBoolean( m_activity, prefsKey, false ) ) { + if ( 0 != prefsKey + && XWPrefs.getPrefsBoolean( m_activity, prefsKey, false ) ) { // If it's set, do the action without bothering with the // dialog if ( Action.SKIP_CALLBACK != action ) { @@ -393,7 +394,8 @@ public class DlgDelegate { { if ( 0 == nakey || ! XWPrefs.getPrefsBoolean( m_activity, nakey, false ) ) { - DlgState state = new DlgState( DlgID.CONFIRM_THEN ).setOnNA(onNA) + DlgState state = new DlgState( DlgID.CONFIRM_THEN ) + .setOnNA(onNA) .setMsg( msg ) .setPosButton( posButton ) .setNegButton( negButton ) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegateAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegateAlert.java index b91070350..84d1e6c6a 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegateAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegateAlert.java @@ -63,6 +63,32 @@ abstract class DlgDelegateAlert extends XWDialogFragment { setArguments( state.toBundle() ); } + abstract void populateBuilder( Context context, DlgState state, + AlertDialog.Builder builder, + NotAgainView naView ); + + Dialog create( AlertDialog.Builder builder ) { return builder.create(); } + + @Override + public final Dialog onCreateDialog( Bundle sis ) + { + Context context = getActivity(); + DlgState state = getState( sis ); + + NotAgainView naView = + ((NotAgainView)LocUtils.inflate( context, R.layout.not_again_view )) + .setMessage( state.m_msg ) + .setShowNACheckbox( 0 != state.m_prefsKey ); + + AlertDialog.Builder builder = LocUtils.makeAlertBuilder( context ) + .setView( naView ) + ; + + populateBuilder( context, state, builder, naView ); + + return create( builder ); + } + @Override public void onSaveInstanceState( Bundle bundle ) { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/EnableSMSAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/EnableSMSAlert.java index 41760d3c1..e924f2850 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/EnableSMSAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/EnableSMSAlert.java @@ -46,11 +46,10 @@ public class EnableSMSAlert extends DlgDelegateAlert { public EnableSMSAlert() {} @Override - public Dialog onCreateDialog( Bundle sis ) + public void populateBuilder( Context context, final DlgState state, + AlertDialog.Builder builder, + NotAgainView naView ) { - Context context = getActivity(); - final DlgState state = getState( sis ); - View layout = LocUtils.inflate( context, R.layout.confirm_sms ); mSpinner = (Spinner)layout.findViewById( R.id.confirm_sms_reasons ); @@ -74,16 +73,20 @@ public class EnableSMSAlert extends DlgDelegateAlert { } }; - AlertDialog dialog = LocUtils.makeAlertBuilder( context ) - .setTitle( R.string.confirm_sms_title ) + builder.setTitle( R.string.confirm_sms_title ) .setView( layout ) .setPositiveButton( R.string.button_enable, lstnr ) .setNegativeButton( android.R.string.cancel, null ) - .create(); + ; + } + @Override + Dialog create( AlertDialog.Builder builder ) + { + Dialog dialog = super.create( builder ); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override - public void onShow(DialogInterface dialog) { + public void onShow( DialogInterface dialog ) { checkEnableButton( (Dialog)dialog ); } }); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java index 466882d73..9e5492a3b 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java @@ -53,12 +53,10 @@ public class InviteChoicesAlert extends DlgDelegateAlert { public InviteChoicesAlert() {} @Override - public Dialog onCreateDialog( Bundle sis ) + public void populateBuilder( final Context context, final DlgState state, + AlertDialog.Builder builder, + NotAgainView naView ) { - final Context context = getActivity(); - - final DlgState state = getState( sis ); - final ArrayList means = new ArrayList(); ArrayList items = new ArrayList(); @@ -156,8 +154,7 @@ public class InviteChoicesAlert extends DlgDelegateAlert { } }; - AlertDialog.Builder builder = LocUtils.makeAlertBuilder( context ) - .setTitle( R.string.invite_choice_title ) + builder.setTitle( R.string.invite_choice_title ) .setSingleChoiceItems( items.toArray( new String[items.size()] ), sel[0], selChanged ) .setPositiveButton( android.R.string.ok, okClicked ) @@ -176,8 +173,6 @@ public class InviteChoicesAlert extends DlgDelegateAlert { }; builder.setNeutralButton( R.string.ok_with_robots, ocl ); } - - return builder.create(); } private void add( List items, List means, diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NotAgainAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NotAgainAlert.java index 6e90fb9b3..944694108 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NotAgainAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NotAgainAlert.java @@ -46,18 +46,11 @@ public class NotAgainAlert extends DlgDelegateAlert { public NotAgainAlert() {} @Override - public Dialog onCreateDialog( Bundle sis ) + public void populateBuilder( Context context, DlgState state, + AlertDialog.Builder builder, + NotAgainView naView ) { - Context context = getActivity(); - DlgState state = getState( sis ); - - NotAgainView naView = (NotAgainView) - LocUtils.inflate( context, R.layout.not_again_view ); - naView.setMessage( state.m_msg ); - - AlertDialog.Builder builder = LocUtils.makeAlertBuilder( context ) - .setTitle( R.string.newbie_title ) - .setView( naView ) + builder.setTitle( R.string.newbie_title ) .setPositiveButton( android.R.string.ok, mkCallbackClickListener( naView ) ); @@ -66,7 +59,5 @@ public class NotAgainAlert extends DlgDelegateAlert { builder.setNegativeButton( pair.buttonStr, mkCallbackClickListener( pair, naView ) ); } - - return builder.create(); } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NotAgainView.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NotAgainView.java index 87545189e..9f3742757 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NotAgainView.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NotAgainView.java @@ -28,14 +28,16 @@ import android.widget.ScrollView; import android.widget.TextView; public class NotAgainView extends ScrollView { + private static final String TAG = NotAgainView.class.getSimpleName(); public NotAgainView( Context cx, AttributeSet as ) { super( cx, as ); } - public void setMessage( String msg ) + public NotAgainView setMessage( String msg ) { ((TextView)findViewById( R.id.msg )).setText( msg ); + return this; } public boolean getChecked() @@ -44,9 +46,10 @@ public class NotAgainView extends ScrollView { return cbx.isChecked(); } - public void setShowNACheckbox( boolean show ) + public NotAgainView setShowNACheckbox( boolean show ) { findViewById( R.id.not_again_check ) .setVisibility( show ? View.VISIBLE : View.GONE ); + return this; } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/OkOnlyAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/OkOnlyAlert.java index 4fabf2be7..248c0ab98 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/OkOnlyAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/OkOnlyAlert.java @@ -46,15 +46,11 @@ public class OkOnlyAlert extends DlgDelegateAlert { public OkOnlyAlert() {} @Override - public Dialog onCreateDialog( Bundle sis ) + public void populateBuilder( Context context, DlgState state, + AlertDialog.Builder builder, + NotAgainView naView ) { - final Context context = getActivity(); - - final DlgState state = getState( sis ); - - AlertDialog.Builder builder = LocUtils.makeAlertBuilder( getActivity() ) - .setTitle( state.m_titleId == 0 ? R.string.info_title : state.m_titleId ) - .setMessage( state.m_msg ) + builder.setTitle( state.m_titleId == 0 ? R.string.info_title : state.m_titleId ) .setPositiveButton( android.R.string.ok, null ) ; @@ -62,9 +58,5 @@ public class OkOnlyAlert extends DlgDelegateAlert { if ( null != pair ) { builder.setNeutralButton( pair.buttonStr, mkCallbackClickListener( pair ) ); } - - Dialog dialog = builder.create(); - // dialog = setCallbackDismissListener( dialog, state, dlgID ); - return dialog; } }