Profile dependent preferences migration improvements

This commit is contained in:
Chumva 2019-11-15 10:06:28 +02:00
parent 73fee0b0bd
commit ff7ab9bc2d
2 changed files with 10 additions and 4 deletions

View file

@ -174,7 +174,7 @@ public class AppInitializer implements IProgress {
firstTime = true;
startPrefs.edit().putBoolean(FIRST_TIME_APP_RUN, true).commit();
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_2).commit();
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_5).commit();
} else if (!Version.getFullVersion(app).equals(startPrefs.getString(VERSION_INSTALLED, ""))) {
prevAppVersion = startPrefs.getInt(VERSION_INSTALLED_NUMBER, 0);
if(prevAppVersion < VERSION_2_2) {
@ -188,7 +188,7 @@ public class AppInitializer implements IProgress {
} else if (prevAppVersion < VERSION_3_2) {
app.getSettings().BILLING_PURCHASE_TOKENS_SENT.set("");
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_2).commit();
} else if (prevAppVersion < VERSION_3_5) {
} else if (prevAppVersion < VERSION_3_5 || Version.getAppVersion(app).equals("3.5.3")) {
app.getSettings().migrateGlobalPrefsToProfile();
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_5).commit();
}

View file

@ -236,8 +236,14 @@ public class OsmandSettings {
OsmandPreference pref = getPreference(key);
if (pref instanceof CommonPreference) {
CommonPreference commonPreference = (CommonPreference) pref;
if (!commonPreference.global && !commonPreference.isSetForMode(ApplicationMode.DEFAULT)) {
boolean valueSaved = setPreference(key, map.get(key), ApplicationMode.DEFAULT);
if (!commonPreference.global) {
List<ApplicationMode> modes = commonPreference.general ? Collections.singletonList(ApplicationMode.DEFAULT) : ApplicationMode.allPossibleValues();
boolean valueSaved = false;
for (ApplicationMode mode : modes) {
if (!commonPreference.isSetForMode(mode)) {
valueSaved = setPreference(key, map.get(key), mode) || valueSaved;
}
}
if (valueSaved) {
settingsAPI.edit(globalPreferences).remove(key).commit();
}