This commit is contained in:
Vitaliy 2020-07-21 18:12:10 +03:00
parent ab993c88de
commit 8dedb3908a
3 changed files with 32 additions and 20 deletions

View file

@ -25,7 +25,8 @@ class AppVersionUpgradeOnInit {
// Each upgrade should have independent version! // 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 // 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; 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_7_01;
@ -110,6 +111,10 @@ class AppVersionUpgradeOnInit {
}); });
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_7_01).commit(); 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().putInt(VERSION_INSTALLED_NUMBER, lastVersion).commit();
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit(); startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
appVersionChanged = true; appVersionChanged = true;

View file

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

View file

@ -75,6 +75,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; 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<HashMap<String, Boolean>>() {
}.getType();
HashMap<String, Boolean> 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() { public void migrateEnumPreferences() {
for (OsmandPreference pref : registeredPreferences.values()) { for (OsmandPreference pref : registeredPreferences.values()) {
if (pref instanceof EnumStringPreference) { 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_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 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(); public final CommonPreference<String> QUICK_ACTION_LIST = new StringPreference("quick_action_list", "").makeGlobal();