mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-09 05:24:44 +01:00
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.
This commit is contained in:
parent
82e0de6c40
commit
7190706eaf
5 changed files with 75 additions and 47 deletions
|
@ -1170,6 +1170,7 @@
|
||||||
it immediately because an email or messaging app will be
|
it immediately because an email or messaging app will be
|
||||||
launched to send your invitation. -->
|
launched to send your invitation. -->
|
||||||
<string name="newgame_invite">Invite now</string>
|
<string name="newgame_invite">Invite now</string>
|
||||||
|
<string name="newgame_invite_anyway">Invite anyway</string>
|
||||||
|
|
||||||
<!-- section separator (white-on-gray bar) for third section:
|
<!-- section separator (white-on-gray bar) for third section:
|
||||||
bluetooth games -->
|
bluetooth games -->
|
||||||
|
@ -2466,11 +2467,15 @@
|
||||||
<string name="seeking_relay">Connecting to relay…</string>
|
<string name="seeking_relay">Connecting to relay…</string>
|
||||||
|
|
||||||
<string name="no_relay_conn">This game is configured to use the
|
<string name="no_relay_conn">This game is configured to use the
|
||||||
relay for communication but has been unable to connect, either
|
relay (server) for communication but has been unable to connect,
|
||||||
because of problems with your device\'s internet connection or
|
either because of problems with your device\'s internet connection
|
||||||
because the relay is not running.\n\nPlease try opening the game
|
or because the relay is not running.\n\nPlease try opening the game
|
||||||
again later after conditions have changed.</string>
|
again later after conditions have changed.</string>
|
||||||
|
|
||||||
|
<string name="skip_relay_warning">(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.)</string>
|
||||||
|
|
||||||
<string name="wifi_warning">\u0020For example, you may need to be on
|
<string name="wifi_warning">\u0020For example, you may need to be on
|
||||||
a different WiFi network.</string>
|
a different WiFi network.</string>
|
||||||
|
|
||||||
|
|
|
@ -432,8 +432,6 @@ public class BoardDelegate extends DelegateBase
|
||||||
.setNegativeButton( R.string.button_no, null )
|
.setNegativeButton( R.string.button_no, null )
|
||||||
.create();
|
.create();
|
||||||
break;
|
break;
|
||||||
case DLG_NOINVITE:
|
|
||||||
Assert.assertFalse( m_relayConnected );
|
|
||||||
case DLG_INVITE:
|
case DLG_INVITE:
|
||||||
lstnr = new OnClickListener() {
|
lstnr = new OnClickListener() {
|
||||||
public void onClick( DialogInterface dialog,
|
public void onClick( DialogInterface dialog,
|
||||||
|
@ -449,7 +447,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
};
|
};
|
||||||
dialog = ab.setTitle( "foo" )
|
dialog = ab.setTitle( "foo" )
|
||||||
.setMessage( "" )
|
.setMessage( "" )
|
||||||
.setPositiveButton( R.string.newgame_invite, lstnr )
|
.setPositiveButton( "", lstnr )
|
||||||
.setNegativeButton( R.string.button_close_game, lstnr2 )
|
.setNegativeButton( R.string.button_close_game, lstnr2 )
|
||||||
.setOnCancelListener( new OnCancelListener() {
|
.setOnCancelListener( new OnCancelListener() {
|
||||||
public void onCancel( DialogInterface dialog ) {
|
public void onCancel( DialogInterface dialog ) {
|
||||||
|
@ -476,48 +474,60 @@ public class BoardDelegate extends DelegateBase
|
||||||
{
|
{
|
||||||
switch( dlgID ) {
|
switch( dlgID ) {
|
||||||
case DLG_INVITE:
|
case DLG_INVITE:
|
||||||
case DLG_NOINVITE:
|
|
||||||
AlertDialog ad = (AlertDialog)dialog;
|
AlertDialog ad = (AlertDialog)dialog;
|
||||||
String message;
|
String message;
|
||||||
int titleID;
|
int titleID;
|
||||||
boolean nukeButton = false;
|
boolean nukeButton = false;
|
||||||
|
int buttonTxt = R.string.newgame_invite;
|
||||||
if ( m_summary.hasRematchInfo() ) {
|
if ( m_summary.hasRematchInfo() ) {
|
||||||
titleID = R.string.info_title;;
|
titleID = R.string.info_title;;
|
||||||
message = getString( R.string.rematch_msg );
|
message = getString( R.string.rematch_msg );
|
||||||
nukeButton = true;
|
nukeButton = true;
|
||||||
} else if ( DlgID.DLG_NOINVITE == dlgID ) {
|
} else {
|
||||||
titleID = R.string.seeking_relay;
|
if ( !m_relayConnected ) {
|
||||||
message = getString( R.string.no_relay_conn );
|
titleID = R.string.seeking_relay;
|
||||||
if ( NetStateCache.netAvail( m_activity )
|
// If relay is only means, don't allow at all
|
||||||
&& NetStateCache.onWifi() ) {
|
boolean relayOnly = 1 >= m_connTypes.size();
|
||||||
message += getString( R.string.wifi_warning );
|
nukeButton = relayOnly;
|
||||||
}
|
message = getString( R.string.no_relay_conn );
|
||||||
nukeButton = true;
|
if ( NetStateCache.netAvail( m_activity )
|
||||||
} else {
|
&& NetStateCache.onWifi() ) {
|
||||||
titleID = R.string.waiting_title;
|
message += getString( R.string.wifi_warning );
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
}
|
if ( !relayOnly ) {
|
||||||
if ( null != ps ) {
|
message += "\n\n" + getString( R.string.skip_relay_warning );
|
||||||
message += "\n\n" + ps;
|
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 );
|
String ps = null;
|
||||||
}
|
if ( m_nMissing > 1 ) {
|
||||||
if ( nukeButton ) {
|
ps = getString( R.string.invite_multiple );
|
||||||
ad.getButton( AlertDialog.BUTTON_POSITIVE ).setVisibility( View.GONE );
|
} 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.setMessage( message );
|
||||||
ad.setTitle( titleID );
|
ad.setTitle( titleID );
|
||||||
|
|
||||||
|
Button posButton = ad.getButton( AlertDialog.BUTTON_POSITIVE );
|
||||||
|
posButton.setVisibility( nukeButton ? View.GONE : View.VISIBLE );
|
||||||
|
if ( !nukeButton ) {
|
||||||
|
posButton.setText( buttonTxt );
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
super.prepareDialog( dlgID, dialog );
|
super.prepareDialog( dlgID, dialog );
|
||||||
|
@ -666,9 +676,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
setBackgroundColor();
|
setBackgroundColor();
|
||||||
setKeepScreenOn();
|
setKeepScreenOn();
|
||||||
} else if ( ! isFinishing() ) {
|
} else if ( ! isFinishing() ) {
|
||||||
if ( !m_relayConnected ) {
|
if ( !m_relayConnected || 0 < m_nMissing ) {
|
||||||
showDialog( DlgID.DLG_NOINVITE );
|
|
||||||
} else if ( 0 < m_nMissing ) {
|
|
||||||
showDialog( DlgID.DLG_INVITE );
|
showDialog( DlgID.DLG_INVITE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1034,6 +1042,9 @@ public class BoardDelegate extends DelegateBase
|
||||||
case EMAIL:
|
case EMAIL:
|
||||||
NetLaunchInfo nli = new NetLaunchInfo( m_summary, m_gi, 1,
|
NetLaunchInfo nli = new NetLaunchInfo( m_summary, m_gi, 1,
|
||||||
1 + m_nGuestDevs );
|
1 + m_nGuestDevs );
|
||||||
|
if ( !m_relayConnected ) {
|
||||||
|
nli.removeAddress( CommsConnType.COMMS_CONN_RELAY );
|
||||||
|
}
|
||||||
GameUtils.launchEmailInviteActivity( m_activity, nli );
|
GameUtils.launchEmailInviteActivity( m_activity, nli );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -1376,7 +1387,7 @@ public class BoardDelegate extends DelegateBase
|
||||||
{
|
{
|
||||||
DbgUtils.logf( "BoardDelegate.handleConndMessage(): nMissing = %d", nMissing );
|
DbgUtils.logf( "BoardDelegate.handleConndMessage(): nMissing = %d", nMissing );
|
||||||
|
|
||||||
dismissInviteAlerts( nMissing, true );
|
dismissInviteAlert( nMissing, true );
|
||||||
|
|
||||||
int naMsg = 0;
|
int naMsg = 0;
|
||||||
int naKey = 0;
|
int naKey = 0;
|
||||||
|
@ -1726,16 +1737,14 @@ public class BoardDelegate extends DelegateBase
|
||||||
m_nGuestDevs = nDevs;
|
m_nGuestDevs = nDevs;
|
||||||
|
|
||||||
// If we might have put up an alert earlier, take it down
|
// 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
|
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 ) {
|
if ( 0 < nMissing && isServer && !m_haveInvited ) {
|
||||||
post( new Runnable() {
|
post( new Runnable() {
|
||||||
public void run() {
|
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() {
|
runOnUiThread( new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if ( !m_relayConnected && connected ) {
|
if ( !m_relayConnected && connected ) {
|
||||||
m_relayConnected = true;
|
m_relayConnected = true;
|
||||||
dismissDialog( DlgID.DLG_NOINVITE );
|
|
||||||
}
|
}
|
||||||
if ( 0 == nMissing ) {
|
if ( 0 == nMissing || m_relayConnected ) {
|
||||||
dismissDialog( DlgID.DLG_INVITE );
|
dismissDialog( DlgID.DLG_INVITE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2285,6 +2293,10 @@ public class BoardDelegate extends DelegateBase
|
||||||
int forceChannel = ii + m_nGuestDevs + 1;
|
int forceChannel = ii + m_nGuestDevs + 1;
|
||||||
NetLaunchInfo nli = new NetLaunchInfo( m_summary, m_gi,
|
NetLaunchInfo nli = new NetLaunchInfo( m_summary, m_gi,
|
||||||
nPlayers, forceChannel );
|
nPlayers, forceChannel );
|
||||||
|
if ( !m_relayConnected ) {
|
||||||
|
nli.removeAddress( CommsConnType.COMMS_CONN_RELAY );
|
||||||
|
}
|
||||||
|
|
||||||
switch ( m_missingMeans ) {
|
switch ( m_missingMeans ) {
|
||||||
case BLUETOOTH:
|
case BLUETOOTH:
|
||||||
if ( ! m_progressShown ) {
|
if ( ! m_progressShown ) {
|
||||||
|
|
|
@ -35,7 +35,6 @@ public enum DlgID {
|
||||||
, DLG_DELETED
|
, DLG_DELETED
|
||||||
, DLG_DICTGONE
|
, DLG_DICTGONE
|
||||||
, DLG_INVITE
|
, DLG_INVITE
|
||||||
, DLG_NOINVITE
|
|
||||||
, DLG_OKONLY
|
, DLG_OKONLY
|
||||||
, ENABLE_NFC
|
, ENABLE_NFC
|
||||||
, FORCE_REMOTE
|
, FORCE_REMOTE
|
||||||
|
|
|
@ -258,6 +258,11 @@ public class NetLaunchInfo {
|
||||||
return m_addrs.contains( typ );
|
return m_addrs.contains( typ );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeAddress( CommsConnType typ )
|
||||||
|
{
|
||||||
|
m_addrs.remove( typ );
|
||||||
|
}
|
||||||
|
|
||||||
public String inviteID()
|
public String inviteID()
|
||||||
{
|
{
|
||||||
String result = m_inviteID;
|
String result = m_inviteID;
|
||||||
|
|
|
@ -246,6 +246,13 @@ public class GameSummary {
|
||||||
{
|
{
|
||||||
boolean result = conTypes.contains( CommsConnType.COMMS_CONN_RELAY )
|
boolean result = conTypes.contains( CommsConnType.COMMS_CONN_RELAY )
|
||||||
&& (null == relayID || 0 == relayID.length());
|
&& (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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue