From 935d74df612c4893003479fb6420865e21077e44 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Thu, 4 Jul 2019 16:09:42 +0300 Subject: [PATCH 1/3] nav settings mode selection fix --- .../plus/activities/SettingsBaseActivity.java | 58 ++++++++++++++----- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java index 49440a21bd..d863c903b3 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java @@ -46,11 +46,14 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity private static final Log LOG = PlatformUtil.getLog(SettingsBaseActivity.class); public static final String INTENT_APP_MODE = "INTENT_APP_MODE"; - + private static final String PREV_MODE_KEY = "previous_mode"; + private static final String SELECTED_MODE_KEY = "selected_mode"; + protected OsmandSettings settings; protected final boolean profileSettings; protected List modes = new ArrayList(); private ApplicationMode previousAppMode; + protected ApplicationMode selectedAppMode; private Map screenPreferences = new LinkedHashMap(); private Map> booleanPreferences = new LinkedHashMap>(); @@ -359,7 +362,7 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity final List activeModes = new ArrayList<>(); for (ApplicationMode am : ApplicationMode.values(getMyApplication())) { boolean isSelected = false; - if (previousAppMode != null && previousAppMode == am) { + if (am == selectedAppMode) { isSelected = true; } if (am != ApplicationMode.DEFAULT) { @@ -411,7 +414,7 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity getModeTitleTV().setText(title); getModeSubTitleTV().setText(getAppModeDescription(mode)); settings.APPLICATION_MODE.set(mode); - previousAppMode = mode; + selectedAppMode = mode; getModeIconIV().setImageDrawable(getMyApplication().getUIUtilities().getIcon(mode.getIconRes(), mode.getIconColorInfo().getColor(nightMode))); getDropDownArrow().setImageDrawable(getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_arrow_drop_down, @@ -439,33 +442,28 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity protected void onResume() { super.onResume(); if (profileSettings) { - previousAppMode = settings.getApplicationMode(); - boolean found; + if (previousAppMode == null) { + previousAppMode = settings.getApplicationMode(); + } if (getIntent() != null && getIntent().hasExtra(INTENT_APP_MODE)) { String modeStr = getIntent().getStringExtra(INTENT_APP_MODE); ApplicationMode mode = ApplicationMode.valueOfStringKey(modeStr, previousAppMode); - found = setSelectedAppMode(mode); + setSelectedAppMode(mode); } else { - found = setSelectedAppMode(previousAppMode); - } - if (!found) { - getSpinner().setSelection(0); + setSelectedAppMode(selectedAppMode); } } else { updateAllSettings(); } } - protected boolean setSelectedAppMode(ApplicationMode am) { - boolean found = false; + protected void setSelectedAppMode(ApplicationMode am) { for (ApplicationMode a : modes) { - if (am == a) { + if (am != null && am == a) { updateModeButton(a); - found = true; break; } } - return found; } @Override @@ -475,7 +473,37 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity settings.APPLICATION_MODE.set(previousAppMode); } } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + if (profileSettings) { + if (previousAppMode != null) { + outState.putString(PREV_MODE_KEY, previousAppMode.getStringKey()); + } + if (selectedAppMode != null) { + outState.putString(SELECTED_MODE_KEY, selectedAppMode.getStringKey()); + } + } + } + @Override + protected void onRestoreInstanceState(Bundle state) { + super.onRestoreInstanceState(state); + if (state != null) { + if (profileSettings && state.containsKey(SELECTED_MODE_KEY) && state.containsKey(PREV_MODE_KEY)) { + for (ApplicationMode am : ApplicationMode.values(getMyApplication())) { + if (am.getStringKey() == state.get(SELECTED_MODE_KEY)) { + setSelectedAppMode(am); + isModeSelected = true; + } + if (am.getStringKey() == state.get(PREV_MODE_KEY)) { + previousAppMode = am; + } + } + } + } + } public void updateAllSettings() { for (OsmandPreference b : booleanPreferences.values()) { From af0c22d4f06b2f54db619e4d2d08f42d17f2c545 Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Thu, 4 Jul 2019 16:18:58 +0300 Subject: [PATCH 2/3] nav settings mode selection fix --- .../activities/SettingsNavigationActivity.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index b3dfe15ef2..e0e7d7860e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -85,6 +85,16 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { createUI(); } + @Override + protected void onResume() { + super.onResume(); + if(getIntent() != null && getIntent().hasExtra(INTENT_SKIP_DIALOG)) { + setSelectedAppMode(settings.getApplicationMode()); + } else if (selectedAppMode == null) { + selectAppModeDialog().show(); + } + } + private void createUI() { addPreferencesFromResource(R.xml.navigation_settings); PreferenceScreen screen = getPreferenceScreen(); @@ -181,11 +191,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { // registerListPreference(settings.DELAY_TO_START_NAVIGATION, screen, delayIntervalNames, delayIntervals); - if(getIntent() != null && getIntent().hasExtra(INTENT_SKIP_DIALOG)) { - setSelectedAppMode(settings.getApplicationMode()); - } else { - selectAppModeDialog().show(); - } + addVoicePrefs((PreferenceGroup) screen.findPreference("voice")); } From 046e40341b3c76dbab006f4f082263a81de14b5c Mon Sep 17 00:00:00 2001 From: madwasp79 Date: Thu, 4 Jul 2019 16:31:12 +0300 Subject: [PATCH 3/3] typo --- OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java index d863c903b3..a605c6a1af 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java @@ -495,7 +495,6 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity for (ApplicationMode am : ApplicationMode.values(getMyApplication())) { if (am.getStringKey() == state.get(SELECTED_MODE_KEY)) { setSelectedAppMode(am); - isModeSelected = true; } if (am.getStringKey() == state.get(PREV_MODE_KEY)) { previousAppMode = am;