From d0d81483e37214c5e7fb654d87f3c2d063c48480 Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 5 Jun 2015 22:12:08 -0700 Subject: [PATCH] When relay-configured game is opened that hasn't yet managed to connect to relay, instead of suggesting user invite another player warn him/her that it's unconnected and suggest opening again later. The problem this addresses is that a game must be opened to make the initial relay connection, and that doesn't happen in the background. This is a temporary fix that should prevent sending invitations to games that the relay doesn't yet know about. --- xwords4/android/XWords4/archive/R.java | 1 + .../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 ++ .../XWords4/res_src/values-fr/strings.xml | 6 ++ .../eehouse/android/xw4/BoardDelegate.java | 56 ++++++++++++------- .../src/org/eehouse/android/xw4/DlgID.java | 1 + .../android/xw4/GamesListDelegate.java | 2 +- .../eehouse/android/xw4/jni/GameSummary.java | 9 ++- 9 files changed, 68 insertions(+), 23 deletions(-) diff --git a/xwords4/android/XWords4/archive/R.java b/xwords4/android/XWords4/archive/R.java index 67c767fc4..2e2eaa174 100644 --- a/xwords4/android/XWords4/archive/R.java +++ b/xwords4/android/XWords4/archive/R.java @@ -1927,6 +1927,7 @@ public final class R { substituted. */ public static final int no_name_found_fmt=0x7f0500b8; + public static final int no_relay_conn=0x7f0502fb; /** This is not currently shown Crosswords wordlists, which are just compressed lists of words plus tile information, determine diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index fa6a76c44..b63ea2143 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -2462,4 +2462,10 @@ Checking Checking for wordlists in %1$s… SD card write complete. + + This game is configured to use the + relay for communication but has been unable to connect, either + because of problems with your device\'s internet connection or + because the relay is not running.\n\nPlease try opening the game again + later. 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 078c4d55c..4ca5ee973 100644 --- a/xwords4/android/XWords4/res_src/values-ba_CK/strings.xml +++ b/xwords4/android/XWords4/res_src/values-ba_CK/strings.xml @@ -2132,4 +2132,9 @@ Gnikcehc Gnikcehc rof stsildrow ni %1$s… DS drac etirw etelpmoc. + Siht emag si derugifnoc ot esu eht + yaler rof noitacinummoc tub sah neeb elbanu ot ,tcennoc rehtie + esuaceb fo smelborp htiw ruoy ecived\'s tenretni noitcennoc ro + esuaceb eht yaler si ton gninnur.\n\nEsaelp yrt gninepo eht emag niaga + retal. 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 4c15fa81e..077973e69 100644 --- a/xwords4/android/XWords4/res_src/values-ca_PS/strings.xml +++ b/xwords4/android/XWords4/res_src/values-ca_PS/strings.xml @@ -2132,4 +2132,9 @@ CHECKING CHECKING FOR WORDLISTS IN %1$s… SD CARD WRITE COMPLETE. + THIS GAME IS CONFIGURED TO USE THE + RELAY FOR COMMUNICATION BUT HAS BEEN UNABLE TO CONNECT, EITHER + BECAUSE OF PROBLEMS WITH YOUR DEVICE\'S INTERNET CONNECTION OR + BECAUSE THE RELAY IS NOT RUNNING.\n\nPLEASE TRY OPENING THE GAME AGAIN + LATER. diff --git a/xwords4/android/XWords4/res_src/values-fr/strings.xml b/xwords4/android/XWords4/res_src/values-fr/strings.xml index b3b37b8f0..a458569d6 100644 --- a/xwords4/android/XWords4/res_src/values-fr/strings.xml +++ b/xwords4/android/XWords4/res_src/values-fr/strings.xml @@ -3444,4 +3444,10 @@ pour la langue Écriture sur la carte SD finie. + Cette partie est configurée pour + communiquer en utilisant le relai mais n\'a pas pu se connecter, soit + à cause de problèmes avec la connexion Internet de votre périphérique, + soit parce que le relai est hors service.\n\n Veuillez réessayer + d\'ouvrir la partie ultérieurement. + 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 73b2806ee..0803265ff 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java @@ -89,6 +89,7 @@ public class BoardDelegate extends DelegateBase private GameLock m_gameLock; private CurGameInfo m_gi; private GameSummary m_summary; + private boolean m_relayConnected; private CommsTransport m_xport; private Handler m_handler = null; private TimerRunnable[] m_timers; @@ -431,6 +432,8 @@ public class BoardDelegate extends DelegateBase .setNegativeButton( R.string.button_no, null ) .create(); break; + case DLG_NOINVITE: + Assert.assertFalse( m_relayConnected ); case DLG_INVITE: lstnr = new OnClickListener() { public void onClick( DialogInterface dialog, @@ -472,15 +475,18 @@ public class BoardDelegate extends DelegateBase protected void prepareDialog( DlgID dlgID, Dialog dialog ) { switch( dlgID ) { - case DLG_INVITE: // here + case DLG_INVITE: + case DLG_NOINVITE: AlertDialog ad = (AlertDialog)dialog; String message; - int titleID; - boolean rematch = m_summary.hasRematchInfo(); - if ( rematch ) { - titleID = R.string.info_title; + int titleID = R.string.info_title;; + boolean nukeButton = false; + if ( m_summary.hasRematchInfo() ) { message = getString( R.string.rematch_msg ); - ad.getButton( AlertDialog.BUTTON_POSITIVE ).setVisibility( View.GONE ); + nukeButton = true; + } else if ( DlgID.DLG_NOINVITE == dlgID ) { + message = getString( R.string.no_relay_conn ); + nukeButton = true; } else { titleID = R.string.waiting_title; message = getQuantityString( R.plurals.invite_msg_fmt, m_nMissing, m_nMissing ); @@ -500,6 +506,9 @@ public class BoardDelegate extends DelegateBase message += "\n\n" + getString( R.string.invite_stays ); } + if ( nukeButton ) { + ad.getButton( AlertDialog.BUTTON_POSITIVE ).setVisibility( View.GONE ); + } ad.setMessage( message ); ad.setTitle( titleID ); break; @@ -649,8 +658,12 @@ public class BoardDelegate extends DelegateBase // in case of change... setBackgroundColor(); setKeepScreenOn(); - } else if ( 0 < m_nMissing && ! isFinishing() ) { - showDialog( DlgID.DLG_INVITE ); + } else if ( ! isFinishing() ) { + if ( !m_relayConnected ) { + showDialog( DlgID.DLG_NOINVITE ); + } else if ( 0 < m_nMissing ) { + showDialog( DlgID.DLG_INVITE ); + } } } } @@ -1356,9 +1369,7 @@ public class BoardDelegate extends DelegateBase { DbgUtils.logf( "BoardDelegate.handleConndMessage(): nMissing = %d", nMissing ); - if ( 0 == nMissing ) { - dismissInviteAlert(); - } + dismissInviteAlerts( nMissing, true ); int naMsg = 0; int naKey = 0; @@ -1708,17 +1719,16 @@ public class BoardDelegate extends DelegateBase m_nGuestDevs = nDevs; // If we might have put up an alert earlier, take it down - if ( 0 < m_nMissing && m_nMissing != nMissing ) { - dismissInviteAlert(); - } + dismissInviteAlerts( nMissing, m_relayConnected ); m_nMissing = nMissing; // will be 0 unless isServer is true - Action action = null; + final DlgID dlgID = + m_relayConnected ? DlgID.DLG_INVITE : DlgID.DLG_NOINVITE; if ( 0 < nMissing && isServer && !m_haveInvited ) { post( new Runnable() { public void run() { - showDialog( DlgID.DLG_INVITE ); + showDialog( dlgID ); } } ); } @@ -1869,6 +1879,7 @@ public class BoardDelegate extends DelegateBase String langName = m_gi.langName(); m_summary = DBUtils.getSummary( m_activity, m_gameLock ); + m_relayConnected = !m_summary.relayConnectPending(); setThis( this ); @@ -2018,14 +2029,17 @@ public class BoardDelegate extends DelegateBase } } - private void dismissInviteAlert() + private void dismissInviteAlerts( final int nMissing, final boolean connected ) { - post( new Runnable() { + runOnUiThread( new Runnable() { public void run() { - try { - dismissDialog( DlgID.DLG_INVITE ); - } catch ( Exception ex ) { + if ( !m_relayConnected && connected ) { + m_relayConnected = true; + dismissDialog( DlgID.DLG_NOINVITE ); } + if ( 0 == nMissing ) { + dismissDialog( DlgID.DLG_INVITE ); + } } } ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgID.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgID.java index 6de9d61a7..2775ae4b1 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgID.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgID.java @@ -35,6 +35,7 @@ public enum DlgID { , DLG_DELETED , DLG_DICTGONE , DLG_INVITE + , DLG_NOINVITE , DLG_OKONLY , ENABLE_NFC , FORCE_REMOTE diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java index 3ca64f7df..b08917acd 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java @@ -1475,7 +1475,7 @@ public class GamesListDelegate extends ListDelegateBase break; case R.id.games_game_copy: final GameSummary smry = DBUtils.getSummary( m_activity, selRowIDs[0] ); - if ( smry.inNetworkGame() ) { + if ( smry.inRelayGame() ) { showOKOnlyDialog( R.string.no_copy_network ); } else { dropSels = true; // will select the new game instead diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java index 49f73cd79..2eb5f457a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java @@ -102,7 +102,7 @@ public class GameSummary { return m_context; } - public boolean inNetworkGame() + public boolean inRelayGame() { return null != relayID; } @@ -242,6 +242,13 @@ public class GameSummary { return result; } + public boolean relayConnectPending() + { + boolean result = conTypes.contains( CommsConnType.COMMS_CONN_RELAY ) + && (null == relayID || 0 == relayID.length()); + return result; + } + public boolean isMultiGame() { return ( serverRole != DeviceRole.SERVER_STANDALONE );