diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBAlert.java index db912aedf..71690ae6d 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBAlert.java @@ -19,9 +19,10 @@ package org.eehouse.android.xw4; -import android.support.v4.app.DialogFragment; -import android.os.Bundle; import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; import java.io.Serializable; @@ -31,8 +32,13 @@ public class DBAlert extends DialogFragment { private static final String DLG_ID_KEY = "DLG_ID_KEY"; private static final String PARMS_KEY = "PARMS_KEY"; + public interface OnDismissListener { + void onDismissed(); + } + private Object[] mParams; private DlgID mDlgID; + private OnDismissListener m_onDismiss; public static DBAlert newInstance( DlgID dlgID, Object[] params ) { @@ -52,6 +58,8 @@ public class DBAlert extends DialogFragment { public DBAlert() {} + public DlgID getDlgID() { return mDlgID; } + @Override public void onSaveInstanceState( Bundle bundle ) { @@ -70,6 +78,20 @@ public class DBAlert extends DialogFragment { mParams = (Object[])sis.getSerializable(PARMS_KEY); XWActivity activity = (XWActivity)getActivity(); - return activity.makeDialog( mDlgID, mParams ); + return activity.makeDialog( this, mParams ); + } + + @Override + public void onDismiss( DialogInterface dif ) + { + if ( null != m_onDismiss ) { + m_onDismiss.onDismissed(); + } + super.onDismiss( dif ); + } + + protected void setOnDismiss( OnDismissListener lstnr ) + { + m_onDismiss = lstnr; } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java index e327337ec..4339922eb 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java @@ -423,8 +423,9 @@ public class DelegateBase implements DlgClickNotify, m_dlgDelegate.showDialog( dlgID ); } - protected Dialog makeDialog( DlgID dlgID, Object[] params ) + protected Dialog makeDialog( DBAlert alert, Object[] params ) { + DlgID dlgID = alert.getDlgID(); DbgUtils.logd( TAG, "makeDialog(): not handling %s", dlgID.toString() ); return null; } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictsDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictsDelegate.java index 0a85443e7..5f1b47003 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictsDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictsDelegate.java @@ -359,14 +359,14 @@ public class DictsDelegate extends ListDelegateBase } @Override - protected Dialog makeDialog( DlgID dlgID, Object[] params ) + protected Dialog makeDialog( DBAlert alert, Object[] params ) { OnClickListener lstnr, lstnr2; Dialog dialog; String message; boolean doRemove = true; - switch( dlgID ) { + switch( alert.getDlgID() ) { case MOVE_DICT: { final String[] selNames = getSelNames(); final int[] moveTo = { -1 }; @@ -460,7 +460,7 @@ public class DictsDelegate extends ListDelegateBase } default: - dialog = super.makeDialog( dlgID, params ); + dialog = super.makeDialog( alert, params ); break; } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DualpaneDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DualpaneDelegate.java index 124738f94..a3db3c2f8 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DualpaneDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DualpaneDelegate.java @@ -47,13 +47,13 @@ public class DualpaneDelegate extends DelegateBase { } @Override - protected Dialog makeDialog( DlgID dlgID, Object[] params ) + protected Dialog makeDialog( DBAlert alert, Object[] params ) { Dialog dialog = null; MainActivity main = (MainActivity)m_activity; XWFragment[] frags = main.getVisibleFragments(); for ( XWFragment frag : frags ) { - dialog = frag.getDelegate().makeDialog( dlgID, params ); + dialog = frag.getDelegate().makeDialog( alert, params ); if ( null != dialog ) { break; } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java index d3964116a..941b70d0b 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java @@ -607,12 +607,13 @@ public class GamesListDelegate extends ListDelegateBase } @Override - protected Dialog makeDialog( DlgID dlgID, Object[] params ) + protected Dialog makeDialog( DBAlert alert, Object[] params ) { Dialog dialog = null; OnClickListener lstnr, lstnr2; AlertDialog.Builder ab; + DlgID dlgID = alert.getDlgID(); switch ( dlgID ) { case WARN_NODICT: case WARN_NODICT_NEW: @@ -824,25 +825,25 @@ public class GamesListDelegate extends ListDelegateBase (EditText)layout.findViewById( R.id.name_edit ); etext.setText( CommonPrefs.getDefaultPlayerName( m_activity, 0, true ) ); + alert.setOnDismiss( new DBAlert.OnDismissListener() { + @Override + public void onDismissed() { + String name = etext.getText().toString(); + if ( 0 == name.length() ) { + name = CommonPrefs. + getDefaultPlayerName( m_activity, 0, true ); + } else { + CommonPrefs.setDefaultPlayerName( m_activity, name ); + } + makeThenLaunchOrConfigure(); + } + } ); dialog = makeAlertBuilder() .setTitle( R.string.default_name_title ) .setMessage( R.string.default_name_message ) .setPositiveButton( android.R.string.ok, null ) .setView( layout ) .create(); - dialog.setOnDismissListener(new DialogInterface. - OnDismissListener() { - public void onDismiss( DialogInterface dlg ) { - String name = etext.getText().toString(); - if ( 0 == name.length() ) { - name = CommonPrefs. - getDefaultPlayerName( m_activity, 0, true ); - } - CommonPrefs.setDefaultPlayerName( m_activity, name ); - - makeThenLaunchOrConfigure(); - } - }); } break; @@ -922,7 +923,7 @@ public class GamesListDelegate extends ListDelegateBase break; default: - dialog = super.makeDialog( dlgID, params ); + dialog = super.makeDialog( alert, params ); break; } return dialog; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWActivity.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWActivity.java index 61a007fe2..1f2f59914 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWActivity.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWActivity.java @@ -280,9 +280,9 @@ public class XWActivity extends FragmentActivity df.show( getSupportFragmentManager(), "dialog" ); } - protected Dialog makeDialog( DlgID dlgID, Object[] params ) + protected Dialog makeDialog( DBAlert alert, Object[] params ) { - return m_dlgt.makeDialog( dlgID, params ); + return m_dlgt.makeDialog( alert, params ); } ////////////////////////////////////////////////////////////