diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index 2089394446..6e4bad6203 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -56,6 +56,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; public abstract class OsmandPlugin { @@ -190,6 +191,10 @@ public abstract class OsmandPlugin { return Collections.emptyList(); } + protected List getQuickActionTypes() { + return Collections.emptyList(); + } + /** * Plugin was installed */ @@ -496,9 +501,6 @@ public abstract class OsmandPlugin { return true; } - protected void registerQuickActionTypes(List quickActionTypes) { - } - protected void registerLayerContextMenuActions(OsmandMapTileView mapView, ContextMenuAdapter adapter, MapActivity mapActivity) { } @@ -787,14 +789,14 @@ public abstract class OsmandPlugin { return false; } - public static void registerQuickActionTypesPlugins(List quickActionTypes) { - for (OsmandPlugin p : getEnabledPlugins()) { - p.registerQuickActionTypes(quickActionTypes); + public static void registerQuickActionTypesPlugins(Map availableQuickActionTypes) { + for (OsmandPlugin p : getAvailablePlugins()) { + for (QuickActionType actionType : p.getQuickActionTypes()) { + availableQuickActionTypes.put(actionType, p.isActive()); + } } } - - public static void updateLocationPlugins(net.osmand.Location location) { for (OsmandPlugin p : getEnabledPlugins()) { p.updateLocation(location); diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index d5bd3f1d96..a6fa51f208 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -1379,6 +1379,7 @@ public class SettingsHelper { } newActions.addAll(appliedItems); actionRegistry.updateQuickActions(newActions); + actionRegistry.updateActionTypes(); } } @@ -1415,9 +1416,9 @@ public class SettingsHelper { String name = object.getString("name"); QuickAction quickAction = null; if (object.has("actionType")) { - quickAction = quickActionRegistry.newActionByStringType(object.getString("actionType")); + quickAction = quickActionRegistry.newActionByStringType(object.getString("actionType"), false); } else if (object.has("type")) { - quickAction = quickActionRegistry.newActionByType(object.getInt("type")); + quickAction = quickActionRegistry.newActionByType(object.getInt("type"), false); } if (quickAction != null) { String paramsString = object.getString("params"); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index a23d712a33..39c625b988 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -872,10 +872,12 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } @Override - protected void registerQuickActionTypes(List quickActionTypes) { + protected List getQuickActionTypes() { + ArrayList quickActionTypes = new ArrayList<>(); quickActionTypes.add(TakeAudioNoteAction.TYPE); quickActionTypes.add(TakePhotoNoteAction.TYPE); quickActionTypes.add(TakeVideoNoteAction.TYPE); + return quickActionTypes; } @Override diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index af0426318a..bf29967be1 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -49,6 +49,7 @@ import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; +import java.util.ArrayList; import java.util.List; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_CREATE_POI; @@ -139,10 +140,12 @@ public class OsmEditingPlugin extends OsmandPlugin { // private EditingPOIDialogProvider poiActions; @Override - protected void registerQuickActionTypes(List quickActionTypes) { + protected List getQuickActionTypes() { + ArrayList quickActionTypes = new ArrayList<>(); quickActionTypes.add(AddPOIAction.TYPE); quickActionTypes.add(AddOSMBugAction.TYPE); quickActionTypes.add(ShowHideOSMBugAction.TYPE); + return quickActionTypes; } @Override diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java index 0cf8e837c0..c7e09b8156 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java @@ -41,6 +41,7 @@ import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.mapwidgets.TextInfoWidget; +import java.util.ArrayList; import java.util.Calendar; import java.util.List; @@ -632,7 +633,9 @@ public class ParkingPositionPlugin extends OsmandPlugin { @Override - protected void registerQuickActionTypes(List quickActionTypes) { + protected List getQuickActionTypes() { + ArrayList quickActionTypes = new ArrayList<>(); quickActionTypes.add(ParkingAction.TYPE); + return quickActionTypes; } } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java b/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java index 079157e383..9a01a47a03 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java @@ -124,7 +124,7 @@ public class CreateEditActionDialog extends DialogFragment { : savedInstanceState.getBoolean(KEY_ACTION_IS_NEW); action = QuickActionRegistry.produceAction(isNew - ? quickActionRegistry.newActionByType(type) + ? quickActionRegistry.newActionByType(type, true) : quickActionRegistry.getQuickAction(actionId)); setupToolbar(view); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java index 714abee320..4a2fa5c204 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java @@ -2,6 +2,8 @@ package net.osmand.plus.quickaction; import android.content.Context; +import androidx.core.util.Pair; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; @@ -70,8 +72,8 @@ public class QuickActionRegistry { private final Map fabStateMap; private final Gson gson; private List quickActionTypes = new ArrayList<>(); - private Map quickActionTypesInt = new TreeMap<>(); - private Map quickActionTypesStr = new TreeMap<>(); + private Map> quickActionTypesInt = new TreeMap<>(); + private Map> quickActionTypesStr = new TreeMap<>(); private QuickActionUpdatesListener updatesListener; @@ -232,14 +234,23 @@ public class QuickActionRegistry { quickActionTypes.add(NavAutoZoomMapAction.TYPE); quickActionTypes.add(NavStartStopAction.TYPE); quickActionTypes.add(NavResumePauseAction.TYPE); - OsmandPlugin.registerQuickActionTypesPlugins(quickActionTypes); - Map quickActionTypesInt = new TreeMap<>(); - Map quickActionTypesStr = new TreeMap<>(); + Map> quickActionTypesInt = new TreeMap<>(); + Map> quickActionTypesStr = new TreeMap<>(); for (QuickActionType qt : quickActionTypes) { - quickActionTypesInt.put(qt.getId(), qt); - quickActionTypesStr.put(qt.getStringId(), qt); + quickActionTypesInt.put(qt.getId(), new Pair<>(qt, true)); + quickActionTypesStr.put(qt.getStringId(), new Pair<>(qt, true)); } + + Map pluginActions = new HashMap<>(); + OsmandPlugin.registerQuickActionTypesPlugins(pluginActions); + for (Map.Entry entry : pluginActions.entrySet()) { + QuickActionType qt = entry.getKey(); + boolean available = entry.getValue(); + quickActionTypesInt.put(qt.getId(), new Pair<>(qt, available)); + quickActionTypesStr.put(qt.getStringId(), new Pair<>(qt, available)); + } + this.quickActionTypes = quickActionTypes; this.quickActionTypesInt = quickActionTypesInt; this.quickActionTypesStr = quickActionTypesStr; @@ -276,18 +287,22 @@ public class QuickActionRegistry { } } - public QuickAction newActionByStringType(String actionType) { - QuickActionType quickActionType = quickActionTypesStr.get(actionType); - if (quickActionType != null) { - return quickActionType.createNew(); + public QuickAction newActionByStringType(String actionType, boolean onlyAvailable) { + Pair quickActionTypeState = quickActionTypesStr.get(actionType); + if (quickActionTypeState != null && quickActionTypeState.first != null) { + if (!onlyAvailable || quickActionTypeState.second != null && quickActionTypeState.second) { + return quickActionTypeState.first.createNew(); + } } return null; } - public QuickAction newActionByType(int type) { - QuickActionType quickActionType = quickActionTypesInt.get(type); - if (quickActionType != null) { - return quickActionType.createNew(); + public QuickAction newActionByType(int type, boolean onlyAvailable) { + Pair quickActionTypeState = quickActionTypesInt.get(type); + if (quickActionTypeState != null && quickActionTypeState.first != null) { + if (!onlyAvailable || quickActionTypeState.second != null && quickActionTypeState.second) { + return quickActionTypeState.first.createNew(); + } } return null; } @@ -303,12 +318,16 @@ public class QuickActionRegistry { public QuickAction deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject obj = json.getAsJsonObject(); QuickActionType found = null; + Pair quickActionTypeState = null; if (obj.has("actionType")) { String actionType = obj.get("actionType").getAsString(); - found = quickActionTypesStr.get(actionType); + quickActionTypeState = quickActionTypesStr.get(actionType); } else if (obj.has("type")) { int type = obj.get("type").getAsInt(); - found = quickActionTypesInt.get(type); + quickActionTypeState = quickActionTypesInt.get(type); + } + if (quickActionTypeState != null && quickActionTypeState.second != null && quickActionTypeState.second) { + found = quickActionTypeState.first; } if (found != null) { QuickAction qa = found.createNew(); diff --git a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java index b4d1085a4c..d2ee18c6a7 100644 --- a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java @@ -683,9 +683,11 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { } @Override - protected void registerQuickActionTypes(List quickActionTypes) { + protected List getQuickActionTypes() { + ArrayList quickActionTypes = new ArrayList<>(); quickActionTypes.add(MapSourceAction.TYPE); quickActionTypes.add(MapOverlayAction.TYPE); quickActionTypes.add(MapUnderlayAction.TYPE); + return quickActionTypes; } } diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java index bb0ad947a6..20cbb866b8 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java @@ -520,8 +520,10 @@ public class SRTMPlugin extends OsmandPlugin { } @Override - protected void registerQuickActionTypes(List quickActionTypes) { + protected List getQuickActionTypes() { + ArrayList quickActionTypes = new ArrayList<>(); quickActionTypes.add(ContourLinesAction.TYPE); quickActionTypes.add(TerrainAction.TYPE); + return quickActionTypes; } }