From e0fd2a9dfd322b5362f7edbda424d292c0d03802 Mon Sep 17 00:00:00 2001 From: 0xRe1nk0 <0xre1nk0@gmail.com> Date: Wed, 27 Nov 2024 10:21:10 +0200 Subject: [PATCH 1/2] Volume unit behavior as units of length --- OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index 812b7b47904..e8e726e8c08 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -1047,6 +1047,7 @@ public boolean setValue(Object prefs, DrivingRegion val) { boolean overrideMetricSystem = !DRIVING_REGION_AUTOMATIC.getValue(prefs, DRIVING_REGION_AUTOMATIC.getDefaultValue()); if (overrideMetricSystem && val != null) { METRIC_SYSTEM.setValue(prefs, val.defMetrics); + UNIT_OF_VOLUME.set(val.volumeUnit); } return super.setValue(prefs, val); } From 42d99d27bd97ca1260dcce783382311a429e897d Mon Sep 17 00:00:00 2001 From: chumv Date: Fri, 20 Dec 2024 00:39:53 +0200 Subject: [PATCH 2/2] Try to fix #21459 --- .../plus/settings/backend/OsmandSettings.java | 1 - .../backend/preferences/CommonPreference.java | 42 ++++++++++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index f2a0733405e..4ee64f2a873 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -1051,7 +1051,6 @@ public boolean setValue(Object prefs, DrivingRegion val) { boolean overrideMetricSystem = !DRIVING_REGION_AUTOMATIC.getValue(prefs, DRIVING_REGION_AUTOMATIC.getDefaultValue()); if (overrideMetricSystem && val != null) { METRIC_SYSTEM.setValue(prefs, val.defMetrics); - UNIT_OF_VOLUME.set(val.volumeUnit); } return super.setValue(prefs, val); } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/preferences/CommonPreference.java b/OsmAnd/src/net/osmand/plus/settings/backend/preferences/CommonPreference.java index c30b4e8239b..164c1c7eab2 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/preferences/CommonPreference.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/preferences/CommonPreference.java @@ -222,17 +222,49 @@ public T get() { @Override public final void resetToDefault() { - T o = getProfileDefaultValue(getApplicationMode()); - set(o); + if (global) { + T oldValue = get(); + Object prefs = getPreferences(); + if (getSettingsAPI().edit(prefs).remove(getId()).commit()) { + T newValue = get(); + boolean changed = !Algorithms.objectEquals(oldValue, newValue); + if (changed && lastModifiedTimeStored) { + setLastModifiedTime(prefs, System.currentTimeMillis()); + } + if (changed && isShared()) { + if (PluginsHelper.isDevelopment()) { + Log.d("CommonPreference", "RESET_TO_DEFAULT id=" + getId() + + " value=" + newValue + " cached=" + cachedValue); + } + settings.updateLastPreferencesEditTime(prefs); + } + cachedValue = newValue; + cachedPreference = prefs; + fireEvent(newValue); + } + } else { + resetModeToDefault(getApplicationMode()); + } } @Override public final void resetModeToDefault(ApplicationMode mode) { if (global) { resetToDefault(); - } else { - T o = getProfileDefaultValue(mode); - setModeValue(mode, o); + } else if (mode != null) { + T oldValue = getModeValue(mode); + Object prefs = settings.getProfilePreferences(mode); + if (getSettingsAPI().edit(prefs).remove(getId()).commit()) { + T newValue = getModeValue(mode); + boolean changed = !Algorithms.objectEquals(oldValue, newValue); + if (changed) { + settings.updateLastPreferencesEditTime(prefs); + } + if (cache && cachedPreference == prefs) { + cachedValue = newValue; + } + fireEvent(newValue); + } } }