Hide disabled quick actions from ui
This commit is contained in:
parent
c585feb1fa
commit
a208ae7029
2 changed files with 30 additions and 19 deletions
|
@ -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<String, String> 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<HashMap<String, LinkedHashSet<String>>>() {
|
||||
}.getType();
|
||||
MapPoiTypes poiTypes = app.getPoiTypes();
|
||||
List<PoiUIFilter> 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<String, LinkedHashSet<String>> acceptedTypes = gson.fromJson(acceptedTypesString, type);
|
||||
Map<PoiCategory, LinkedHashSet<String>> acceptedTypesDone = new HashMap<>();
|
||||
for (Map.Entry<String, LinkedHashSet<String>> 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) {
|
||||
|
|
|
@ -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<QuickAction> actions = getQuickActions();
|
||||
List<QuickAction> filteredActions = new ArrayList<>();
|
||||
|
||||
List<QuickAction> 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<String, String> 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) {
|
||||
|
|
Loading…
Reference in a new issue