From 649f7e594b4b88e5d2173f1f1f5cf71e273d4aee Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 3 Apr 2020 17:07:41 +0300 Subject: [PATCH] Add warnings to settings items --- OsmAnd/res/values/strings.xml | 3 ++ OsmAnd/src/net/osmand/plus/OsmandPlugin.java | 2 +- .../src/net/osmand/plus/SettingsHelper.java | 28 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 08b95def38..dfd62fdc32 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,9 @@ Thx - Hardy --> + Could not import %1$s. + Could not write %1$s. + Could not read %1$s. Custom OsmAnd plugin Snowmobile Ski touring diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index 3b4864bad1..a386303aba 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -789,7 +789,7 @@ public abstract class OsmandPlugin { } public static void registerQuickActionTypesPlugins(List quickActionTypes) { - for (OsmandPlugin p : getAvailablePlugins()) { + for (OsmandPlugin p : getEnabledPlugins()) { quickActionTypes.addAll(p.getQuickActionTypes()); } } diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index d5bd3f1d96..3a5da6894c 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -10,6 +10,7 @@ import androidx.annotation.Nullable; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import net.osmand.AndroidUtils; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.data.LatLon; @@ -142,6 +143,8 @@ public class SettingsHelper { boolean shouldReplace = false; + protected List warnings; + SettingsItem(OsmandApplication app) { this.app = app; init(); @@ -149,6 +152,7 @@ public class SettingsHelper { SettingsItem(OsmandApplication app, @NonNull JSONObject json) throws JSONException { this.app = app; + warnings = new ArrayList<>(); init(); readFromJson(json); } @@ -157,6 +161,10 @@ public class SettingsHelper { // override } + public List getWarnings() { + return warnings; + } + @NonNull public abstract SettingsItemType getType(); @@ -1256,6 +1264,7 @@ public class SettingsHelper { try { setInputStream(new FileInputStream(file)); } catch (FileNotFoundException e) { + warnings.add(app.getString(R.string.settings_item_read_error, file.getName())); LOG.error("Failed to set input stream from file: " + file.getName(), e); } return super.getWriter(); @@ -1428,9 +1437,12 @@ public class SettingsHelper { } quickAction.setParams(params); items.add(quickAction); + } else { + warnings.add(app.getString(R.string.settings_item_read_error, name)); } } } catch (JSONException e) { + warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType()))); throw new IllegalArgumentException("Json parse error", e); } } @@ -1453,6 +1465,7 @@ public class SettingsHelper { } json.put("items", jsonArray); } catch (JSONException e) { + warnings.add(app.getString(R.string.settings_item_write_error, String.valueOf(getType()))); LOG.error("Failed write to json", e); } } @@ -1574,6 +1587,7 @@ public class SettingsHelper { items.add(filter); } } catch (JSONException e) { + warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType()))); throw new IllegalArgumentException("Json parse error", e); } } @@ -1595,6 +1609,7 @@ public class SettingsHelper { } json.put("items", jsonArray); } catch (JSONException e) { + warnings.add(app.getString(R.string.settings_item_write_error, String.valueOf(getType()))); LOG.error("Failed write to json", e); } } @@ -1758,6 +1773,7 @@ public class SettingsHelper { items.add(template); } } catch (JSONException e) { + warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType()))); throw new IllegalArgumentException("Json parse error", e); } } @@ -1792,6 +1808,7 @@ public class SettingsHelper { json.put("items", jsonArray); } catch (JSONException e) { + warnings.add(app.getString(R.string.settings_item_write_error, String.valueOf(getType()))); LOG.error("Failed write to json", e); } } @@ -1927,6 +1944,7 @@ public class SettingsHelper { items.add(roadInfo); } } catch (JSONException e) { + warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType()))); throw new IllegalArgumentException("Json parse error", e); } } @@ -1946,6 +1964,7 @@ public class SettingsHelper { } json.put("items", jsonArray); } catch (JSONException e) { + warnings.add(app.getString(R.string.settings_item_write_error, String.valueOf(getType()))); LOG.error("Failed write to json", e); } } @@ -2232,8 +2251,10 @@ public class SettingsHelper { reader.readFromStream(ois); } } catch (IllegalArgumentException e) { + item.warnings.add(app.getString(R.string.settings_item_read_error, item.getName())); LOG.error("Error reading item data: " + item.getName(), e); } catch (IOException e) { + item.warnings.add(app.getString(R.string.settings_item_read_error, item.getName())); LOG.error("Error reading item data: " + item.getName(), e); } finally { zis.closeEntry(); @@ -2484,6 +2505,13 @@ public class SettingsHelper { private void finishImport(@Nullable SettingsImportListener listener, boolean success, @NonNull List items) { importTask = null; + List warnings = new ArrayList<>(); + for (SettingsItem item : items) { + warnings.addAll(item.getWarnings()); + } + if (!warnings.isEmpty()) { + app.showToastMessage(AndroidUtils.formatWarnings(warnings).toString()); + } if (listener != null) { listener.onSettingsImportFinished(success, items); }