Improve copy preferences performance
This commit is contained in:
parent
3a9a8b3bd4
commit
a8b71688ec
1 changed files with 30 additions and 16 deletions
|
@ -301,22 +301,6 @@ public class OsmandSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copyPreferencesFromProfile(ApplicationMode modeFrom, ApplicationMode modeTo) {
|
|
||||||
for (OsmandPreference pref : registeredPreferences.values()) {
|
|
||||||
if (pref instanceof CommonPreference) {
|
|
||||||
CommonPreference commonPreference = (CommonPreference) pref;
|
|
||||||
if (!commonPreference.global) {
|
|
||||||
Object copiedValue = commonPreference.getModeValue(modeFrom);
|
|
||||||
commonPreference.setModeValue(modeTo, copiedValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean resetPreferencesForProfile(ApplicationMode mode) {
|
|
||||||
return settingsAPI.edit(getProfilePreferences(mode)).clear().commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean setPreference(String key, Object value) {
|
public boolean setPreference(String key, Object value) {
|
||||||
return setPreference(key, value, APPLICATION_MODE.get());
|
return setPreference(key, value, APPLICATION_MODE.get());
|
||||||
}
|
}
|
||||||
|
@ -421,6 +405,36 @@ public class OsmandSettings {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean copyPreferencesFromProfile(ApplicationMode modeFrom, ApplicationMode modeTo) {
|
||||||
|
SettingsEditor settingsEditor = settingsAPI.edit(getProfilePreferences(modeTo));
|
||||||
|
for (OsmandPreference pref : registeredPreferences.values()) {
|
||||||
|
if (pref instanceof CommonPreference && !((CommonPreference) pref).global) {
|
||||||
|
CommonPreference profilePref = (CommonPreference) pref;
|
||||||
|
if (!profilePref.isSetForMode(modeFrom)) {
|
||||||
|
settingsEditor.remove(pref.getId());
|
||||||
|
} else {
|
||||||
|
Object copiedValue = profilePref.getModeValue(modeFrom);
|
||||||
|
if (copiedValue instanceof String) {
|
||||||
|
settingsEditor.putString(pref.getId(), (String) copiedValue);
|
||||||
|
} else if (copiedValue instanceof Boolean) {
|
||||||
|
settingsEditor.putBoolean(pref.getId(), (Boolean) copiedValue);
|
||||||
|
} else if (copiedValue instanceof Float) {
|
||||||
|
settingsEditor.putFloat(pref.getId(), (Float) copiedValue);
|
||||||
|
} else if (copiedValue instanceof Integer) {
|
||||||
|
settingsEditor.putInt(pref.getId(), (Integer) copiedValue);
|
||||||
|
} else if (copiedValue instanceof Long) {
|
||||||
|
settingsEditor.putLong(pref.getId(), (Long) copiedValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return settingsEditor.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean resetPreferencesForProfile(ApplicationMode mode) {
|
||||||
|
return settingsAPI.edit(getProfilePreferences(mode)).clear().commit();
|
||||||
|
}
|
||||||
|
|
||||||
public ApplicationMode LAST_ROUTING_APPLICATION_MODE = null;
|
public ApplicationMode LAST_ROUTING_APPLICATION_MODE = null;
|
||||||
|
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
|
|
Loading…
Reference in a new issue