From 7190706eaf65d5b5c4db579cd47b9ae8e43514f8 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sat, 13 Jun 2015 07:35:02 -0700 Subject: [PATCH] when game doesn't have connection to relay but has another way to connect, give user the option of inviting "anyway", but warn that there will be no relay connection used in that game. And then remove the relay addressing from the invitation info. --- .../android/XWords4/res/values/strings.xml | 11 ++- .../eehouse/android/xw4/BoardDelegate.java | 98 +++++++++++-------- .../src/org/eehouse/android/xw4/DlgID.java | 1 - .../eehouse/android/xw4/NetLaunchInfo.java | 5 + .../eehouse/android/xw4/jni/GameSummary.java | 7 ++ 5 files changed, 75 insertions(+), 47 deletions(-) diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index ede5633e4..fdfce9d5e 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -1170,6 +1170,7 @@ it immediately because an email or messaging app will be launched to send your invitation. --> Invite now + Invite anyway @@ -2466,11 +2467,15 @@ Connecting to relay… 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 + relay (server) 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 after conditions have changed. + (Because this game has other ways + of communicating, you can invite even without a relay connection, + but they you\'ll have to play the game without it.) + \u0020For example, you may need to be on a different WiFi network. 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 3589154d5..e3bb34bf0 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java @@ -432,8 +432,6 @@ 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, @@ -449,7 +447,7 @@ public class BoardDelegate extends DelegateBase }; dialog = ab.setTitle( "foo" ) .setMessage( "" ) - .setPositiveButton( R.string.newgame_invite, lstnr ) + .setPositiveButton( "", lstnr ) .setNegativeButton( R.string.button_close_game, lstnr2 ) .setOnCancelListener( new OnCancelListener() { public void onCancel( DialogInterface dialog ) { @@ -476,48 +474,60 @@ public class BoardDelegate extends DelegateBase { switch( dlgID ) { case DLG_INVITE: - case DLG_NOINVITE: AlertDialog ad = (AlertDialog)dialog; String message; int titleID; boolean nukeButton = false; + int buttonTxt = R.string.newgame_invite; if ( m_summary.hasRematchInfo() ) { titleID = R.string.info_title;; message = getString( R.string.rematch_msg ); nukeButton = true; - } else if ( DlgID.DLG_NOINVITE == dlgID ) { - titleID = R.string.seeking_relay; - message = getString( R.string.no_relay_conn ); - if ( NetStateCache.netAvail( m_activity ) - && NetStateCache.onWifi() ) { - message += getString( R.string.wifi_warning ); - } - nukeButton = true; - } else { - titleID = R.string.waiting_title; - message = getQuantityString( R.plurals.invite_msg_fmt, - m_nMissing, m_nMissing ); - - String ps = null; - if ( m_nMissing > 1 ) { - ps = getString( R.string.invite_multiple ); - } else { - boolean[] avail = NFCUtils.nfcAvail( m_activity ); - if ( avail[1] ) { - ps = getString( R.string.invite_if_nfc ); + } else { + if ( !m_relayConnected ) { + titleID = R.string.seeking_relay; + // If relay is only means, don't allow at all + boolean relayOnly = 1 >= m_connTypes.size(); + nukeButton = relayOnly; + message = getString( R.string.no_relay_conn ); + if ( NetStateCache.netAvail( m_activity ) + && NetStateCache.onWifi() ) { + message += getString( R.string.wifi_warning ); } - } - if ( null != ps ) { - message += "\n\n" + ps; - } + if ( !relayOnly ) { + message += "\n\n" + getString( R.string.skip_relay_warning ); + buttonTxt = R.string.newgame_invite_anyway; + } + } else { + titleID = R.string.waiting_title; + message = getQuantityString( R.plurals.invite_msg_fmt, + m_nMissing, m_nMissing ); - message += "\n\n" + getString( R.string.invite_stays ); - } - if ( nukeButton ) { - ad.getButton( AlertDialog.BUTTON_POSITIVE ).setVisibility( View.GONE ); + String ps = null; + if ( m_nMissing > 1 ) { + ps = getString( R.string.invite_multiple ); + } else { + boolean[] avail = NFCUtils.nfcAvail( m_activity ); + if ( avail[1] ) { + ps = getString( R.string.invite_if_nfc ); + } + } + if ( null != ps ) { + message += "\n\n" + ps; + } + + message += "\n\n" + getString( R.string.invite_stays ); + } } + ad.setMessage( message ); ad.setTitle( titleID ); + + Button posButton = ad.getButton( AlertDialog.BUTTON_POSITIVE ); + posButton.setVisibility( nukeButton ? View.GONE : View.VISIBLE ); + if ( !nukeButton ) { + posButton.setText( buttonTxt ); + } break; default: super.prepareDialog( dlgID, dialog ); @@ -666,9 +676,7 @@ public class BoardDelegate extends DelegateBase setBackgroundColor(); setKeepScreenOn(); } else if ( ! isFinishing() ) { - if ( !m_relayConnected ) { - showDialog( DlgID.DLG_NOINVITE ); - } else if ( 0 < m_nMissing ) { + if ( !m_relayConnected || 0 < m_nMissing ) { showDialog( DlgID.DLG_INVITE ); } } @@ -1034,6 +1042,9 @@ public class BoardDelegate extends DelegateBase case EMAIL: NetLaunchInfo nli = new NetLaunchInfo( m_summary, m_gi, 1, 1 + m_nGuestDevs ); + if ( !m_relayConnected ) { + nli.removeAddress( CommsConnType.COMMS_CONN_RELAY ); + } GameUtils.launchEmailInviteActivity( m_activity, nli ); break; default: @@ -1376,7 +1387,7 @@ public class BoardDelegate extends DelegateBase { DbgUtils.logf( "BoardDelegate.handleConndMessage(): nMissing = %d", nMissing ); - dismissInviteAlerts( nMissing, true ); + dismissInviteAlert( nMissing, true ); int naMsg = 0; int naKey = 0; @@ -1726,16 +1737,14 @@ public class BoardDelegate extends DelegateBase m_nGuestDevs = nDevs; // If we might have put up an alert earlier, take it down - dismissInviteAlerts( nMissing, m_relayConnected ); + dismissInviteAlert( nMissing, m_relayConnected ); m_nMissing = nMissing; // will be 0 unless isServer is true - 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 ); + showDialog( DlgID.DLG_INVITE ); } } ); } @@ -2036,15 +2045,14 @@ public class BoardDelegate extends DelegateBase } } - private void dismissInviteAlerts( final int nMissing, final boolean connected ) + private void dismissInviteAlert( final int nMissing, final boolean connected ) { runOnUiThread( new Runnable() { public void run() { if ( !m_relayConnected && connected ) { m_relayConnected = true; - dismissDialog( DlgID.DLG_NOINVITE ); } - if ( 0 == nMissing ) { + if ( 0 == nMissing || m_relayConnected ) { dismissDialog( DlgID.DLG_INVITE ); } } @@ -2285,6 +2293,10 @@ public class BoardDelegate extends DelegateBase int forceChannel = ii + m_nGuestDevs + 1; NetLaunchInfo nli = new NetLaunchInfo( m_summary, m_gi, nPlayers, forceChannel ); + if ( !m_relayConnected ) { + nli.removeAddress( CommsConnType.COMMS_CONN_RELAY ); + } + switch ( m_missingMeans ) { case BLUETOOTH: if ( ! m_progressShown ) { 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 2775ae4b1..6de9d61a7 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgID.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgID.java @@ -35,7 +35,6 @@ 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/NetLaunchInfo.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java index 1928e371a..c1e74d866 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java @@ -258,6 +258,11 @@ public class NetLaunchInfo { return m_addrs.contains( typ ); } + public void removeAddress( CommsConnType typ ) + { + m_addrs.remove( typ ); + } + public String inviteID() { String result = m_inviteID; 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 2eb5f457a..d82e8dec0 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 @@ -246,6 +246,13 @@ public class GameSummary { { boolean result = conTypes.contains( CommsConnType.COMMS_CONN_RELAY ) && (null == relayID || 0 == relayID.length()); + if ( result ) { + // Don't report it as unconnected if a game's happening + // anyway, e.g. via BT. + result = 0 > turn && !gameOver; + } + // DbgUtils.logf( "relayConnectPending()=>%b (turn=%d)", result, + // turn ); return result; }