From c7b98dd0e31054ce6e17578ca3202a1cdd373708 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 23 Mar 2020 00:12:10 +0100 Subject: [PATCH] Introduce cache and delete todo --- .../plus/quickaction/QuickActionRegistry.java | 19 ++++++------------- .../settings/ExportProfileBottomSheet.java | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java index c0a3764fe2..91f30ac18f 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java @@ -65,7 +65,7 @@ public class QuickActionRegistry { private final OsmandSettings settings; - private final List quickActions; + private List quickActions; private final Map fabStateMap; private final Gson gson; private List quickActionTypes = new ArrayList<>(); @@ -75,13 +75,10 @@ public class QuickActionRegistry { private QuickActionUpdatesListener updatesListener; public QuickActionRegistry(OsmandSettings settings) { - this.settings = settings; gson = new GsonBuilder().registerTypeAdapter(QuickAction.class, new QuickActionSerializer()).create(); - quickActions = parseActiveActionsList(settings.QUICK_ACTION_LIST.get()); fabStateMap = getQuickActionFabStateMapFromJson(settings.QUICK_ACTION.get()); updateActionTypes(); - } public void setUpdatesListener(QuickActionUpdatesListener updatesListener) { @@ -97,14 +94,7 @@ public class QuickActionRegistry { } public List getFilteredQuickActions() { - List actions = quickActions; - List filteredActions = new ArrayList<>(); - for (QuickAction action : actions) { - if (quickActionTypesInt.containsKey(action.getActionType().getId())) { - filteredActions.add(action); - } - } - return filteredActions; + return getQuickActions(); } public void addQuickAction(QuickAction action){ @@ -188,7 +178,7 @@ public class QuickActionRegistry { - public List parseActiveActionsList(String json) { + private List parseActiveActionsList(String json) { Type type = new TypeToken>() {}.getType(); List quickActions = gson.fromJson(json, type); List rquickActions = new ArrayList<>(quickActions.size()); @@ -199,6 +189,7 @@ public class QuickActionRegistry { } } } + this.quickActions = rquickActions; return rquickActions; } @@ -234,6 +225,8 @@ public class QuickActionRegistry { this.quickActionTypes = quickActionTypes; this.quickActionTypesInt = quickActionTypesInt; this.quickActionTypesStr = quickActionTypesStr; + // reparse to get new quick actions + parseActiveActionsList(settings.QUICK_ACTION_LIST.get()); return quickActionTypes; } diff --git a/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java index 61a086149d..a12fd32fd6 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java @@ -220,7 +220,7 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet { QuickActionRegistry registry = app.getQuickActionRegistry(); - List actionsList = registry.parseActiveActionsList(app.getSettings().QUICK_ACTION_LIST.get()); + List actionsList = registry.getQuickActions(); if (!actionsList.isEmpty()) { dataList.put(Type.QUICK_ACTIONS, actionsList); }