more dialog cleanup

get rid of subclasses that are no longer separate, since features like
providing a not-again checkbox are available everywhere now.
This commit is contained in:
Eric House 2020-06-25 10:20:19 -07:00
parent ba9fe85611
commit 6b2fceb468
9 changed files with 45 additions and 192 deletions

View file

@ -315,8 +315,9 @@ public class BoardDelegate extends DelegateBase
int title = (Integer)params[0];
String msg = (String)params[1];
ab.setMessage( msg );
Assert.assertTrue( 0 != title );
ab.setTitle( title );
if ( 0 != title ) {
ab.setTitle( title );
}
ab.setPositiveButton( android.R.string.ok, null );
if ( DlgID.DLG_SCORES == dlgID ) {
if ( null != m_mySIS.words && m_mySIS.words.length > 0 ) {
@ -2635,7 +2636,6 @@ public class BoardDelegate extends DelegateBase
switch ( dlgID ) {
case DLG_OKONLY:
case DLG_SCORES:
dlgTitle = R.string.info_title;
break;
case DLG_USEDICT:
case DLG_GETDICT:

View file

@ -1,64 +0,0 @@
/* -*- compile-command: "find-and-gradle.sh inXw4dDebug"; -*- */
/*
* Copyright 2017 - 2020 by Eric House (xwords@eehouse.org). All rights
* reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
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 {
private static final String TAG = ConfirmThenAlert.class.getSimpleName();
public static ConfirmThenAlert newInstance( DlgState state )
{
ConfirmThenAlert result = new ConfirmThenAlert();
result.addStateArgument( state );
return result;
}
public ConfirmThenAlert() {}
@Override
public void populateBuilder( Context context, DlgState state,
AlertDialog.Builder builder )
{
NotAgainView naView = addNAView( state, builder );
OnClickListener lstnr = mkCallbackClickListener( naView );
if ( 0 != state.m_titleId ) {
builder.setTitle( state.m_titleId );
}
builder.setPositiveButton( state.m_posButton, lstnr )
.setNegativeButton( state.m_negButton, lstnr );
if ( null != state.m_pair ) {
ActionPair pair = state.m_pair;
builder.setNeutralButton( pair.buttonStr,
mkCallbackClickListener( pair, naView ) );
}
}
}

View file

@ -483,17 +483,13 @@ public class DelegateBase implements DlgClickNotify,
DlgDelegateAlert df = null;
switch ( state.m_id ) {
case CONFIRM_THEN:
df = ConfirmThenAlert.newInstance( state );
case DIALOG_OKONLY:
case DIALOG_NOTAGAIN:
df = DlgDelegateAlert.newInstance( state );
break;
case DIALOG_ENABLESMS:
df = EnableSMSAlert.newInstance( state );
break;
case DIALOG_OKONLY:
df = OkOnlyAlert.newInstance( state );
break;
case DIALOG_NOTAGAIN:
df = NotAgainAlert.newInstance( state );
break;
case INVITE_CHOICES_THEN:
df = InviteChoicesAlert.newInstance( state );
break;

View file

@ -214,7 +214,7 @@ public class DlgDelegate {
Builder setNAKey( int keyID )
{
mState.setPrefsKey( keyID );
mState.setPrefsNAKey( keyID );
return this;
}
@ -291,6 +291,7 @@ public class DlgDelegate {
return new Builder( DlgID.DIALOG_NOTAGAIN )
.setNAKey( key )
.setAction( Action.SKIP_CALLBACK )
.setTitle( R.string.newbie_title )
;
}

View file

@ -1,6 +1,7 @@
/* -*- compile-command: "find-and-gradle.sh inXw4dDebug"; -*- */
/* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */
/*
* Copyright 2017 by Eric House (xwords@eehouse.org). All rights reserved.
* Copyright 2017 - 2020 by Eric House (xwords@eehouse.org). All rights
* reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@ -37,13 +38,20 @@ import org.eehouse.android.xw4.loc.LocUtils;
/** Abstract superclass for Alerts that have moved from and are still created
* inside DlgDelegate
*/
abstract class DlgDelegateAlert extends XWDialogFragment {
public class DlgDelegateAlert extends XWDialogFragment {
private static final String TAG = DlgDelegateAlert.class.getSimpleName();
private static final String STATE_KEY = "STATE_KEY";
private DlgState m_state;
public DlgDelegateAlert() {}
public static DlgDelegateAlert newInstance( DlgState state )
{
DlgDelegateAlert result = new DlgDelegateAlert();
result.addStateArgument( state );
return result;
}
protected final DlgState getState( Bundle sis )
{
if ( m_state == null ) {
@ -63,18 +71,37 @@ abstract class DlgDelegateAlert extends XWDialogFragment {
setArguments( state.toBundle() );
}
abstract void populateBuilder( Context context, DlgState state,
AlertDialog.Builder builder );
protected void populateBuilder( Context context, DlgState state,
AlertDialog.Builder builder )
{
Log.d( TAG, "populateBuilder()" );
NotAgainView naView = addNAView( state, builder );
OnClickListener lstnr = mkCallbackClickListener( naView );
if ( 0 != state.m_posButton ) {
builder.setPositiveButton( state.m_posButton, lstnr );
}
if ( 0 != state.m_negButton ) {
builder.setNegativeButton( state.m_negButton, lstnr );
}
if ( null != state.m_pair ) {
ActionPair pair = state.m_pair;
builder.setNeutralButton( pair.buttonStr,
mkCallbackClickListener( pair, naView ) );
}
}
Dialog create( AlertDialog.Builder builder ) { return builder.create(); }
protected NotAgainView addNAView( DlgState state, AlertDialog.Builder builder )
private NotAgainView addNAView( DlgState state, AlertDialog.Builder builder )
{
Context context = getActivity();
NotAgainView naView =
((NotAgainView)LocUtils.inflate( context, R.layout.not_again_view ))
.setMessage( state.m_msg )
.setShowNACheckbox( 0 != state.m_prefsNAKey );
.setShowNACheckbox( 0 != state.m_prefsNAKey )
;
builder.setView( naView );

View file

@ -56,7 +56,7 @@ public class DlgState implements Parcelable {
public DlgState setMsg( String msg )
{ m_msg = msg; return this; }
public DlgState setPrefsKey( int key )
public DlgState setPrefsNAKey( int key )
{ m_prefsNAKey = key; return this; }
public DlgState setAction( Action action )
{ m_action = action; return this; }
@ -203,7 +203,7 @@ public class DlgState implements Parcelable {
.setPosButton( posButton )
.setNegButton( negButton )
.setAction( action )
.setPrefsKey( prefsKey )
.setPrefsNAKey( prefsKey )
.setOnNA( onNA )
.setTitle(titleId)
.setParams(params)

View file

@ -1,54 +0,0 @@
/* -*- compile-command: "find-and-gradle.sh inXw4dDebug"; -*- */
/*
* Copyright 2017 by Eric House (xwords@eehouse.org). All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.eehouse.android.xw4;
import android.app.AlertDialog;
import android.content.Context;
import org.eehouse.android.xw4.DlgDelegate.ActionPair;
public class NotAgainAlert extends DlgDelegateAlert {
private static final String TAG = NotAgainAlert.class.getSimpleName();
public static NotAgainAlert newInstance( DlgState state )
{
NotAgainAlert result = new NotAgainAlert();
result.addStateArgument( state );
return result;
}
public NotAgainAlert() {}
@Override
public void populateBuilder( Context context, DlgState state,
AlertDialog.Builder builder )
{
NotAgainView naView = addNAView( state, builder );
builder.setTitle( R.string.newbie_title )
.setPositiveButton( android.R.string.ok,
mkCallbackClickListener( naView ) );
if ( null != state.m_pair ) {
ActionPair pair = state.m_pair;
builder.setNegativeButton( pair.buttonStr,
mkCallbackClickListener( pair, naView ) );
}
}
}

View file

@ -1,53 +0,0 @@
/* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */
/*
* Copyright 2017 - 2020 by Eric House (xwords@eehouse.org). All rights
* reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.eehouse.android.xw4;
import android.app.AlertDialog;
import android.content.Context;
import org.eehouse.android.xw4.DlgDelegate.ActionPair;
public class OkOnlyAlert extends DlgDelegateAlert {
private static final String TAG = OkOnlyAlert.class.getSimpleName();
public static OkOnlyAlert newInstance( DlgState state )
{
OkOnlyAlert result = new OkOnlyAlert();
result.addStateArgument( state );
return result;
}
public OkOnlyAlert() {}
@Override
public void populateBuilder( Context context, DlgState state,
AlertDialog.Builder builder )
{
builder.setMessage( state.m_msg )
.setPositiveButton( state.m_posButton, null )
;
ActionPair pair = state.m_pair;
if ( null != pair ) {
builder.setNeutralButton( pair.buttonStr, mkCallbackClickListener( pair ) );
}
}
}

View file

@ -287,7 +287,7 @@ public class XWActivity extends FragmentActivity
df.show( fm, tag );
}
} catch (IllegalStateException ise ) {
Log.d( TAG, "error showing tag %s (df: %s)", tag, df );
Log.d( TAG, "error showing tag %s (df: %s; msg: %s)", tag, df, ise );
// DLG_SCORES is causing this for non-belongsOnBackStack() case
// Assert.assertFalse( BuildConfig.DEBUG );
}