make setActionPair work for confirmThen alerts too

(To be used shortly)
This commit is contained in:
Eric House 2019-02-28 16:03:46 -08:00
parent 4297b3c2c3
commit aa8296f829
2 changed files with 26 additions and 16 deletions

View file

@ -19,11 +19,13 @@
package org.eehouse.android.xw4;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import org.eehouse.android.xw4.DlgDelegate.ActionPair;
import org.eehouse.android.xw4.loc.LocUtils;
public class ConfirmThenAlert extends DlgDelegateAlert {
@ -49,11 +51,17 @@ public class ConfirmThenAlert extends DlgDelegateAlert {
naView.setShowNACheckbox( null != state.m_onNAChecked );
OnClickListener lstnr = mkCallbackClickListener( naView );
return LocUtils.makeAlertBuilder( context )
AlertDialog.Builder builder = LocUtils.makeAlertBuilder( context )
.setTitle( state.m_titleId == 0 ? R.string.query_title : state.m_titleId )
.setView( naView )
.setPositiveButton( state.m_posButton, lstnr )
.setNegativeButton( state.m_negButton, lstnr )
.create();
.setNegativeButton( state.m_negButton, lstnr );
if ( null != state.m_pair ) {
ActionPair pair = state.m_pair;
builder.setNeutralButton( pair.buttonStr,
mkCallbackClickListener( pair, naView ) );
}
return builder.create();
}
}

View file

@ -164,6 +164,7 @@ public class DlgDelegate {
protected Action m_action;
protected Object[] m_params;
protected int m_titleId = 0;
protected ActionPair m_actionPair;
public DlgDelegateBuilder( String msg, Action action )
{ m_msgString = msg; m_action = action; }
@ -171,6 +172,9 @@ public class DlgDelegate {
public DlgDelegateBuilder( int msgId, Action action )
{ this( getString(msgId), action );}
public DlgDelegateBuilder setAction( Action action )
{ m_action = action; return this; }
public DlgDelegateBuilder setNAKey( int keyId )
{ m_nakey = keyId; return this; }
@ -186,6 +190,12 @@ public class DlgDelegate {
public DlgDelegateBuilder setParams( Object... params )
{ m_params = params; return this; }
public DlgDelegateBuilder setTitle( int titleId )
{ m_titleId = titleId; return this; }
public DlgDelegateBuilder setActionPair( ActionPair pr )
{ m_actionPair = pr; return this; }
abstract void show();
}
@ -193,14 +203,11 @@ public class DlgDelegate {
public OkOnlyBuilder(String msg) { super( msg, Action.SKIP_CALLBACK ); }
public OkOnlyBuilder(int msgId) { super( msgId, Action.SKIP_CALLBACK ); }
public OkOnlyBuilder setAction( Action action )
{ m_action = action; return this; }
public OkOnlyBuilder setTitle( int titleId )
{ m_titleId = titleId; return this; }
@Override
public void show()
{
Assert.assertTrue( null == m_actionPair || !BuildConfig.DEBUG );
showOKOnlyDialogThen( m_msgString, m_action, m_params, m_titleId );
}
}
@ -209,20 +216,17 @@ public class DlgDelegate {
public ConfirmThenBuilder(String msg, Action action) {super(msg, action);}
public ConfirmThenBuilder(int msgId, Action action) {super(msgId, action);}
public ConfirmThenBuilder setTitle( int titleId )
{ m_titleId = titleId; return this; }
@Override
public void show()
{
showConfirmThen( m_nakey, m_onNA, m_msgString, m_posButton,
m_negButton, m_action, m_titleId, m_params );
m_negButton, m_action, m_titleId, m_actionPair,
m_params );
}
}
public class NotAgainBuilder extends DlgDelegateBuilder {
private int m_prefsKey;
private ActionPair m_actionPair;
public NotAgainBuilder(String msg, int key, Action action)
{ super(msg, action); m_prefsKey = key; }
@ -236,9 +240,6 @@ public class DlgDelegate {
public NotAgainBuilder( int msgId, int key )
{ super( msgId, Action.SKIP_CALLBACK ); m_prefsKey = key; }
public NotAgainBuilder setActionPair( ActionPair pr )
{ m_actionPair = pr; return this; }
@Override
public void show()
{
@ -385,7 +386,7 @@ public class DlgDelegate {
private void showConfirmThen( int nakey, Action onNA, String msg,
int posButton, int negButton, Action action,
int titleId, Object[] params )
int titleId, ActionPair more, Object[] params )
{
if ( 0 == nakey ||
! XWPrefs.getPrefsBoolean( m_activity, nakey, false ) ) {
@ -395,6 +396,7 @@ public class DlgDelegate {
.setNegButton( negButton )
.setAction( action )
.setTitle( titleId )
.setActionPair( more )
.setParams( params );
m_dlgt.show( state );
}