diff --git a/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java b/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java index e4f720fa14..46574ab062 100644 --- a/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java +++ b/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java @@ -25,7 +25,8 @@ 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; @@ -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; diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java index 548ff41055..61ae5fd1ca 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java @@ -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 quickActions; - private final Map fabStateMap; private final Gson gson; private List quickActionTypes = new ArrayList<>(); private Map 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 getQuickActionFabStateMapFromJson(String json) { - Type type = new TypeToken>() { - }.getType(); - HashMap quickActions = gson.fromJson(json, type); - - return quickActions != null ? quickActions : new HashMap(); - } - - private List parseActiveActionsList(String json) { List resQuickActions; if (!Algorithms.isEmpty(json)) { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index eb9308efa2..2dd55c810e 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -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,25 @@ 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>() { + }.getType(); + HashMap quickActions = gson.fromJson(quickActionsJson, type); + if (!Algorithms.isEmpty(quickActions)) { + for (ApplicationMode mode : ApplicationMode.allPossibleValues()) { + 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 +3519,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 QUICK_ACTION = new StringPreference("quick_action_new", "").makeGlobal(); + public final CommonPreference QUICK_ACTION = new BooleanPreference("quick_action_state", false).makeProfile(); public final CommonPreference QUICK_ACTION_LIST = new StringPreference("quick_action_list", "").makeGlobal();