Fix parsing settings items and remove unnecessary changes

This commit is contained in:
Vitaliy 2020-03-23 17:05:05 +02:00
parent 37f5dd0419
commit 235028d317
5 changed files with 57 additions and 441 deletions

View file

@ -4,28 +4,16 @@ import android.content.res.Configuration;
import androidx.annotation.NonNull;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import net.osmand.PlatformUtil;
import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager;
import net.osmand.osm.PoiCategory;
import net.osmand.plus.helpers.AvoidSpecificRoads;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@ -39,11 +27,6 @@ public class CustomOsmandPlugin extends OsmandPlugin {
public List<String> rendererNames = new ArrayList<>();
public List<String> routerNames = new ArrayList<>();
public List<ApplicationMode> appModes = new ArrayList<>();
public List<QuickAction> quickActions = new ArrayList<>();
public List<PoiUIFilter> poiUIFilters = new ArrayList<>();
public List<ITileSource> mapSources = new ArrayList<>();
public List<AvoidSpecificRoads.AvoidRoadInfo> avoidRoadInfos = new ArrayList<>();
public CustomOsmandPlugin(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
super(app);
@ -139,314 +122,9 @@ public class CustomOsmandPlugin extends OsmandPlugin {
}
json.put("description", descriptionJson);
saveAdditionalItemsToJson(json);
return json.toString();
}
public void loadAdditionalItemsFromJson(JSONObject json) throws JSONException {
if (json.has("appModes")) {
String appModesStr = json.getString("appModes");
if (!Algorithms.isEmpty(appModesStr)) {
JSONArray appModesJson = new JSONArray(appModesStr);
for (int i = 0; i < appModesJson.length(); i++) {
String str = appModesJson.getString(i);
ApplicationMode mode = ApplicationMode.valueOfStringKey(str, null);
if (mode != null) {
appModes.add(mode);
}
}
}
}
if (json.has("rendererNames")) {
String rendererNamesStr = json.getString("rendererNames");
if (!Algorithms.isEmpty(rendererNamesStr)) {
JSONArray rendererNamesJson = new JSONArray(rendererNamesStr);
for (int i = 0; i < rendererNamesJson.length(); i++) {
String str = rendererNamesJson.getString(i);
rendererNames.add(str);
}
}
}
if (json.has("routerNames")) {
String routerNamesStr = json.getString("routerNames");
if (!Algorithms.isEmpty(routerNamesStr)) {
JSONArray routerNamesJson = new JSONArray(routerNamesStr);
for (int i = 0; i < routerNamesJson.length(); i++) {
String str = routerNamesJson.getString(i);
routerNames.add(str);
}
}
}
readPoiUIFiltersFromJson(json);
readMapSourcesFromJson(json);
readQuickActionsFromJson(json);
readAvoidRoadsFromJson(json);
}
public void saveAdditionalItemsToJson(JSONObject json) throws JSONException {
if (!appModes.isEmpty()) {
List<String> appModesKeys = new ArrayList<>();
for (ApplicationMode mode : appModes) {
appModesKeys.add(mode.getStringKey());
}
JSONArray appModesJson = new JSONArray(appModesKeys);
json.put("appModes", appModesJson);
}
if (!rendererNames.isEmpty()) {
JSONArray rendererNamesJson = new JSONArray(rendererNames);
json.put("rendererNames", rendererNamesJson);
}
if (!routerNames.isEmpty()) {
JSONArray rendererNamesJson = new JSONArray(routerNames);
json.put("routerNames", rendererNamesJson);
}
savePoiUIFiltersToJson(json);
saveMapSourcesToJson(json);
saveQuickActionsToJson(json);
saveAvoidRoadsToJson(json);
}
private void savePoiUIFiltersToJson(JSONObject poiUIFiltersJson) throws JSONException {
if (!poiUIFilters.isEmpty()) {
JSONObject json = new JSONObject();
JSONArray jsonArray = new JSONArray();
Gson gson = new Gson();
Type type = new TypeToken<HashMap<PoiCategory, LinkedHashSet<String>>>() {
}.getType();
try {
for (PoiUIFilter filter : poiUIFilters) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", filter.getName());
jsonObject.put("filterId", filter.getFilterId());
jsonObject.put("acceptedTypes", gson.toJson(filter.getAcceptedTypes(), type));
jsonArray.put(jsonObject);
}
json.put("items", jsonArray);
} catch (JSONException e) {
LOG.error("Failed write to json", e);
}
poiUIFiltersJson.put("poiUIFilters", json);
}
}
private void saveMapSourcesToJson(JSONObject mapSourcesJson) throws JSONException {
if (!mapSources.isEmpty()) {
JSONObject json = new JSONObject();
JSONArray jsonArray = new JSONArray();
if (!mapSources.isEmpty()) {
try {
for (ITileSource template : mapSources) {
JSONObject jsonObject = new JSONObject();
boolean sql = template instanceof SQLiteTileSource;
jsonObject.put("sql", sql);
jsonObject.put("name", template.getName());
jsonObject.put("minZoom", template.getMinimumZoomSupported());
jsonObject.put("maxZoom", template.getMaximumZoomSupported());
jsonObject.put("url", template.getUrlTemplate());
jsonObject.put("randoms", template.getRandoms());
jsonObject.put("ellipsoid", template.isEllipticYTile());
jsonObject.put("inverted_y", template.isInvertedYTile());
jsonObject.put("referer", template.getReferer());
jsonObject.put("timesupported", template.isTimeSupported());
jsonObject.put("expire", template.getExpirationTimeMillis());
jsonObject.put("inversiveZoom", template.getInversiveZoom());
jsonObject.put("ext", template.getTileFormat());
jsonObject.put("tileSize", template.getTileSize());
jsonObject.put("bitDensity", template.getBitDensity());
jsonObject.put("avgSize", template.getAvgSize());
jsonObject.put("rule", template.getRule());
jsonArray.put(jsonObject);
}
json.put("items", jsonArray);
} catch (JSONException e) {
LOG.error("Failed write to json", e);
}
}
mapSourcesJson.put("mapSources", json);
}
}
private void saveAvoidRoadsToJson(JSONObject avoidRoadInfosJson) throws JSONException {
if (!avoidRoadInfos.isEmpty()) {
JSONObject json = new JSONObject();
JSONArray jsonArray = new JSONArray();
if (!avoidRoadInfos.isEmpty()) {
try {
for (AvoidSpecificRoads.AvoidRoadInfo avoidRoad : avoidRoadInfos) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("latitude", avoidRoad.latitude);
jsonObject.put("longitude", avoidRoad.longitude);
jsonObject.put("name", avoidRoad.name);
jsonObject.put("appModeKey", avoidRoad.appModeKey);
jsonArray.put(jsonObject);
}
json.put("items", jsonArray);
} catch (JSONException e) {
LOG.error("Failed write to json", e);
}
}
avoidRoadInfosJson.put("avoidRoadInfos", json);
}
}
private void saveQuickActionsToJson(JSONObject quickActionsJson) throws JSONException {
if (!quickActions.isEmpty()) {
JSONObject json = new JSONObject();
JSONArray jsonArray = new JSONArray();
Gson gson = new Gson();
Type type = new TypeToken<HashMap<String, String>>() {
}.getType();
if (!quickActions.isEmpty()) {
try {
for (QuickAction action : quickActions) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", action.hasCustomName(app)
? action.getName(app) : "");
jsonObject.put("type", action.getType());
jsonObject.put("params", gson.toJson(action.getParams(), type));
jsonArray.put(jsonObject);
}
json.put("items", jsonArray);
} catch (JSONException e) {
LOG.error("Failed write to json", e);
}
}
quickActionsJson.put("quickActions", json);
}
}
private void readMapSourcesFromJson(JSONObject json) {
if (json.has("mapSources")) {
try {
String mapSourcesStr = json.getString("mapSources");
if (!Algorithms.isEmpty(mapSourcesStr)) {
json = new JSONObject(mapSourcesStr);
JSONArray jsonArray = json.getJSONArray("items");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject object = jsonArray.getJSONObject(i);
boolean sql = object.optBoolean("sql");
String name = object.optString("name");
int minZoom = object.optInt("minZoom");
int maxZoom = object.optInt("maxZoom");
String url = object.optString("url");
String randoms = object.optString("randoms");
boolean ellipsoid = object.optBoolean("ellipsoid", false);
boolean invertedY = object.optBoolean("inverted_y", false);
String referer = object.optString("referer");
boolean timesupported = object.optBoolean("timesupported", false);
long expire = object.optLong("expire");
boolean inversiveZoom = object.optBoolean("inversiveZoom", false);
String ext = object.optString("ext");
int tileSize = object.optInt("tileSize");
int bitDensity = object.optInt("bitDensity");
int avgSize = object.optInt("avgSize");
String rule = object.optString("rule");
ITileSource template;
if (!sql) {
template = new TileSourceManager.TileSourceTemplate(name, url, ext, maxZoom, minZoom, tileSize, bitDensity, avgSize);
} else {
template = new SQLiteTileSource(app, name, minZoom, maxZoom, url, randoms, ellipsoid, invertedY, referer, timesupported, expire, inversiveZoom);
}
mapSources.add(template);
}
}
} catch (JSONException e) {
throw new IllegalArgumentException("Json parse error", e);
}
}
}
private void readQuickActionsFromJson(JSONObject json) {
if (json.has("quickActions")) {
try {
String quickActionsStr = json.getString("quickActions");
if (!Algorithms.isEmpty(quickActionsStr)) {
Gson gson = new Gson();
Type type = new TypeToken<HashMap<String, String>>() {
}.getType();
JSONObject quickActionsJson = new JSONObject(quickActionsStr);
JSONArray itemsJson = quickActionsJson.getJSONArray("items");
for (int i = 0; i < itemsJson.length(); i++) {
JSONObject object = itemsJson.getJSONObject(i);
String name = object.getString("name");
int actionType = object.getInt("type");
String paramsString = object.getString("params");
HashMap<String, String> params = gson.fromJson(paramsString, type);
QuickAction action = app.getQuickActionRegistry().getQuickAction(app, actionType, name, params);
if (action != null) {
quickActions.add(action);
}
}
}
} catch (JSONException e) {
throw new IllegalArgumentException("Json parse error", e);
}
}
}
private void readAvoidRoadsFromJson(JSONObject json) {
if (json.has("avoidRoadInfos")) {
try {
String avoidRoadInfosStr = json.getString("avoidRoadInfos");
if (!Algorithms.isEmpty(avoidRoadInfosStr)) {
JSONObject avoidRoadInfosJson = new JSONObject(avoidRoadInfosStr);
JSONArray jsonArray = avoidRoadInfosJson.getJSONArray("items");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject object = jsonArray.getJSONObject(i);
double latitude = object.optDouble("latitude");
double longitude = object.optDouble("longitude");
String name = object.optString("name");
String appModeKey = object.optString("appModeKey");
AvoidSpecificRoads.AvoidRoadInfo roadInfo = new AvoidSpecificRoads.AvoidRoadInfo();
roadInfo.id = 0;
roadInfo.latitude = latitude;
roadInfo.longitude = longitude;
roadInfo.name = name;
if (ApplicationMode.valueOfStringKey(appModeKey, null) != null) {
roadInfo.appModeKey = appModeKey;
} else {
roadInfo.appModeKey = app.getRoutingHelper().getAppMode().getStringKey();
}
avoidRoadInfos.add(roadInfo);
}
}
} catch (JSONException e) {
throw new IllegalArgumentException("Json parse error", e);
}
}
}
private void readPoiUIFiltersFromJson(JSONObject json) {
if (json.has("poiUIFilters")) {
try {
String poiUIFiltersStr = json.getString("poiUIFilters");
if (!Algorithms.isEmpty(poiUIFiltersStr)) {
JSONObject poiUIFiltersJson = new JSONObject(poiUIFiltersStr);
JSONArray jsonArray = poiUIFiltersJson.getJSONArray("items");
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");
for (PoiUIFilter filter : existingItems) {
if (filter.getName().equals(name)) {
poiUIFilters.add(filter);
}
}
}
}
} catch (JSONException e) {
throw new IllegalArgumentException("Json parse error", e);
}
}
}
@Override
public List<String> getRendererNames() {
return rendererNames;
@ -456,29 +134,4 @@ public class CustomOsmandPlugin extends OsmandPlugin {
public List<String> getRouterNames() {
return routerNames;
}
@Override
public List<ApplicationMode> getAddedAppModes() {
return appModes;
}
@Override
public List<QuickAction> getQuickActions() {
return quickActions;
}
@Override
public List<PoiUIFilter> getPoiUIFilters() {
return poiUIFilters;
}
@Override
public List<ITileSource> getMapSources() {
return mapSources;
}
@Override
public List<AvoidSpecificRoads.AvoidRoadInfo> getAvoidRoadInfos() {
return avoidRoadInfos;
}
}

View file

@ -20,7 +20,6 @@ import net.osmand.IProgress;
import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibilityPlugin;
import net.osmand.map.ITileSource;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TabActivity.TabItem;
import net.osmand.plus.api.SettingsAPI;
@ -30,7 +29,6 @@ import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.dialogs.PluginDisabledBottomSheet;
import net.osmand.plus.dialogs.PluginInstalledBottomSheetDialog;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.helpers.AvoidSpecificRoads;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.mapillary.MapillaryPlugin;
@ -40,8 +38,6 @@ import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.settings.BaseSettingsFragment;
import net.osmand.plus.skimapsplugin.SkiMapsPlugin;
@ -185,22 +181,6 @@ public abstract class OsmandPlugin {
return Collections.emptyList();
}
public List<QuickAction> getQuickActions() {
return Collections.emptyList();
}
public List<PoiUIFilter> getPoiUIFilters() {
return Collections.emptyList();
}
public List<ITileSource> getMapSources() {
return Collections.emptyList();
}
public List<AvoidSpecificRoads.AvoidRoadInfo> getAvoidRoadInfos() {
return Collections.emptyList();
}
/**
* Plugin was installed
*/
@ -311,7 +291,6 @@ public abstract class OsmandPlugin {
for (int i = 0; i < jArray.length(); i++) {
JSONObject json = jArray.getJSONObject(i);
CustomOsmandPlugin plugin = new CustomOsmandPlugin(app, json);
plugin.loadAdditionalItemsFromJson(json);
allPlugins.add(plugin);
}
} catch (JSONException e) {

View file

@ -25,7 +25,6 @@ import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionRegistry;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -136,16 +135,20 @@ public class SettingsHelper {
public abstract static class SettingsItem {
protected OsmandApplication app;
private String pluginId;
private String fileName;
boolean shouldReplace = false;
SettingsItem() {
SettingsItem(OsmandApplication app) {
this.app = app;
init();
}
SettingsItem(@NonNull JSONObject json) throws JSONException {
SettingsItem(OsmandApplication app, @NonNull JSONObject json) throws JSONException {
this.app = app;
init();
readFromJson(json);
}
@ -313,14 +316,11 @@ public class SettingsHelper {
public static class PluginSettingsItem extends SettingsItem {
private OsmandApplication app;
private CustomOsmandPlugin plugin;
private List<SettingsItem> pluginItems;
PluginSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
super(json);
this.app = app;
readFromJson(app, json);
super(app, json);
}
@NonNull
@ -355,7 +355,9 @@ public class SettingsHelper {
return pluginItems;
}
void readFromJson(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
@Override
void readFromJson(@NonNull JSONObject json) throws JSONException {
super.readFromJson(json);
plugin = new CustomOsmandPlugin(app, json);
}
@ -384,13 +386,13 @@ public class SettingsHelper {
duplicateItems = new ArrayList<>();
}
CollectionSettingsItem(@NonNull List<T> items) {
super();
CollectionSettingsItem(OsmandApplication app, @NonNull List<T> items) {
super(app);
this.items = items;
}
CollectionSettingsItem(@NonNull JSONObject json) throws JSONException {
super(json);
CollectionSettingsItem(OsmandApplication app, @NonNull JSONObject json) throws JSONException {
super(app, json);
}
@NonNull
@ -453,12 +455,12 @@ public class SettingsHelper {
private OsmandSettings settings;
protected OsmandSettingsItem(@NonNull OsmandSettings settings) {
super();
super(settings.getContext());
this.settings = settings;
}
protected OsmandSettingsItem(@NonNull SettingsItemType type, @NonNull OsmandSettings settings, @NonNull JSONObject json) throws JSONException {
super(json);
super(settings.getContext(), json);
this.settings = settings;
}
@ -620,7 +622,6 @@ public class SettingsHelper {
public static class ProfileSettingsItem extends OsmandSettingsItem {
private OsmandApplication app;
private ApplicationMode appMode;
private ApplicationModeBuilder builder;
private ApplicationModeBean modeBean;
@ -628,14 +629,12 @@ public class SettingsHelper {
public ProfileSettingsItem(@NonNull OsmandApplication app, @NonNull ApplicationMode appMode) {
super(app.getSettings());
this.app = app;
this.appMode = appMode;
appModeBeanPrefsIds = new HashSet<>(Arrays.asList(app.getSettings().appModeBeanPrefsIds));
}
public ProfileSettingsItem(@NonNull OsmandApplication app, @NonNull ApplicationModeBean modeBean) {
super(app.getSettings());
this.app = app;
this.modeBean = modeBean;
builder = ApplicationMode.fromModeBean(app, modeBean);
appMode = builder.getApplicationMode();
@ -644,8 +643,6 @@ public class SettingsHelper {
public ProfileSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
super(SettingsItemType.PROFILE, app.getSettings(), json);
this.app = app;
readFromJson(app, json);
appModeBeanPrefsIds = new HashSet<>(Arrays.asList(app.getSettings().appModeBeanPrefsIds));
}
@ -687,7 +684,9 @@ public class SettingsHelper {
return "profile_" + getName() + ".json";
}
void readFromJson(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
@Override
void readFromJson(@NonNull JSONObject json) throws JSONException {
super.readFromJson(json);
String appModeJson = json.getString("appMode");
modeBean = ApplicationMode.fromJson(appModeJson);
builder = ApplicationMode.fromModeBean(app, modeBean);
@ -814,17 +813,17 @@ public class SettingsHelper {
private InputStream inputStream;
protected String name;
public StreamSettingsItem(@NonNull String name) {
super();
public StreamSettingsItem(@NonNull OsmandApplication app, @NonNull String name) {
super(app);
this.name = name;
}
StreamSettingsItem(@NonNull JSONObject json) throws JSONException {
super(json);
StreamSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
super(app, json);
}
public StreamSettingsItem(@NonNull InputStream inputStream, @NonNull String name) {
super();
public StreamSettingsItem(@NonNull OsmandApplication app, @NonNull InputStream inputStream, @NonNull String name) {
super(app);
this.inputStream = inputStream;
this.name = name;
}
@ -868,16 +867,16 @@ public class SettingsHelper {
@Nullable
private byte[] data;
public DataSettingsItem(@NonNull String name) {
super(name);
public DataSettingsItem(@NonNull OsmandApplication app, @NonNull String name) {
super(app, name);
}
DataSettingsItem(@NonNull JSONObject json) throws JSONException {
super(json);
DataSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
super(app, json);
}
public DataSettingsItem(@NonNull byte[] data, @NonNull String name) {
super(name);
public DataSettingsItem(@NonNull OsmandApplication app, @NonNull byte[] data, @NonNull String name) {
super(app, name);
this.data = data;
}
@ -992,7 +991,7 @@ public class SettingsHelper {
private FileSubtype subtype;
public FileSettingsItem(@NonNull OsmandApplication app, @NonNull File file) throws IllegalArgumentException {
super(file.getPath().replace(app.getAppPath(null).getPath(), ""));
super(app, file.getPath().replace(app.getAppPath(null).getPath(), ""));
this.file = file;
this.appPath = app.getAppPath(null);
this.subtype = FileSubtype.getSubtypeByFileName(getFileName());
@ -1002,7 +1001,7 @@ public class SettingsHelper {
}
public FileSettingsItem(@NonNull OsmandApplication app, @NonNull FileSubtype subtype, @NonNull File file) throws IllegalArgumentException {
super(file.getPath().replace(app.getAppPath(null).getPath(), ""));
super(app, file.getPath().replace(app.getAppPath(null).getPath(), ""));
this.file = file;
this.appPath = app.getAppPath(null);
this.subtype = subtype;
@ -1012,7 +1011,7 @@ public class SettingsHelper {
}
FileSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
super(json);
super(app, json);
this.file = new File(app.getAppPath(null), name);
this.appPath = app.getAppPath(null);
}
@ -1176,19 +1175,16 @@ public class SettingsHelper {
public static class QuickActionsSettingsItem extends CollectionSettingsItem<QuickAction> {
private OsmandApplication app;
private QuickActionRegistry actionRegistry;
public QuickActionsSettingsItem(@NonNull OsmandApplication app, @NonNull List<QuickAction> items) {
super(items);
this.app = app;
super(app, items);
actionRegistry = app.getQuickActionRegistry();
existingItems = actionRegistry.getQuickActions();
}
QuickActionsSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
super(json);
this.app = app;
super(app, json);
actionRegistry = app.getQuickActionRegistry();
existingItems = actionRegistry.getQuickActions();
}
@ -1270,10 +1266,10 @@ public class SettingsHelper {
JSONObject object = itemsJson.getJSONObject(i);
String name = object.getString("name");
QuickAction quickAction = null;
if(object.has("actionType")) {
quickAction = quickActionRegistry .newActionByStringType(object.getString("actionType"));
} else if(object.has("type")) {
quickAction = quickActionRegistry .newActionByType(object.getInt("type"));
if (object.has("actionType")) {
quickAction = quickActionRegistry.newActionByStringType(object.getString("actionType"));
} else if (object.has("type")) {
quickAction = quickActionRegistry.newActionByType(object.getInt("type"));
}
if (quickAction != null) {
String paramsString = object.getString("params");
@ -1329,17 +1325,13 @@ public class SettingsHelper {
public static class PoiUiFilterSettingsItem extends CollectionSettingsItem<PoiUIFilter> {
private OsmandApplication app;
public PoiUiFilterSettingsItem(@NonNull OsmandApplication app, @NonNull List<PoiUIFilter> items) {
super(items);
this.app = app;
super(app, items);
existingItems = app.getPoiFilters().getUserDefinedPoiFilters(false);
}
PoiUiFilterSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
super(json);
this.app = app;
super(app, json);
existingItems = app.getPoiFilters().getUserDefinedPoiFilters(false);
}
@ -1479,13 +1471,13 @@ public class SettingsHelper {
private List<String> existingItemsNames;
public MapSourcesSettingsItem(@NonNull OsmandApplication app, @NonNull List<ITileSource> items) {
super(items);
super(app, items);
this.app = app;
existingItemsNames = new ArrayList<>(app.getSettings().getTileSourceEntries().values());
}
MapSourcesSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
super(json);
super(app, json);
this.app = app;
existingItemsNames = new ArrayList<>(app.getSettings().getTileSourceEntries().values());
}
@ -1682,7 +1674,7 @@ public class SettingsHelper {
private AvoidSpecificRoads specificRoads;
public AvoidRoadsSettingsItem(@NonNull OsmandApplication app, @NonNull List<AvoidRoadInfo> items) {
super(items);
super(app, items);
this.app = app;
settings = app.getSettings();
specificRoads = app.getAvoidSpecificRoads();
@ -1690,7 +1682,7 @@ public class SettingsHelper {
}
AvoidRoadsSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
super(json);
super(app, json);
this.app = app;
settings = app.getSettings();
specificRoads = app.getAvoidSpecificRoads();
@ -1910,7 +1902,7 @@ public class SettingsHelper {
item = new PluginSettingsItem(app, json);
break;
case DATA:
item = new DataSettingsItem(json);
item = new DataSettingsItem(app, json);
break;
case FILE:
item = new FileSettingsItem(app, json);

View file

@ -797,7 +797,7 @@ public class ImportHelper {
for (SettingsHelper.SettingsItem item : items) {
if (item instanceof SettingsHelper.PluginSettingsItem) {
pluginSettingsItems.add((SettingsHelper.PluginSettingsItem) item);
} else {
} else if (Algorithms.isEmpty(item.getPluginId())) {
pluginIndependentItems.add(item);
}
}
@ -805,23 +805,16 @@ public class ImportHelper {
CustomOsmandPlugin plugin = pluginItem.getPlugin();
List<SettingsHelper.SettingsItem> pluginItems = pluginItem.getPluginItems();
if (!Algorithms.isEmpty(pluginItems)) {
pluginIndependentItems.removeAll(pluginItems);
for (SettingsHelper.SettingsItem item : pluginItems) {
item.setShouldReplace(true);
if (item instanceof SettingsHelper.QuickActionsSettingsItem) {
plugin.quickActions = ((SettingsHelper.QuickActionsSettingsItem) item).getItems();
}
if (item instanceof SettingsHelper.PoiUiFilterSettingsItem) {
plugin.poiUIFilters = ((SettingsHelper.PoiUiFilterSettingsItem) item).getItems();
}
if (item instanceof SettingsHelper.MapSourcesSettingsItem) {
plugin.mapSources = ((SettingsHelper.MapSourcesSettingsItem) item).getItems();
}
if (item instanceof SettingsHelper.AvoidRoadsSettingsItem) {
plugin.avoidRoadInfos = ((SettingsHelper.AvoidRoadsSettingsItem) item).getItems();
}
if (item instanceof SettingsHelper.ProfileSettingsItem) {
plugin.appModes.add(((SettingsHelper.ProfileSettingsItem) item).getAppMode());
if (item instanceof SettingsHelper.FileSettingsItem) {
SettingsHelper.FileSettingsItem fileItem = (SettingsHelper.FileSettingsItem) item;
if (fileItem.getSubtype() == SettingsHelper.FileSettingsItem.FileSubtype.RENDERING_STYLE) {
plugin.rendererNames.add(fileItem.getFileName());
}
if (fileItem.getSubtype() == SettingsHelper.FileSettingsItem.FileSubtype.ROUTING_CONFIG) {
plugin.routerNames.add(fileItem.getFileName());
}
}
}

View file

@ -34,7 +34,6 @@ import net.osmand.plus.quickaction.actions.NewAction;
import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction;
import net.osmand.plus.quickaction.actions.ShowHideGpxTracksAction;
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
import net.osmand.util.Algorithms;
import java.lang.reflect.Type;
import java.util.ArrayList;
@ -194,7 +193,7 @@ public class QuickActionRegistry {
Type type = new TypeToken<List<QuickAction>>() {
}.getType();
List<QuickAction> quickActions = gson.fromJson(json, type);
List<QuickAction> rquickActions = new ArrayList<>(quickActions.size());
List<QuickAction> rquickActions = new ArrayList<>();
if (quickActions != null) {
for (QuickAction qa : quickActions) {
if (qa != null) {