Merge pull request #7153 from osmandapp/navset_fix

nav settings mode selection fix
This commit is contained in:
Alexey 2019-07-04 17:09:24 +03:00 committed by GitHub
commit fa5f9f0ced
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 20 deletions

View file

@ -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<ApplicationMode> modes = new ArrayList<ApplicationMode>();
private ApplicationMode previousAppMode;
protected ApplicationMode selectedAppMode;
private Map<String, Preference> screenPreferences = new LinkedHashMap<String, Preference>();
private Map<String, OsmandPreference<Boolean>> booleanPreferences = new LinkedHashMap<String, OsmandPreference<Boolean>>();
@ -359,7 +362,7 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
final List<ProfileDataObject> 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) {
if (previousAppMode == null) {
previousAppMode = settings.getApplicationMode();
boolean found;
}
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
@ -476,6 +474,35 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
}
}
@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);
}
if (am.getStringKey() == state.get(PREV_MODE_KEY)) {
previousAppMode = am;
}
}
}
}
}
public void updateAllSettings() {
for (OsmandPreference<Boolean> b : booleanPreferences.values()) {

View file

@ -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"));
}