From 2445ca69f0a2b7f70c6e18dff1006391b9a0da63 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Wed, 27 Nov 2019 17:31:10 +0300 Subject: [PATCH] Added url to go --- .../osmand/plus/activities/MapActivity.java | 11 +++++++- .../osmand/plus/helpers/DiscountHelper.java | 25 ++++++++++++------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index b344304e6a..75dac299aa 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -1707,6 +1707,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven data.getPath() != null && data.getPath().startsWith("/go")) { String lat = data.getQueryParameter("lat"); String lon = data.getQueryParameter("lon"); + String url = data.getQueryParameter("url"); if (lat != null && lon != null) { try { double lt = Double.parseDouble(lat); @@ -1720,6 +1721,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } catch (NumberFormatException e) { LOG.error("error", e); } + } else if (url != null) { + url = DiscountHelper.parseUrl(app, url); + if (DiscountHelper.validateUrl(app, url)) { + DiscountHelper.openUrl(this, url); + } } setIntent(null); return true; @@ -1736,7 +1742,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven data.getPath() != null && data.getPath().startsWith("/add-tile-source")) { Map attrs = new HashMap<>(); for (String name : data.getQueryParameterNames()) { - attrs.put(name, data.getQueryParameter(name)); + String value = data.getQueryParameter(name); + if (value != null) { + attrs.put(name, value); + } } if (!attrs.isEmpty()) { try { diff --git a/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java b/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java index 4cd0ff3af2..0baafab662 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java @@ -141,13 +141,8 @@ public class DiscountHelper { JSONObject application = obj.getJSONObject("application"); boolean showChristmasDialog = obj.optBoolean("show_christmas_dialog", false); - if (data.url.startsWith(INAPP_PREFIX) && data.url.length() > INAPP_PREFIX.length()) { - String inAppSku = data.url.substring(INAPP_PREFIX.length()); - InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper(); - if (purchaseHelper != null - && purchaseHelper.isPurchased(inAppSku) || InAppPurchaseHelper.isSubscribedToLiveUpdates(app)) { - return; - } + if (!validateUrl(app, data.url)) { + return; } if (data.oneOfConditions != null) { @@ -215,7 +210,19 @@ public class DiscountHelper { } } - private static String parseUrl(OsmandApplication app, String url) { + public static boolean validateUrl(OsmandApplication app, String url) { + if (url.startsWith(INAPP_PREFIX) && url.length() > INAPP_PREFIX.length()) { + String inAppSku = url.substring(INAPP_PREFIX.length()); + InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper(); + if (purchaseHelper != null + && purchaseHelper.isPurchased(inAppSku) || InAppPurchaseHelper.isSubscribedToLiveUpdates(app)) { + return false; + } + } + return true; + } + + public static String parseUrl(OsmandApplication app, String url) { if (!Algorithms.isEmpty(url)) { int i = url.indexOf("osmand-market-app:"); if (i != -1) { @@ -297,7 +304,7 @@ public class DiscountHelper { mFilterVisible = true; } - private static void openUrl(final MapActivity mapActivity, String url) { + public static void openUrl(final MapActivity mapActivity, String url) { if (url.startsWith(INAPP_PREFIX)) { OsmandApplication app = mapActivity.getMyApplication(); InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();