improve (fix?) invite/wait dialog

Override onCancel() in order to finish when the alert's closed via the
back button. Count the number of alerts and when it drops to 0 (when all
the alerts launched from the invite/wait dialog are gone) put the
invite/wait up again.
This commit is contained in:
Eric House 2017-03-23 08:39:15 -07:00
parent d9a4783e32
commit 265818725c
2 changed files with 106 additions and 39 deletions

View file

@ -80,6 +80,7 @@ public class BoardDelegate extends DelegateBase
implements TransportProcs.TPMsgHandler, View.OnClickListener, implements TransportProcs.TPMsgHandler, View.OnClickListener,
DwnldDelegate.DownloadFinishedListener, DwnldDelegate.DownloadFinishedListener,
ConnStatusHandler.ConnStatusCBacks, ConnStatusHandler.ConnStatusCBacks,
XWDialogFragment.OnLastGoneListener,
NFCUtils.NFCActor { NFCUtils.NFCActor {
private static final String TAG = BoardDelegate.class.getSimpleName(); private static final String TAG = BoardDelegate.class.getSimpleName();
@ -131,7 +132,6 @@ public class BoardDelegate extends DelegateBase
private boolean m_overNotShown; private boolean m_overNotShown;
private boolean m_dropOnDismiss; private boolean m_dropOnDismiss;
private DBAlert m_inviteAlert; private DBAlert m_inviteAlert;
private int m_inviteAlertCount;
public class TimerRunnable implements Runnable { public class TimerRunnable implements Runnable {
private int m_why; private int m_why;
@ -380,27 +380,10 @@ public class BoardDelegate extends DelegateBase
.setNegativeButton( R.string.button_no, null ) .setNegativeButton( R.string.button_no, null )
.create(); .create();
break; break;
case DLG_INVITE: case DLG_INVITE: {
InviteAlertState state = (InviteAlertState)params[0]; InviteAlertState state = (InviteAlertState)params[0];
dialog = makeInviteDialog( alert, state ); dialog = makeInviteDialog( alert, state );
if ( null != dialog ) { }
// Hack: I can't prevent screen rotation from duplicating this alert
if ( null != m_inviteAlert ) {
m_inviteAlert.dismiss();
}
m_inviteAlert = alert;
alert.setOnDismissListener( new DBAlert.OnDismissListener() {
@Override
public void onDismissed( XWDialogFragment frag ) {
DbgUtils.logd( TAG, "onDismissed(%s)", frag.toString() );
m_inviteAlert = null;
if ( null != m_mySIS && m_mySIS.nMissing > 0
&& 0 == m_inviteAlertCount ) {
finish();
}
}
} );
}
break; break;
case ENABLE_NFC: case ENABLE_NFC:
@ -520,7 +503,6 @@ public class BoardDelegate extends DelegateBase
if ( state.summary.hasRematchInfo() ) { if ( state.summary.hasRematchInfo() ) {
tryRematchInvites( true ); tryRematchInvites( true );
} else { } else {
++m_inviteAlertCount;
callInviteChoices( sentInfo[0] ); callInviteChoices( sentInfo[0] );
} }
} else { } else {
@ -539,7 +521,6 @@ public class BoardDelegate extends DelegateBase
public void onClick( DialogInterface dialog, public void onClick( DialogInterface dialog,
int item ) { int item ) {
String msg = sentInfo[0].getAsText( activity ); String msg = sentInfo[0].getAsText( activity );
++m_inviteAlertCount;
makeOkOnlyBuilder( msg ) makeOkOnlyBuilder( msg )
.setAction( Action.INVITE_INFO ) .setAction( Action.INVITE_INFO )
.show(); .show();
@ -548,10 +529,36 @@ public class BoardDelegate extends DelegateBase
ab.setNeutralButton( R.string.newgame_invite_more, lstnrMore ); ab.setNeutralButton( R.string.newgame_invite_more, lstnrMore );
} }
if ( showInviteButton ) { if ( showInviteButton ) {
ab.setNegativeButton( R.string.button_wait, null ); ab.setNegativeButton( R.string.button_wait,
new OnClickListener() {
@Override
public void onClick( DialogInterface di,
int item ) {
finish();
}
} );
} }
dialog = ab.create(); dialog = ab.create();
// Hack: I can't prevent screen rotation from duplicating this alert
// if ( null != m_inviteAlert ) {
// m_inviteAlert.dismiss();
// }
m_inviteAlert = alert;
alert.setOnCancelListener( new DBAlert.OnCancelListener() {
@Override
public void onCancelled( XWDialogFragment frag ) {
finish();
}
} );
alert.setOnDismissListener( new DBAlert.OnDismissListener() {
@Override
public void onDismissed( XWDialogFragment frag ) {
m_inviteAlert = null;
}
} );
} }
return dialog; return dialog;
} // makeInviteDialog } // makeInviteDialog
@ -614,12 +621,14 @@ public class BoardDelegate extends DelegateBase
@Override @Override
protected void onResume() protected void onResume()
{ {
XWDialogFragment.setOnLastGoneListener(this);
super.onResume(); super.onResume();
doResume( false ); doResume( false );
} }
protected void onPause() protected void onPause()
{ {
XWDialogFragment.setOnLastGoneListener(null);
closeIfFinishing( false ); closeIfFinishing( false );
m_handler = null; m_handler = null;
ConnStatusHandler.setHandler( null ); ConnStatusHandler.setHandler( null );
@ -654,7 +663,6 @@ public class BoardDelegate extends DelegateBase
protected void onSaveInstanceState( Bundle outState ) protected void onSaveInstanceState( Bundle outState )
{ {
outState.putSerializable( SAVE_MYSIS, m_mySIS ); outState.putSerializable( SAVE_MYSIS, m_mySIS );
m_mySIS = null; // signal that we're exiting
} }
private void getBundledData( Bundle bundle ) private void getBundledData( Bundle bundle )
@ -1155,12 +1163,6 @@ public class BoardDelegate extends DelegateBase
{ {
boolean handled = true; boolean handled = true;
switch ( action ) { switch ( action ) {
case INVITE_INFO:
if ( 0 < m_inviteAlertCount ) {
--m_inviteAlertCount;
showInviteAlertIf();
}
break;
case ENABLE_RELAY_DO_OR: case ENABLE_RELAY_DO_OR:
if ( m_dropOnDismiss ) { if ( m_dropOnDismiss ) {
postDelayed( new Runnable() { postDelayed( new Runnable() {
@ -1174,12 +1176,6 @@ public class BoardDelegate extends DelegateBase
finish(); finish();
break; break;
case LAUNCH_INVITE_ACTION:
Assert.assertTrue( 0 < m_inviteAlertCount || !BuildConfig.DEBUG );
--m_inviteAlertCount;
showInviteAlertIf();
break;
default: default:
handled = false; handled = false;
} }
@ -1453,6 +1449,14 @@ public class BoardDelegate extends DelegateBase
return data; return data;
} }
//////////////////////////////////////////////////
// XWDialogFragment.OnLastGoneListener
//////////////////////////////////////////////////
public void onLastGone()
{
showInviteAlertIf();
}
////////////////////////////////////////////////// //////////////////////////////////////////////////
// ConnStatusHandler.ConnStatusCBacks // ConnStatusHandler.ConnStatusCBacks
////////////////////////////////////////////////// //////////////////////////////////////////////////
@ -2307,7 +2311,7 @@ public class BoardDelegate extends DelegateBase
private void showInviteAlertIf() private void showInviteAlertIf()
{ {
if ( null == m_inviteAlert && m_mySIS.nMissing > 0 if ( null == m_inviteAlert && m_mySIS.nMissing > 0
&& m_inviteAlertCount == 0 ) { && XWDialogFragment.inviteAlertCount() == 0 ) {
InviteAlertState ias = new InviteAlertState(); InviteAlertState ias = new InviteAlertState();
ias.summary = m_summary; ias.summary = m_summary;
ias.gi = m_gi; ias.gi = m_gi;

View file

@ -19,15 +19,38 @@
package org.eehouse.android.xw4; package org.eehouse.android.xw4;
import android.support.v4.app.DialogFragment; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.support.v4.app.DialogFragment;
import junit.framework.Assert;
class XWDialogFragment extends DialogFragment { class XWDialogFragment extends DialogFragment {
private static final String TAG = XWDialogFragment.class.getSimpleName();
private static int s_count = 0;
private OnDismissListener m_onDismiss; private OnDismissListener m_onDismiss;
private OnCancelListener m_onCancel;
private static OnLastGoneListener s_onLast;
public interface OnDismissListener { public interface OnDismissListener {
void onDismissed( XWDialogFragment frag ); void onDismissed( XWDialogFragment frag );
} }
public interface OnCancelListener {
void onCancelled( XWDialogFragment frag );
}
public interface OnLastGoneListener {
void onLastGone();
}
@Override
public void onCancel( DialogInterface dialog )
{
if ( null != m_onCancel ) {
m_onCancel.onCancelled( this );
}
super.onCancel( dialog );
}
@Override @Override
public void onDismiss( DialogInterface dif ) public void onDismiss( DialogInterface dif )
@ -38,9 +61,49 @@ class XWDialogFragment extends DialogFragment {
super.onDismiss( dif ); super.onDismiss( dif );
} }
@Override
public void onAttach( Context context )
{
++s_count;
super.onAttach( context );
// DbgUtils.logd(TAG, "%s added to %s; now %d", toString(),
// context.getClass().getSimpleName(), s_count );
}
@Override
public void onDetach()
{
--s_count;
Assert.assertTrue( s_count >= 0 || !BuildConfig.DEBUG );
super.onDetach();
// DbgUtils.logd(TAG, "%s removed from %s; now %d", toString(),
// getActivity().getClass().getSimpleName(), s_count );
if ( 0 == s_count && null != s_onLast ) {
s_onLast.onLastGone();
}
}
protected void setOnDismissListener( OnDismissListener lstnr ) protected void setOnDismissListener( OnDismissListener lstnr )
{ {
Assert.assertTrue( null == lstnr || null == m_onDismiss || !BuildConfig.DEBUG );
m_onDismiss = lstnr; m_onDismiss = lstnr;
} }
protected void setOnCancelListener( OnCancelListener lstnr )
{
Assert.assertTrue( null == lstnr || null == m_onCancel || !BuildConfig.DEBUG );
m_onCancel = lstnr;
}
protected static void setOnLastGoneListener( OnLastGoneListener lstnr )
{
Assert.assertTrue( null == lstnr || null == s_onLast || !BuildConfig.DEBUG );
s_onLast = lstnr;
}
protected static int inviteAlertCount()
{
DbgUtils.logd( TAG, "inviteAlertCount() => %d", s_count );
return s_count;
}
} }