From 82a11e5ebf79bd88c7263508be9542b29e7bf16d Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 23 Nov 2020 21:35:35 -0800 Subject: [PATCH] explain where deleted game message comes from Not sure it'll make release builds, but it's useful for figuring out if the deletes should actually be there. --- .../java/org/eehouse/android/xw4/BTUtils.java | 17 ++++++++-------- .../eehouse/android/xw4/BoardDelegate.java | 20 ++++++++++++++----- .../org/eehouse/android/xw4/MQTTUtils.java | 9 +++++++-- .../eehouse/android/xw4/jni/CommsAddrRec.java | 20 ++++++++++++++++++- .../app/src/main/res/values/strings.xml | 2 +- 5 files changed, 50 insertions(+), 18 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTUtils.java index 1446277a3..254c998c8 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTUtils.java @@ -53,6 +53,7 @@ import org.eehouse.android.xw4.DbgUtils.DeadlockWatch; import org.eehouse.android.xw4.MultiService.DictFetchOwner; import org.eehouse.android.xw4.MultiService.MultiEvent; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; +import org.eehouse.android.xw4.jni.CommsAddrRec.ConnExpl; import org.eehouse.android.xw4.jni.CommsAddrRec; import org.eehouse.android.xw4.jni.XwJNI; import org.eehouse.android.xw4.loc.LocUtils; @@ -962,7 +963,8 @@ public class BTUtils { mHelper.postEvent( MultiEvent.BAD_PROTO_BT, socket.getRemoteDevice().getName() ); } else { - handleReply( inStream, cmd, gameID, reply ); + String remoteName = socket.getRemoteDevice().getName(); + handleReply( inStream, cmd, gameID, remoteName, reply ); } ++nDone; } @@ -979,18 +981,19 @@ public class BTUtils { } // writeAndCheck() private void handleReply( DataInputStream inStream, BTCmd cmd, int gameID, - BTCmd reply ) throws IOException + String remoteName, BTCmd reply ) throws IOException { - MultiEvent evt = null; switch ( cmd ) { case MESG_SEND: case MESG_GAMEGONE: switch ( reply ) { case MESG_ACCPT: - evt = MultiEvent.MESSAGE_ACCEPTED; + mHelper.postEvent( MultiEvent.MESSAGE_ACCEPTED, gameID, 0, mName ); break; case MESG_GAMEGONE: - evt = MultiEvent.MESSAGE_NOGAME; + ConnExpl expl = new ConnExpl( CommsConnType.COMMS_CONN_BT, + remoteName ); + mHelper.postEvent( MultiEvent.MESSAGE_NOGAME, gameID, expl ); break; } break; @@ -1028,10 +1031,6 @@ public class BTUtils { Log.e( TAG, "handleReply(cmd=%s) case not handled", cmd ); Assert.failDbg(); // fired } - - if ( null != evt ) { - mHelper.postEvent( evt, gameID, 0, mName ); - } } private BluetoothSocket connect( BluetoothDevice remote, int timeout ) 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 6010604bb..e852391d2 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 @@ -262,8 +262,14 @@ public class BoardDelegate extends DelegateBase case DLG_DELETED: { String gameName = GameUtils.getName( m_activity, m_rowid ); + CommsAddrRec.ConnExpl expl = params.length == 0 ? null + : (CommsAddrRec.ConnExpl)params[0]; + String message = getString( R.string.msg_dev_deleted_fmt, gameName ); + if ( null != expl ) { + message += "\n\n" + expl.getUserExpl( m_activity ); + } ab = ab.setTitle( R.string.query_title ) - .setMessage( getString( R.string.msg_dev_deleted_fmt, gameName ) ) + .setMessage( message ) .setPositiveButton( android.R.string.ok, null ); lstnr = new OnClickListener() { @Override @@ -429,7 +435,7 @@ public class BoardDelegate extends DelegateBase } // makeDialog private boolean mDeletePosted; - private void postDeleteOnce() + private void postDeleteOnce( final CommsAddrRec.ConnExpl expl ) { if ( !mDeletePosted ) { // PENDING: could clear this if user says "ok" rather than "delete" @@ -437,7 +443,7 @@ public class BoardDelegate extends DelegateBase post( new Runnable() { @Override public void run() { - showDialogFragment( DlgID.DLG_DELETED ); + showDialogFragment( DlgID.DLG_DELETED, expl ); } } ); } @@ -1309,7 +1315,11 @@ public class BoardDelegate extends DelegateBase case MESSAGE_NOGAME: final int gameID = (Integer)args[0]; if ( null != m_gi && gameID == m_gi.gameID && !isFinishing() ) { - postDeleteOnce(); + CommsAddrRec.ConnExpl expl = null; + if ( 1 < args.length && args[1] instanceof CommsAddrRec.ConnExpl ) { + expl = (CommsAddrRec.ConnExpl)args[1]; + } + postDeleteOnce( expl ); } break; @@ -1395,7 +1405,7 @@ public class BoardDelegate extends DelegateBase case DEADGAME: case DELETED: - postDeleteOnce(); + postDeleteOnce( null ); break; case OLDFLAGS: diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MQTTUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MQTTUtils.java index 112973298..6a581a496 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MQTTUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MQTTUtils.java @@ -40,8 +40,9 @@ import javax.net.ssl.HttpsURLConnection; import org.json.JSONException; import org.json.JSONObject; -import org.eehouse.android.xw4.jni.CommsAddrRec; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; +import org.eehouse.android.xw4.jni.CommsAddrRec.ConnExpl; +import org.eehouse.android.xw4.jni.CommsAddrRec; import org.eehouse.android.xw4.jni.XwJNI; import org.eehouse.android.xw4.loc.LocUtils; @@ -605,8 +606,12 @@ public class MQTTUtils extends Thread implements IMqttActionListener, MqttCallba public static void handleGameGone( Context context, CommsAddrRec from, int gameID ) { if ( BuildConfig.DO_MQTT_GAME_GONE ) { + String player = XwJNI.kplr_nameForMqttDev( from.mqtt_devID ); + ConnExpl expl = null == player ? null + : new ConnExpl( CommsConnType.COMMS_CONN_MQTT, player ); new MQTTServiceHelper( context, from ) - .postEvent( MultiService.MultiEvent.MESSAGE_NOGAME, gameID ); + .postEvent( MultiService.MultiEvent.MESSAGE_NOGAME, gameID, + expl ); } else { Log.d( TAG, "not posting game-gone for now (gameID: %d)" , gameID ); } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java index 785aa2c52..28cfeb189 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/CommsAddrRec.java @@ -42,8 +42,9 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.io.Serializable; -public class CommsAddrRec implements java.io.Serializable { +public class CommsAddrRec implements Serializable { private static final String TAG = CommsAddrRec.class.getSimpleName(); public enum CommsConnType { @@ -99,6 +100,23 @@ public class CommsAddrRec implements java.io.Serializable { } }; + // Pairs how and name of device in that context + public static class ConnExpl implements Serializable { + public final CommsConnType mType; + public final String mName; + + public ConnExpl( CommsConnType typ, String name ) + { + mType = typ; + mName = name; + } + + public String getUserExpl( Context context ) + { + return String.format( "%s: %s", mType, mName ); + } + } + public static class CommsConnTypeSet extends HashSet { private static final int BIT_VECTOR_MASK = 0x8000; diff --git a/xwords4/android/app/src/main/res/values/strings.xml b/xwords4/android/app/src/main/res/values/strings.xml index fcbcd7f84..36229d10e 100644 --- a/xwords4/android/app/src/main/res/values/strings.xml +++ b/xwords4/android/app/src/main/res/values/strings.xml @@ -525,7 +525,7 @@ Invite forwarded via MQTT/internet - to known player ā€œ%1$sā€ on %2$s. + to Known Player ā€œ%1$sā€ on %2$s.