Skip to content

Commit

Permalink
Try to fix #21459
Browse files Browse the repository at this point in the history
  • Loading branch information
Chumva committed Dec 19, 2024
1 parent 7660caf commit 42d99d2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit 42d99d2

Please sign in to comment.