From 46c4cc06697c55bf72306e621f5b1fe9d7a52ca0 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sat, 31 Jan 2015 23:17:13 -0800 Subject: [PATCH] warn when user disables all communication options in prefs --- xwords4/android/XWords4/archive/R.java | 1 + .../android/XWords4/res/values/strings.xml | 4 ++ .../XWords4/res_src/values-ba_CK/strings.xml | 3 ++ .../XWords4/res_src/values-ca_PS/strings.xml | 3 ++ .../android/xw4/ConnViaViewLayout.java | 26 +++++++---- .../android/xw4/GameConfigDelegate.java | 31 +++++++------ .../android/xw4/GamesListDelegate.java | 26 ++++++++--- .../android/xw4/XWConnAddrPreference.java | 46 +++++++++++-------- 8 files changed, 90 insertions(+), 50 deletions(-) diff --git a/xwords4/android/XWords4/archive/R.java b/xwords4/android/XWords4/archive/R.java index 0d904354f..58db7c228 100644 --- a/xwords4/android/XWords4/archive/R.java +++ b/xwords4/android/XWords4/archive/R.java @@ -2604,6 +2604,7 @@ public final class R { line in a game summary. The \u0020 is a space in xml. */ public static final int vs_join=0x7f050123; + public static final int warn_no_comms=0x7f0502da; /** */ public static final int warn_nomobile_fmt=0x7f05021f; diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 2c4f8bbed..9e6f3bf14 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -2297,4 +2297,8 @@ Please turn Bluetooth on before enabling. Please check \"Allow games via SMS\" before enabling. + + If you have no default connection + options every new networked game will have to be configured + manually. 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 84c19baa1..5418037fd 100644 --- a/xwords4/android/XWords4/res_src/values-ba_CK/strings.xml +++ b/xwords4/android/XWords4/res_src/values-ba_CK/strings.xml @@ -1951,4 +1951,7 @@ emag si nepo. Esaelp nrut Htooteulb no erofeb gnilbane. Esaelp kcehc \"Wolla semag aiv SMS\" erofeb gnilbane. + Fi uoy evah on tluafed noitcennoc + snoitpo yreve wen dekrowten emag lliw evah ot eb derugifnoc + yllaunam. 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 12e5e4016..d451b9c12 100644 --- a/xwords4/android/XWords4/res_src/values-ca_PS/strings.xml +++ b/xwords4/android/XWords4/res_src/values-ca_PS/strings.xml @@ -1951,4 +1951,7 @@ GAME IS OPEN. PLEASE TURN BLUETOOTH ON BEFORE ENABLING. PLEASE CHECK \"ALLOW GAMES VIA SMS\" BEFORE ENABLING. + IF YOU HAVE NO DEFAULT CONNECTION + OPTIONS EVERY NEW NETWORKED GAME WILL HAVE TO BE CONFIGURED + MANUALLY. diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ConnViaViewLayout.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ConnViaViewLayout.java index 1b371a158..8cef607cb 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ConnViaViewLayout.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ConnViaViewLayout.java @@ -40,21 +40,26 @@ public class ConnViaViewLayout extends LinearLayout { public interface CheckEnabledWarner { public void warnDisabled( CommsConnType typ ); } - private CheckEnabledWarner m_warner; + public interface SetEmptyWarner { + public void typeSetEmpty(); + } + + private CheckEnabledWarner m_disabledWarner; + private SetEmptyWarner m_emptyWarner; public ConnViaViewLayout( Context context, AttributeSet as ) { super( context, as ); } - protected void setWarner( CheckEnabledWarner warner ) - { - m_warner = warner; - } - - protected void setTypes( CommsConnTypeSet types ) + protected void configure( CommsConnTypeSet types, + CheckEnabledWarner cew, + SetEmptyWarner sew ) { m_curSet = (CommsConnTypeSet)types.clone(); addConnections(); + + m_disabledWarner = cew; + m_emptyWarner = sew; } protected CommsConnTypeSet getTypes() @@ -88,6 +93,9 @@ public class ConnViaViewLayout extends LinearLayout { } } else { m_curSet.remove( typf ); + if ( null != m_emptyWarner && 0 == m_curSet.size()) { + m_emptyWarner.typeSetEmpty(); + } } } } ); @@ -106,8 +114,8 @@ public class ConnViaViewLayout extends LinearLayout { result = BTService.BTEnabled(); } - if ( !result && null != m_warner ) { - m_warner.warnDisabled( typ ); + if ( !result && null != m_disabledWarner ) { + m_disabledWarner.warnDisabled( typ ); } return result; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java index 668deb058..9783c8135 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java @@ -282,21 +282,22 @@ public class GameConfigDelegate extends DelegateBase LinearLayout layout = (LinearLayout)inflate( R.layout.conn_types_display ); final ConnViaViewLayout items = (ConnViaViewLayout) layout.findViewById( R.id.conn_types ); - items.setTypes( m_conTypes ); - items.setWarner( new ConnViaViewLayout.CheckEnabledWarner() { - public void warnDisabled( CommsConnType typ ) { - switch( typ ) { - case COMMS_CONN_SMS: - showConfirmThen( R.string.warn_sms_disabled, - R.string.button_go_settings, - Action.SMS_CONFIG_ACTION ); - break; - case COMMS_CONN_BT: - showOKOnlyDialog( R.string.enable_bt_first ); - break; - } - } - }); + items.configure( m_conTypes, + new ConnViaViewLayout.CheckEnabledWarner() { + public void warnDisabled( CommsConnType typ ) { + switch( typ ) { + case COMMS_CONN_SMS: + showConfirmThen( R.string.warn_sms_disabled, + R.string.button_go_settings, + Action.SMS_CONFIG_ACTION ); + break; + case COMMS_CONN_BT: + showOKOnlyDialog( R.string.enable_bt_first ); + break; + } + } + public void typeSetEmpty() {} + }, null ); final DialogInterface.OnClickListener lstnr = new DialogInterface.OnClickListener() { 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 39c723f88..734600ee2 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java @@ -1142,7 +1142,7 @@ public class GamesListDelegate extends ListDelegateBase break; case NEW_GAME_PRESSED: - showDialog( DlgID.GAMES_LIST_NEWGAME ); + handleNewGame( m_nextIsSolo ); break; case DELETE_GROUPS: @@ -1330,12 +1330,10 @@ public class GamesListDelegate extends ListDelegateBase GameUtils.resendAllIf( m_activity, null, true ); break; case R.id.games_menu_newgame_solo: - m_nextIsSolo = true; - showDialog( DlgID.GAMES_LIST_NEWGAME ); + handleNewGame( true ); break; case R.id.games_menu_newgame_net: - m_nextIsSolo = false; - showDialog( DlgID.GAMES_LIST_NEWGAME ); + handleNewGame( false ); break; case R.id.games_menu_newgroup: @@ -1565,6 +1563,22 @@ public class GamesListDelegate extends ListDelegateBase } } + private void handleNewGame( boolean solo ) + { + m_nextIsSolo = solo; + // force config if we don't have at least one way to communicate + boolean skipDefaults = !solo; + if ( skipDefaults ) { + skipDefaults = 0 == XWPrefs.getAddrTypes( m_activity ).size(); + } + + if ( skipDefaults ) { + makeThenLaunchOrConfigure( true ); + } else { + showDialog( DlgID.GAMES_LIST_NEWGAME ); + } + } + private void handleNewGameButton( boolean solo ) { m_nextIsSolo = solo; @@ -1572,7 +1586,7 @@ public class GamesListDelegate extends ListDelegateBase int count = m_adapter.getCount(); boolean skipOffer = 6 > count || XWPrefs.getHideNewgameButtons( m_activity ); if ( skipOffer ) { - showDialog( DlgID.GAMES_LIST_NEWGAME ); + handleNewGame( solo ); } else { ActionPair pair = new ActionPair( Action.SET_HIDE_NEWGAME_BUTTONS, R.string.set_pref ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWConnAddrPreference.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWConnAddrPreference.java index 1ab582664..85ac9b6e5 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWConnAddrPreference.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWConnAddrPreference.java @@ -54,26 +54,32 @@ public class XWConnAddrPreference extends DialogPreference { { LocUtils.xlateView( m_context, view ); m_view = (ConnViaViewLayout)view.findViewById( R.id.conn_types ); - m_view.setTypes( XWPrefs.getAddrTypes( m_context ) ); - m_view.setWarner( new ConnViaViewLayout.CheckEnabledWarner() { - public void warnDisabled( CommsConnType typ ) { - int id; - switch( typ ) { - case COMMS_CONN_SMS: - id = R.string.enable_sms_first; - break; - case COMMS_CONN_BT: - id = R.string.enable_bt_first; - break; - default: - id = 0; - } - if ( 0 != id ) { - PrefsActivity activity = (PrefsActivity)m_context; - activity.showOKOnlyDialog( id ); - } - } - } ); + m_view.configure( XWPrefs.getAddrTypes( m_context ), + new ConnViaViewLayout.CheckEnabledWarner() { + public void warnDisabled( CommsConnType typ ) { + int id; + switch( typ ) { + case COMMS_CONN_SMS: + id = R.string.enable_sms_first; + break; + case COMMS_CONN_BT: + id = R.string.enable_bt_first; + break; + default: + id = 0; + } + if ( 0 != id ) { + PrefsActivity activity = (PrefsActivity)m_context; + activity.showOKOnlyDialog( id ); + } + } + }, + new ConnViaViewLayout.SetEmptyWarner() { + public void typeSetEmpty() { + PrefsActivity activity = (PrefsActivity)m_context; + activity.showOKOnlyDialog( R.string.warn_no_comms ); + } + } ); } @Override