From 3a32d3a17b41ba9a03f91671d6bd9a47e6752b8b Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 13 Aug 2015 07:05:06 -0700 Subject: [PATCH] return count of messages sent from comms_resendAll(), and post it as a toast so user sees something happened. --- xwords4/android/XWords4/archive/R.java | 7 +++---- xwords4/android/XWords4/jni/xwjni.c | 6 ++++-- xwords4/android/XWords4/res/values/strings.xml | 6 ++++++ .../XWords4/res_src/values-ba_CK/strings.xml | 5 +++++ .../XWords4/res_src/values-ca_PS/strings.xml | 5 +++++ .../org/eehouse/android/xw4/BoardDelegate.java | 5 +++++ .../org/eehouse/android/xw4/jni/JNIThread.java | 9 ++++++--- .../src/org/eehouse/android/xw4/jni/XwJNI.java | 4 ++-- xwords4/common/comms.c | 15 ++++++++++----- xwords4/common/comms.h | 2 +- 10 files changed, 47 insertions(+), 17 deletions(-) diff --git a/xwords4/android/XWords4/archive/R.java b/xwords4/android/XWords4/archive/R.java index 0f5e81ec3..3ca5799b3 100644 --- a/xwords4/android/XWords4/archive/R.java +++ b/xwords4/android/XWords4/archive/R.java @@ -411,6 +411,9 @@ public final class R { */ public static final int query_trade_fmt=0x7f07000b; public static final int resend_finished_fmt=0x7f070007; + /** Shown after "resend messages" menuitem chosen + */ + public static final int resent_msgs_fmt=0x7f07001f; /** Intro to the paragraph listing all of the tiles remaining */ public static final int strd_remains_expl_fmt=0x7f07000a; @@ -848,7 +851,6 @@ public final class R { public static final int checking_for_fmt=0x7f0502ff; public static final int checking_title=0x7f0502fe; public static final int checkupdates_none_found=0x7f05022b; - public static final int clip_label=0x7f05030f; /** color of the "crosshairs", lines drawn vertically and horizontally through the square the user is currently touching in order to guide the fat-fingered (most of us) in @@ -1333,7 +1335,6 @@ public final class R { */ public static final int initial_player_minutes=0x7f050126; public static final int invite_choice_bt=0x7f05016b; - public static final int invite_choice_clip=0x7f05030d; public static final int invite_choice_email=0x7f05016a; public static final int invite_choice_nfc=0x7f05016c; /** EXPLAIN ME @@ -1356,7 +1357,6 @@ public final class R { */ public static final int invite_chooser_fmt=0x7f050171; public static final int invite_chooser_sms=0x7f050173; - public static final int invite_copied=0x7f05030e; public static final int invite_dict_missing_body_fmt=0x7f05023b; public static final int invite_dict_missing_body_noname_fmt=0x7f05023c; public static final int invite_dict_missing_title=0x7f05023a; @@ -1965,7 +1965,6 @@ public final class R { main Board screen */ public static final int not_again_chat=0x7f0501b1; - public static final int not_again_clip_expl_fmt=0x7f050310; public static final int not_again_comms_bt=0x7f05030b; public static final int not_again_comms_relay=0x7f050309; public static final int not_again_comms_sms=0x7f05030a; diff --git a/xwords4/android/XWords4/jni/xwjni.c b/xwords4/android/XWords4/jni/xwjni.c index 00f0a2ddf..88b18b050 100644 --- a/xwords4/android/XWords4/jni/xwjni.c +++ b/xwords4/android/XWords4/jni/xwjni.c @@ -1677,20 +1677,22 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1changeDict } #endif -JNIEXPORT void JNICALL +JNIEXPORT jint JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_comms_1resendAll ( JNIEnv* env, jclass C, jint gamePtr, jboolean force, jboolean thenAck ) { + jint result; XWJNI_START(); CommsCtxt* comms = state->game.comms; XP_ASSERT( !!comms ); - (void)comms_resendAll( comms, force ); + result = comms_resendAll( comms, force ); if ( thenAck ) { #ifdef XWFEATURE_COMMSACK comms_ackAny( comms ); #endif } XWJNI_END(); + return result; } #ifdef XWFEATURE_COMMSACK diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 90f486618..8e51f1607 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -2532,4 +2532,10 @@ Cannot find any moves + + + One message sent + %1$s messages sent + + diff --git a/xwords4/android/XWords4/res_src/values-ba_CK/strings.xml b/xwords4/android/XWords4/res_src/values-ba_CK/strings.xml index e0560e2da..1474ab684 100644 --- a/xwords4/android/XWords4/res_src/values-ba_CK/strings.xml +++ b/xwords4/android/XWords4/res_src/values-ba_CK/strings.xml @@ -2181,4 +2181,9 @@ Esu Htooteulb ot yalp tsniaga a ybraen ecived taht\'s \"deriap\" htiw sruoy. Tonnac dnif yna sevom + + + Eno egassem tnes + %1$s segassem tnes + diff --git a/xwords4/android/XWords4/res_src/values-ca_PS/strings.xml b/xwords4/android/XWords4/res_src/values-ca_PS/strings.xml index 66be44729..52bb792fa 100644 --- a/xwords4/android/XWords4/res_src/values-ca_PS/strings.xml +++ b/xwords4/android/XWords4/res_src/values-ca_PS/strings.xml @@ -2181,4 +2181,9 @@ USE BLUETOOTH TO PLAY AGAINST A NEARBY DEVICE THAT\'S \"PAIRED\" WITH YOURS. CANNOT FIND ANY MOVES + + + ONE MESSAGE SENT + %1$s MESSAGES SENT + diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java index 986d5a5fb..385c60fa6 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java @@ -2011,6 +2011,11 @@ public class BoardDelegate extends DelegateBase m_dlgTitle = msg.arg1; showDialog( DlgID.GAME_OVER ); break; + case JNIThread.MSGS_SENT: + int nSent = (Integer)msg.obj; + showToast( getQuantityString( R.plurals.resent_msgs_fmt, + nSent, nSent ) ); + break; } } }; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java index 7be80dd8d..b686c062b 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java @@ -102,6 +102,7 @@ public class JNIThread extends Thread { public static final int TOOLBAR_STATES = 4; public static final int GOT_WORDS = 5; public static final int GAME_OVER = 6; + public static final int MSGS_SENT = 7; public class GameStateInfo implements Cloneable { public int visTileCount; @@ -522,9 +523,11 @@ public class JNIThread extends Thread { break; case CMD_RESEND: - XwJNI.comms_resendAll( m_jniGamePtr, - ((Boolean)args[0]).booleanValue(), - ((Boolean)args[1]).booleanValue() ); + int nSent = + XwJNI.comms_resendAll( m_jniGamePtr, + ((Boolean)args[0]).booleanValue(), + ((Boolean)args[1]).booleanValue() ); + Message.obtain( m_handler, MSGS_SENT, nSent ).sendToTarget(); break; // case CMD_ACKANY: // XwJNI.comms_ackAny( m_jniGamePtr ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java index 2f3da7be4..6046dcc19 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java @@ -317,8 +317,8 @@ public class XwJNI { public static native void comms_getAddr( int gamePtr, CommsAddrRec addr ); public static native CommsAddrRec[] comms_getAddrs( int gamePtr ); public static native void comms_setAddr( int gamePtr, CommsAddrRec addr ); - public static native void comms_resendAll( int gamePtr, boolean force, - boolean andAck ); + public static native int comms_resendAll( int gamePtr, boolean force, + boolean andAck ); public static native void comms_ackAny( int gamePtr ); public static native void comms_transportFailed( int gamePtr, CommsConnType failed ); diff --git a/xwords4/common/comms.c b/xwords4/common/comms.c index a3c2de639..509bbea9a 100644 --- a/xwords4/common/comms.c +++ b/xwords4/common/comms.c @@ -1436,9 +1436,10 @@ send_ack( CommsCtxt* comms ) (void)send_via_relay( comms, XWRELAY_ACK, comms->rr.myHostID, NULL, 0 ); } -XP_Bool +XP_S16 comms_resendAll( CommsCtxt* comms, XP_Bool force ) { + XP_S16 count = 0; XP_Bool success = XP_TRUE; XP_ASSERT( !!comms ); @@ -1452,9 +1453,13 @@ comms_resendAll( CommsCtxt* comms, XP_Bool force ) MsgQueueElem* msg; for ( msg = comms->msgQueueHead; !!msg; msg = msg->next ) { - if ( 0 > sendMsg( comms, msg ) ) { + XP_S16 len = sendMsg( comms, msg ); + if ( 0 > len ) { success = XP_FALSE; break; + } else { + XP_ASSERT( 0 < len ); + ++count; } } @@ -1465,9 +1470,9 @@ comms_resendAll( CommsCtxt* comms, XP_Bool force ) comms->nextResend = now + comms->resendBackoff; } } - XP_LOGF( TAGFMT() "=>%d", TAGPRMS, success ); - return success; -} /* comms_resend */ + XP_LOGF( TAGFMT() "=>%d", TAGPRMS, count ); + return count; +} /* comms_resendAll */ #ifdef XWFEATURE_COMMSACK void diff --git a/xwords4/common/comms.h b/xwords4/common/comms.h index dcd95cdf2..385e62fa2 100644 --- a/xwords4/common/comms.h +++ b/xwords4/common/comms.h @@ -214,7 +214,7 @@ void addrFromStream( CommsAddrRec* addr, XWStreamCtxt* stream ); void addrToStream( XWStreamCtxt* stream, const CommsAddrRec* addr ); XP_S16 comms_send( CommsCtxt* comms, XWStreamCtxt* stream ); -XP_Bool comms_resendAll( CommsCtxt* comms, XP_Bool force ); +XP_S16 comms_resendAll( CommsCtxt* comms, XP_Bool force ); XP_U16 comms_getChannelSeed( CommsCtxt* comms ); #ifdef XWFEATURE_COMMSACK