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