Merge pull request #9503 from osmandapp/fix_9470

Fix_9470
This commit is contained in:
vshcherb 2020-07-21 17:28:40 +02:00 committed by GitHub
commit 90131d5f7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 21 deletions

View file

@ -25,9 +25,10 @@ class AppVersionUpgradeOnInit {
// Each upgrade should have independent version!
// So, we could have multiple upgrades per 1 release i.e. 3701, 3702, 3703, ... - will be for 3.7
public static final int VERSION_3_7_01 = 3701;
// 3800 - 3.8-00
public static final int VERSION_3_8_00 = 3800;
public static final int LAST_APP_VERSION = VERSION_3_7_01;
public static final int LAST_APP_VERSION = VERSION_3_8_00;
static final String VERSION_INSTALLED = "VERSION_INSTALLED";
@ -110,6 +111,10 @@ class AppVersionUpgradeOnInit {
});
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_7_01).commit();
}
if (prevAppVersion < VERSION_3_8_00) {
app.getSettings().migrateQuickActionStates();
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_8_00).commit();
}
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, lastVersion).commit();
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
appVersionChanged = true;

View file

@ -15,9 +15,6 @@ import com.google.gson.reflect.TypeToken;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.quickaction.actions.NavRemoveNextDestination;
import net.osmand.plus.quickaction.actions.ShowHideMapillaryAction;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.quickaction.actions.DayNightModeAction;
import net.osmand.plus.quickaction.actions.FavoriteAction;
@ -28,15 +25,18 @@ import net.osmand.plus.quickaction.actions.NavAddDestinationAction;
import net.osmand.plus.quickaction.actions.NavAddFirstIntermediateAction;
import net.osmand.plus.quickaction.actions.NavAutoZoomMapAction;
import net.osmand.plus.quickaction.actions.NavDirectionsFromAction;
import net.osmand.plus.quickaction.actions.NavRemoveNextDestination;
import net.osmand.plus.quickaction.actions.NavReplaceDestinationAction;
import net.osmand.plus.quickaction.actions.NavResumePauseAction;
import net.osmand.plus.quickaction.actions.NavStartStopAction;
import net.osmand.plus.quickaction.actions.NavVoiceAction;
import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction;
import net.osmand.plus.quickaction.actions.ShowHideGpxTracksAction;
import net.osmand.plus.quickaction.actions.ShowHideMapillaryAction;
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
import net.osmand.plus.quickaction.actions.ShowHideTransportLinesAction;
import net.osmand.plus.quickaction.actions.SwitchProfileAction;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.util.Algorithms;
import java.lang.reflect.Type;
@ -70,7 +70,6 @@ public class QuickActionRegistry {
private final OsmandSettings settings;
private List<QuickAction> quickActions;
private final Map<String, Boolean> fabStateMap;
private final Gson gson;
private List<QuickActionType> quickActionTypes = new ArrayList<>();
private Map<Integer, QuickActionType> quickActionTypesInt = new TreeMap<>();
@ -81,7 +80,6 @@ public class QuickActionRegistry {
public QuickActionRegistry(OsmandSettings settings) {
this.settings = settings;
gson = new GsonBuilder().registerTypeAdapter(QuickAction.class, new QuickActionSerializer()).create();
fabStateMap = getQuickActionFabStateMapFromJson(settings.QUICK_ACTION.get());
updateActionTypes();
}
@ -175,24 +173,13 @@ public class QuickActionRegistry {
}
public boolean isQuickActionOn() {
Boolean result = fabStateMap.get(settings.APPLICATION_MODE.get().getStringKey());
return result != null && result;
return settings.QUICK_ACTION.get();
}
public void setQuickActionFabState(boolean isOn) {
fabStateMap.put(settings.APPLICATION_MODE.get().getStringKey(), isOn);
settings.QUICK_ACTION.set(gson.toJson(fabStateMap));
settings.QUICK_ACTION.set(isOn);
}
private Map<String, Boolean> getQuickActionFabStateMapFromJson(String json) {
Type type = new TypeToken<HashMap<String, Boolean>>() {
}.getType();
HashMap<String, Boolean> quickActions = gson.fromJson(json, type);
return quickActions != null ? quickActions : new HashMap<String, Boolean>();
}
private List<QuickAction> parseActiveActionsList(String json) {
List<QuickAction> resQuickActions;
if (!Algorithms.isEmpty(json)) {

View file

@ -75,6 +75,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
@ -318,6 +319,27 @@ public class OsmandSettings {
}
}
public void migrateQuickActionStates() {
String quickActionsJson = settingsAPI.getString(globalPreferences, "quick_action_new", "");
if (!Algorithms.isEmpty(quickActionsJson)) {
Gson gson = new GsonBuilder().create();
Type type = new TypeToken<HashMap<String, Boolean>>() {
}.getType();
HashMap<String, Boolean> quickActions = gson.fromJson(quickActionsJson, type);
if (!Algorithms.isEmpty(quickActions)) {
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
if (!QUICK_ACTION.isSetForMode(mode)) {
Boolean actionState = quickActions.get(mode.getStringKey());
if (actionState == null) {
actionState = QUICK_ACTION.getDefaultValue();
}
setPreference(QUICK_ACTION.getId(), actionState, mode);
}
}
}
}
}
public void migrateEnumPreferences() {
for (OsmandPreference pref : registeredPreferences.values()) {
if (pref instanceof EnumStringPreference) {
@ -3499,7 +3521,7 @@ public class OsmandSettings {
public static final String QUICK_FAB_MARGIN_X_LANDSCAPE_MARGIN = "quick_fab_margin_x_landscape_margin";
public static final String QUICK_FAB_MARGIN_Y_LANDSCAPE_MARGIN = "quick_fab_margin_y_landscape_margin";
public final CommonPreference<String> QUICK_ACTION = new StringPreference("quick_action_new", "").makeGlobal();
public final CommonPreference<Boolean> QUICK_ACTION = new BooleanPreference("quick_action_state", false).makeProfile();
public final CommonPreference<String> QUICK_ACTION_LIST = new StringPreference("quick_action_list", "").makeGlobal();