add net-stats dialog to log-tap games menu

So I don't have to open a game to see e.g. how it's connecting, refactor
the network status stuff so it can be called from both board and
gameslist views. Then add new context menuitem that calls it.
This commit is contained in:
Eric House 2019-01-08 11:37:57 -08:00
parent e9e03a06a3
commit 7c7b80deae
6 changed files with 115 additions and 54 deletions

View file

@ -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 );

View file

@ -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
//////////////////////////////////////////////////

View file

@ -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] )

View file

@ -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()

View file

@ -25,6 +25,9 @@
<item android:id="@+id/games_game_copy"
android:title="@string/list_item_copy"
/>
<item android:id="@+id/games_game_netstats"
android:title="@string/list_item_netstats"
/>
<item android:id="@+id/games_game_select"
android:title="@string/list_item_select"
/>

View file

@ -148,6 +148,9 @@
<!-- Title of dialog for renaming game (triggered by selecting
list_item_rename) -->
<!-- long-tap game list menuitem for showing info about game's connectivity -->
<string name="list_item_netstats">Connections…</string>
<!-- If you try to copy a networked game you get this error
message. -->
<string name="no_copy_network">Games that have already connected