From eb1b61d8bfd1a59af2e4f2ac194d15ed69791a8e Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 19 Sep 2019 13:19:54 +0300 Subject: [PATCH] Add check if pref was set for app mode --- OsmAnd/src/net/osmand/plus/OsmandSettings.java | 15 ++++++++++----- .../settings/GeneralProfileSettingsFragment.java | 13 +++++++++---- .../ChangeGeneralProfilesPrefBottomSheet.java | 16 +++++++--------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 9f30a7bd2e..aeb39499ee 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -81,6 +81,8 @@ public class OsmandSettings { void removeListener(StateChangedListener listener); boolean isSet(); + + boolean isSetForMode(ApplicationMode m); } private abstract class PreferenceWithListener implements OsmandPreference { @@ -326,13 +328,12 @@ public class OsmandSettings { // this value string is synchronized with settings_pref.xml preference name public final OsmandPreference APPLICATION_MODE = new PreferenceWithListener() { + @Override public String getId() { return "application_mode"; } - ; - @Override public ApplicationMode get() { return currentMode; @@ -348,14 +349,15 @@ public class OsmandSettings { set(ApplicationMode.DEFAULT); } - ; - @Override public boolean isSet() { return true; } - ; + @Override + public boolean isSetForMode(ApplicationMode m) { + return true; + } @Override public boolean set(ApplicationMode val) { @@ -582,6 +584,9 @@ public class OsmandSettings { return settingsAPI.contains(getPreferences(), getId()); } + public boolean isSetForMode(ApplicationMode mode) { + return settingsAPI.contains(getProfilePreferences(mode), getId()); + } } public class BooleanPreference extends CommonPreference { diff --git a/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java index e78163f47f..5877a19a94 100644 --- a/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java @@ -279,10 +279,15 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { - FragmentManager fragmentManager = getFragmentManager(); - if (fragmentManager != null) { - ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, preference.getKey(), newValue, this, false); + OsmandSettings.OsmandPreference pref = settings.getPreference(preference.getKey()); + if (pref != null && !pref.isSetForMode(getSelectedAppMode())) { + FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, preference.getKey(), newValue, this, false); + } + return false; } - return false; + + return true; } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java index d37fe19002..447607ecac 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java @@ -41,9 +41,11 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh if (app == null || args == null || newValue == null || !args.containsKey(PREFERENCE_ID)) { return; } + final String prefId = args.getString(PREFERENCE_ID); CommonPreference pref = getPreference(prefId); - if (pref == null) { + OsmandPreference osmandPref = app.getSettings().getPreference(prefId); + if (pref == null || osmandPref == null) { return; } @@ -51,20 +53,16 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh StringBuilder builder = new StringBuilder(); final List values = ApplicationMode.values(app); - List appModesSameValue = new ArrayList<>(); + List appModesDefaultValue = new ArrayList<>(); for (int i = 0; i < values.size(); i++) { ApplicationMode mode = values.get(i); - Object modeValue = pref.getModeValue(mode); - if (modeValue instanceof Enum) { - modeValue = ((Enum) modeValue).ordinal(); - } - if (modeValue.equals(newValue)) { - appModesSameValue.add(mode); + if (!osmandPref.isSetForMode(mode)) { + appModesDefaultValue.add(mode); } } - Iterator iterator = appModesSameValue.iterator(); + Iterator iterator = appModesDefaultValue.iterator(); while (iterator.hasNext()) { builder.append(iterator.next().toHumanString(app)); builder.append(iterator.hasNext() ? ", " : '.');