start/stop relay service when pref changed; warn user when opens

relay-connected game and relay is disabled.
This commit is contained in:
Eric House 2016-06-22 07:20:23 -07:00
parent 6ef9c60cb9
commit 7d47098947
5 changed files with 37 additions and 14 deletions

View file

@ -2495,6 +2495,14 @@ public class BoardDelegate extends DelegateBase
Action.ENABLE_SMS_ASK );
}
}
if ( m_connTypes.contains( CommsConnType.COMMS_CONN_RELAY ) ) {
if ( !RelayService.relayEnabled( m_activity ) ) {
showConfirmThen( R.string.warn_relay_disabled,
R.string.button_enable_relay,
R.string.button_later,
Action.ENABLE_RELAY_DO );
}
}
}
private void trySendChats()

View file

@ -638,7 +638,7 @@ public class DelegateBase implements DlgClickNotify,
BTService.enable();
break;
case ENABLE_RELAY_DO:
RelayService.enable( m_activity );
RelayService.setEnabled( m_activity, true );
break;
default:
Assert.fail();

View file

@ -122,7 +122,6 @@ public class DlgDelegate {
ENABLE_SMS_DO,
ENABLE_BT_DO,
ENABLE_RELAY_DO,
__LAST
}
public static class ActionPair {

View file

@ -59,6 +59,7 @@ public class PrefsDelegate extends DelegateBase
R.string.key_force_radio,
R.string.key_disable_nag,
R.string.key_disable_nag_solo,
R.string.key_disable_relay,
};
private static Map<String, Integer> s_keysHash = null;
@ -226,6 +227,9 @@ public class PrefsDelegate extends DelegateBase
case R.string.key_disable_nag_solo:
NagTurnReceiver.resetNagsDisabled( m_activity );
break;
case R.string.key_disable_relay:
RelayService.enabledChanged( m_activity );
break;
default:
Assert.fail();
break;

View file

@ -80,6 +80,7 @@ public class RelayService extends XWService
UPGRADE,
INVITE,
GOT_INVITE,
STOP,
}
private static final String MSGS_ARR = "MSGS_ARR";
@ -162,8 +163,18 @@ public class RelayService extends XWService
return enabled;
}
public static void enable( Context context ) {
XWPrefs.setPrefsBoolean( context, R.string.key_disable_relay, false );
public static void enabledChanged( Context context ) {
boolean enabled = relayEnabled( context );
if ( enabled ) {
startService( context );
} else {
stopService( context );
}
}
public static void setEnabled( Context context, boolean enabled ) {
XWPrefs.setPrefsBoolean( context, R.string.key_disable_relay, enabled );
enabledChanged( context );
}
public static void startService( Context context )
@ -173,6 +184,12 @@ public class RelayService extends XWService
context.startService( intent );
}
private static void stopService( Context context )
{
Intent intent = getIntentTo( context, MsgCmds.STOP );
context.startService( intent );
}
public static void inviteRemote( Context context, int destDevID,
String relayID, NetLaunchInfo nli )
{
@ -439,6 +456,10 @@ public class RelayService extends XWService
}
RelayReceiver.setTimer( this );
break;
case STOP:
stopThreads();
stopSelf();
break;
default:
Assert.fail();
}
@ -489,19 +510,10 @@ public class RelayService extends XWService
}
}
// private void setupNotification( long rowid )
// {
// Intent intent = GamesListDelegate.makeRowidIntent( this, rowid );
// String msg = LocUtils.getString( this, R.string.notify_body_fmt,
// GameUtils.getName( this, rowid ) );
// Utils.postNotification( this, intent, R.string.notify_title,
// msg, (int)rowid );
// }
private boolean startFetchThreadIf()
{
// DbgUtils.logf( "startFetchThreadIf()" );
boolean handled = !XWApp.UDP_ENABLED;
boolean handled = relayEnabled( this ) && !XWApp.UDP_ENABLED;
if ( handled && null == m_fetchThread ) {
m_fetchThread = new Thread( null, new Runnable() {
public void run() {