diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java index c671b6ebe..8d0b26788 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java @@ -187,16 +187,14 @@ public class BoardDelegate extends DelegateBase } break; - case GAME_OVER: - case DLG_CONNSTAT: { + case GAME_OVER: { GameSummary summary = (GameSummary)params[0]; int title = (Integer)params[1]; String msg = (String)params[2]; ab.setTitle( title ) .setMessage( msg ) .setPositiveButton( android.R.string.ok, null ); - if ( DlgID.GAME_OVER == dlgID - && rematchSupported( m_activity, true, summary ) ) { + if ( rematchSupported( m_activity, true, summary ) ) { lstnr = new OnClickListener() { public void onClick( DialogInterface dlg, int whichButton ) { @@ -215,25 +213,6 @@ public class BoardDelegate extends DelegateBase }; ab.setNeutralButton( R.string.button_archive, lstnr ); } - - } else if ( DlgID.DLG_CONNSTAT == dlgID - && BuildConfig.DEBUG && null != m_connTypes - && (m_connTypes.contains( CommsConnType.COMMS_CONN_RELAY ) - || m_connTypes.contains( CommsConnType.COMMS_CONN_P2P )) ) { - - lstnr = new OnClickListener() { - public void onClick( DialogInterface dlg, - int whichButton ) { - NetStateCache.reset( m_activity ); - if ( m_connTypes.contains( CommsConnType.COMMS_CONN_RELAY ) ) { - RelayService.reset( m_activity ); - } - if ( m_connTypes.contains( CommsConnType.COMMS_CONN_P2P ) ) { - WiDirService.reset( m_activity ); - } - } - }; - ab.setNegativeButton( R.string.button_reconnect, lstnr ); } dialog = ab.create(); } @@ -1473,6 +1452,7 @@ public class BoardDelegate extends DelegateBase ////////////////////////////////////////////////// // ConnStatusHandler.ConnStatusCBacks ////////////////////////////////////////////////// + @Override public void invalidateParent() { runOnUiThread(new Runnable() { @@ -1483,26 +1463,13 @@ public class BoardDelegate extends DelegateBase }); } + @Override public void onStatusClicked() { - CommsAddrRec[] addrs = XwJNI.comms_getAddrs( m_jniGamePtr ); - CommsAddrRec addr = null != addrs && 0 < addrs.length ? addrs[0] : null; - final String msg = ConnStatusHandler - .getStatusText( m_activity, m_connTypes, addr ); - - post( new Runnable() { - @Override - public void run() { - if ( null == msg ) { - askNoAddrsDelete(); - } else { - showDialogFragment( DlgID.DLG_CONNSTAT, null, - R.string.info_title, msg ); - } - } - } ); + onStatusClicked( m_jniGamePtr ); } + @Override public Handler getHandler() { return m_handler; @@ -1515,15 +1482,6 @@ public class BoardDelegate extends DelegateBase finish(); } - private void askNoAddrsDelete() - { - makeConfirmThenBuilder( R.string.connstat_net_noaddr, - Action.DELETE_AND_EXIT ) - .setPosButton( R.string.list_item_delete ) - .setNegButton( R.string.button_close_game ) - .show(); - } - private void askDropRelay() { String msg = getString( R.string.confirm_drop_relay ); 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 0bd011297..0900cb3cd 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 @@ -22,12 +22,15 @@ package org.eehouse.android.xw4; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; -import android.support.v4.app.DialogFragment; +import android.content.Context; import android.content.DialogInterface.OnCancelListener; +import android.content.DialogInterface.OnClickListener; +import android.content.DialogInterface; import android.content.Intent; import android.graphics.Point; import android.graphics.Rect; import android.os.Bundle; +import android.support.v4.app.DialogFragment; import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu; import android.view.LayoutInflater; @@ -40,7 +43,6 @@ import android.widget.CheckBox; import android.widget.EditText; import android.widget.TextView; - import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.ActionPair; import org.eehouse.android.xw4.DlgDelegate.ConfirmThenBuilder; @@ -48,6 +50,12 @@ import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify; import org.eehouse.android.xw4.DlgDelegate.NotAgainBuilder; import org.eehouse.android.xw4.DlgDelegate.OkOnlyBuilder; import org.eehouse.android.xw4.MultiService.MultiEvent; +import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; +import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet; +import org.eehouse.android.xw4.jni.CommsAddrRec; +import org.eehouse.android.xw4.jni.GameSummary; +import org.eehouse.android.xw4.jni.XwJNI.GamePtr; +import org.eehouse.android.xw4.jni.XwJNI; import org.eehouse.android.xw4.loc.LocUtils; import java.lang.ref.WeakReference; @@ -414,10 +422,44 @@ public class DelegateBase implements DlgClickNotify, protected Dialog makeDialog( DBAlert alert, Object[] params ) { + Dialog dialog = null; DlgID dlgID = alert.getDlgID(); - Log.d( TAG, "%s.makeDialog(): not handling %s", getClass().getSimpleName(), - dlgID.toString() ); - return null; + switch ( dlgID ) { + case DLG_CONNSTAT: { + AlertDialog.Builder ab = makeAlertBuilder(); + GameSummary summary = (GameSummary)params[0]; + int title = (Integer)params[1]; + String msg = (String)params[2]; + final CommsConnTypeSet conTypes = summary.conTypes; + ab.setTitle( title ) + .setMessage( msg ) + .setPositiveButton( android.R.string.ok, null ); + if ( BuildConfig.DEBUG && null != conTypes + && (conTypes.contains( CommsConnType.COMMS_CONN_RELAY ) + || conTypes.contains( CommsConnType.COMMS_CONN_P2P )) ) { + OnClickListener lstnr = new OnClickListener() { + public void onClick( DialogInterface dlg, + int whichButton ) { + NetStateCache.reset( m_activity ); + if ( conTypes.contains( CommsConnType.COMMS_CONN_RELAY ) ) { + RelayService.reset( getActivity() ); + } + if ( conTypes.contains( CommsConnType.COMMS_CONN_P2P ) ) { + WiDirService.reset( getActivity() ); + } + } + }; + ab.setNegativeButton( R.string.button_reconnect, lstnr ); + } + dialog = ab.create(); + } + break; + default: + Log.d( TAG, "%s.makeDialog(): not handling %s", getClass().getSimpleName(), + dlgID.toString() ); + break; + } + return dialog; } protected void showDialogFragment( final DlgID dlgID, final Object... params ) @@ -593,6 +635,53 @@ public class DelegateBase implements DlgClickNotify, runIfVisible(); } + public void onStatusClicked( GamePtr gamePtr ) + { + Context context = getActivity(); + CommsAddrRec[] addrs = XwJNI.comms_getAddrs( gamePtr ); + CommsAddrRec addr = null != addrs && 0 < addrs.length ? addrs[0] : null; + final GameSummary summary = GameUtils.getSummary( context, gamePtr.getRowid(), 1 ); + if ( null != summary ) { + final String msg = ConnStatusHandler + .getStatusText( context, summary.conTypes, addr ); + + post( new Runnable() { + @Override + public void run() { + if ( null == msg ) { + askNoAddrsDelete(); + } else { + showDialogFragment( DlgID.DLG_CONNSTAT, summary, + R.string.info_title, msg ); + } + } + } ); + } + } + + public void onStatusClicked( long rowid ) + { + Log.d( TAG, "onStatusClicked(%d)", rowid ); + try ( GameLock lock = GameLock.getFor( rowid ).tryLockRO() ) { + if ( null != lock ) { + GamePtr gamePtr = GameUtils.loadMakeGame( getActivity(), lock ); + if ( null != gamePtr ) { + onStatusClicked( gamePtr ); + gamePtr.release(); + } + } + } + } + + protected void askNoAddrsDelete() + { + makeConfirmThenBuilder( R.string.connstat_net_noaddr, + Action.DELETE_AND_EXIT ) + .setPosButton( R.string.list_item_delete ) + .setNegButton( R.string.button_close_game ) + .show(); + } + ////////////////////////////////////////////////// // MultiService.MultiEventListener interface ////////////////////////////////////////////////// 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 6dfe22f22..e4c7eae9d 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 @@ -1671,9 +1671,11 @@ public class GamesListDelegate extends ListDelegateBase enable = BoardDelegate.rematchSupported( m_activity, rowID ); Utils.setItemVisible( menu, R.id.games_game_rematch, enable ); - enable = item.getSummary().isMultiGame() + boolean isMultiGame = item.getSummary().isMultiGame(); + enable = isMultiGame && (BuildConfig.DEBUG || XWPrefs.getDebugEnabled( m_activity )); Utils.setItemVisible( menu, R.id.games_game_invites, enable ); + Utils.setItemVisible( menu, R.id.games_game_netstats, isMultiGame ); enable = !m_launchedGames.contains( rowID ); Utils.setItemVisible( menu, R.id.games_game_delete, enable ); @@ -1848,6 +1850,10 @@ public class GamesListDelegate extends ListDelegateBase showDialogFragment( DlgID.RENAME_GAME, selRowIDs[0] ); break; + case R.id.games_game_netstats: + onStatusClicked( selRowIDs[0] ); + break; + // DEBUG only case R.id.games_game_invites: msg = GameUtils.getSummary( m_activity, selRowIDs[0] ) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java index bd51c2f92..93fc6592f 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java @@ -58,6 +58,8 @@ public class XwJNI { return this; } + public long getRowid() { return m_rowid; } + // Force (via an assert in finalize() below) that this is called. It's // better if jni stuff isn't being done on the finalizer thread public synchronized void release() diff --git a/xwords4/android/app/src/main/res/menu/games_list_game_menu.xml b/xwords4/android/app/src/main/res/menu/games_list_game_menu.xml index 8627fe01c..97bf85a39 100644 --- a/xwords4/android/app/src/main/res/menu/games_list_game_menu.xml +++ b/xwords4/android/app/src/main/res/menu/games_list_game_menu.xml @@ -25,6 +25,9 @@ + diff --git a/xwords4/android/app/src/main/res/values/strings.xml b/xwords4/android/app/src/main/res/values/strings.xml index 41331f79f..c7f91bc9f 100644 --- a/xwords4/android/app/src/main/res/values/strings.xml +++ b/xwords4/android/app/src/main/res/values/strings.xml @@ -148,6 +148,9 @@ + + Connections… + Games that have already connected