Fix plugin dependent quick actions
This commit is contained in:
parent
50577f3f32
commit
2fac0833cc
9 changed files with 67 additions and 33 deletions
|
@ -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<QuickActionType> getQuickActionTypes() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin was installed
|
||||
*/
|
||||
|
@ -496,9 +501,6 @@ public abstract class OsmandPlugin {
|
|||
return true;
|
||||
}
|
||||
|
||||
protected void registerQuickActionTypes(List<QuickActionType> 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<QuickActionType> quickActionTypes) {
|
||||
for (OsmandPlugin p : getEnabledPlugins()) {
|
||||
p.registerQuickActionTypes(quickActionTypes);
|
||||
public static void registerQuickActionTypesPlugins(Map<QuickActionType, Boolean> 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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -872,10 +872,12 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void registerQuickActionTypes(List<QuickActionType> quickActionTypes) {
|
||||
protected List<QuickActionType> getQuickActionTypes() {
|
||||
ArrayList<QuickActionType> quickActionTypes = new ArrayList<>();
|
||||
quickActionTypes.add(TakeAudioNoteAction.TYPE);
|
||||
quickActionTypes.add(TakePhotoNoteAction.TYPE);
|
||||
quickActionTypes.add(TakeVideoNoteAction.TYPE);
|
||||
return quickActionTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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<QuickActionType> quickActionTypes) {
|
||||
protected List<QuickActionType> getQuickActionTypes() {
|
||||
ArrayList<QuickActionType> quickActionTypes = new ArrayList<>();
|
||||
quickActionTypes.add(AddPOIAction.TYPE);
|
||||
quickActionTypes.add(AddOSMBugAction.TYPE);
|
||||
quickActionTypes.add(ShowHideOSMBugAction.TYPE);
|
||||
return quickActionTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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<QuickActionType> quickActionTypes) {
|
||||
protected List<QuickActionType> getQuickActionTypes() {
|
||||
ArrayList<QuickActionType> quickActionTypes = new ArrayList<>();
|
||||
quickActionTypes.add(ParkingAction.TYPE);
|
||||
return quickActionTypes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<String, Boolean> fabStateMap;
|
||||
private final Gson gson;
|
||||
private List<QuickActionType> quickActionTypes = new ArrayList<>();
|
||||
private Map<Integer, QuickActionType> quickActionTypesInt = new TreeMap<>();
|
||||
private Map<String, QuickActionType> quickActionTypesStr = new TreeMap<>();
|
||||
private Map<Integer, Pair<QuickActionType, Boolean>> quickActionTypesInt = new TreeMap<>();
|
||||
private Map<String, Pair<QuickActionType, Boolean>> 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<Integer, QuickActionType> quickActionTypesInt = new TreeMap<>();
|
||||
Map<String, QuickActionType> quickActionTypesStr = new TreeMap<>();
|
||||
Map<Integer, Pair<QuickActionType, Boolean>> quickActionTypesInt = new TreeMap<>();
|
||||
Map<String, Pair<QuickActionType, Boolean>> 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<QuickActionType, Boolean> pluginActions = new HashMap<>();
|
||||
OsmandPlugin.registerQuickActionTypesPlugins(pluginActions);
|
||||
for (Map.Entry<QuickActionType, Boolean> 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<QuickActionType, Boolean> 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<QuickActionType, Boolean> 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<QuickActionType, Boolean> 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();
|
||||
|
|
|
@ -683,9 +683,11 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void registerQuickActionTypes(List<QuickActionType> quickActionTypes) {
|
||||
protected List<QuickActionType> getQuickActionTypes() {
|
||||
ArrayList<QuickActionType> quickActionTypes = new ArrayList<>();
|
||||
quickActionTypes.add(MapSourceAction.TYPE);
|
||||
quickActionTypes.add(MapOverlayAction.TYPE);
|
||||
quickActionTypes.add(MapUnderlayAction.TYPE);
|
||||
return quickActionTypes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -520,8 +520,10 @@ public class SRTMPlugin extends OsmandPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void registerQuickActionTypes(List<QuickActionType> quickActionTypes) {
|
||||
protected List<QuickActionType> getQuickActionTypes() {
|
||||
ArrayList<QuickActionType> quickActionTypes = new ArrayList<>();
|
||||
quickActionTypes.add(ContourLinesAction.TYPE);
|
||||
quickActionTypes.add(TerrainAction.TYPE);
|
||||
return quickActionTypes;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue