use of net.osmand.plus.settings.backend.backup.OsmandSettingsItemReader in project Osmand by osmandapp.
the class ProfileSettingsItem method getReader.
@Nullable
@Override
public SettingsItemReader<? extends SettingsItem> getReader() {
return new OsmandSettingsItemReader<ProfileSettingsItem>(this, getSettings()) {
@Override
protected void readPreferenceFromJson(@NonNull OsmandPreference<?> preference, @NonNull JSONObject json) throws JSONException {
if (!appModeBeanPrefsIds.contains(preference.getId())) {
preference.readFromJson(json, appMode);
}
}
@Override
public void readPreferencesFromJson(final JSONObject json) {
getSettings().getContext().runInUIThread(() -> {
OsmandSettings settings = getSettings();
Map<String, OsmandPreference<?>> prefs = settings.getRegisteredPreferences();
Iterator<String> iterator = json.keys();
while (iterator.hasNext()) {
String key = iterator.next();
OsmandPreference<?> p = prefs.get(key);
if (p == null) {
if (OsmandSettings.isRoutingPreference(key)) {
p = settings.registerStringPreference(key, "");
}
}
if (p != null) {
try {
readPreferenceFromJson(p, json);
if (OsmandSettings.isRoutingPreference(p.getId())) {
if (p.getId().endsWith(GeneralRouter.USE_SHORTEST_WAY)) {
settings.FAST_ROUTE_MODE.setModeValue(appMode, !settings.getCustomRoutingBooleanProperty(GeneralRouter.USE_SHORTEST_WAY, false).getModeValue(appMode));
}
}
} catch (Exception e) {
SettingsHelper.LOG.error("Failed to read preference: " + key, e);
}
} else {
SettingsHelper.LOG.warn("No preference while importing settings: " + key);
}
}
});
}
};
}
Aggregations