diff --git a/OsmAnd/src/net/osmand/plus/CustomOsmandPlugin.java b/OsmAnd/src/net/osmand/plus/CustomOsmandPlugin.java index ce8869f7c1..8fe8dada16 100644 --- a/OsmAnd/src/net/osmand/plus/CustomOsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/CustomOsmandPlugin.java @@ -8,7 +8,6 @@ import com.google.gson.reflect.TypeToken; import net.osmand.PlatformUtil; import net.osmand.map.ITileSource; import net.osmand.map.TileSourceManager; -import net.osmand.osm.MapPoiTypes; import net.osmand.osm.PoiCategory; import net.osmand.plus.helpers.AvoidSpecificRoads; import net.osmand.plus.poi.PoiUIFilter; @@ -25,7 +24,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; public class CustomOsmandPlugin extends OsmandPlugin { @@ -334,12 +332,11 @@ public class CustomOsmandPlugin extends OsmandPlugin { int actionType = object.getInt("type"); String paramsString = object.getString("params"); HashMap params = gson.fromJson(paramsString, type); - QuickAction quickAction = new QuickAction(actionType); - if (!name.isEmpty()) { - quickAction.setName(name); + + QuickAction action = app.getQuickActionRegistry().getQuickAction(app, actionType, name, params); + if (action != null) { + quickActions.add(action); } - quickAction.setParams(params); - quickActions.add(quickAction); } } } catch (JSONException e) { @@ -387,23 +384,17 @@ public class CustomOsmandPlugin extends OsmandPlugin { if (!Algorithms.isEmpty(poiUIFiltersStr)) { JSONObject poiUIFiltersJson = new JSONObject(poiUIFiltersStr); JSONArray jsonArray = poiUIFiltersJson.getJSONArray("items"); - Gson gson = new Gson(); - Type type = new TypeToken>>() { - }.getType(); - MapPoiTypes poiTypes = app.getPoiTypes(); + List existingItems = app.getPoiFilters().getUserDefinedPoiFilters(false); + for (int i = 0; i < jsonArray.length(); i++) { JSONObject object = jsonArray.getJSONObject(i); String name = object.getString("name"); String filterId = object.getString("filterId"); - String acceptedTypesString = object.getString("acceptedTypes"); - HashMap> acceptedTypes = gson.fromJson(acceptedTypesString, type); - Map> acceptedTypesDone = new HashMap<>(); - for (Map.Entry> mapItem : acceptedTypes.entrySet()) { - final PoiCategory a = poiTypes.getPoiCategoryByName(mapItem.getKey()); - acceptedTypesDone.put(a, mapItem.getValue()); + for (PoiUIFilter filter : existingItems) { + if (filter.getName().equals(name)) { + poiUIFilters.add(filter); + } } - PoiUIFilter filter = new PoiUIFilter(name, filterId, acceptedTypesDone, app); - poiUIFilters.add(filter); } } } catch (JSONException e) { diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java index 07bc2f4202..28466d8f90 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java @@ -5,6 +5,7 @@ import android.content.Context; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.audionotes.AudioVideoNotesPlugin; @@ -77,6 +78,11 @@ public class QuickActionRegistry { List actions = getQuickActions(); List filteredActions = new ArrayList<>(); + List disabledPluginActions = new ArrayList<>(); + for (OsmandPlugin plugin : OsmandPlugin.getNotEnabledPlugins()) { + disabledPluginActions.addAll(plugin.getQuickActions()); + } + for (QuickAction action : actions) { boolean skip = false; if (OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class) == null) { @@ -122,6 +128,9 @@ public class QuickActionRegistry { skip = true; } } + if (disabledPluginActions.contains(action)) { + skip = true; + } if (!skip) { filteredActions.add(action); } @@ -180,6 +189,17 @@ public class QuickActionRegistry { return null; } + public QuickAction getQuickAction(OsmandApplication app, int type, String name, Map params) { + for (QuickAction action : quickActions) { + if (action.type == type + && (action.hasCustomName(app) && action.getName(app).equals(name) || !action.hasCustomName(app)) + && action.getParams().equals(params)) { + return action; + } + } + return null; + } + public boolean isNameUnique(QuickAction action, Context context){ for (QuickAction a: quickActions){ if (action.id != a.id) {