From 5bd92b5ae92e112a2999049888f4e75428e85456 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Fri, 14 Apr 2017 10:48:00 +0300 Subject: [PATCH] Hide inapp banner when already purchased --- .../src/net/osmand/plus/helpers/DiscountHelper.java | 12 ++++++++++-- OsmAnd/src/net/osmand/plus/inapp/InAppHelper.java | 12 ++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java b/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java index 2f2d1e6be4..281de080d7 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java @@ -39,6 +39,7 @@ public class DiscountHelper { private static String mUrl; private static boolean mBannerVisible; private static final String URL = "http://osmand.net/api/motd"; + private static final String INAPP_PREFIX = "osmand-in-app:"; public static void checkAndDisplay(final MapActivity mapActivity) { @@ -105,6 +106,13 @@ public class DiscountHelper { int maxTotalShow = obj.getInt("max_total_show"); JSONObject application = obj.getJSONObject("application"); + if (url.startsWith(INAPP_PREFIX) && url.length() > INAPP_PREFIX.length()) { + String inAppSku = url.substring(INAPP_PREFIX.length()); + if (InAppHelper.isPurchased(app, inAppSku)) { + return; + } + } + String appName = app.getPackageName(); Date date = new Date(); if (application.has(appName) && application.getBoolean(appName) @@ -113,7 +121,7 @@ public class DiscountHelper { OsmandSettings settings = app.getSettings(); int discountId = getDiscountId(message, description, start, end); boolean discountChanged = settings.DISCOUNT_ID.get() != discountId; - if(discountChanged) { + if (discountChanged) { settings.DISCOUNT_TOTAL_SHOW.set(0); } if (discountChanged @@ -200,7 +208,7 @@ public class DiscountHelper { } private static void openUrl(final MapActivity mapActivity, String url) { - if (url.startsWith("osmand-in-app:")) { + if (url.startsWith(INAPP_PREFIX)) { if (url.contains(InAppHelper.SKU_FULL_VERSION_PRICE)) { mapActivity.execInAppTask(new InAppHelper.InAppRunnable() { @Override diff --git a/OsmAnd/src/net/osmand/plus/inapp/InAppHelper.java b/OsmAnd/src/net/osmand/plus/inapp/InAppHelper.java index 2c38d3328b..18aa1715e9 100644 --- a/OsmAnd/src/net/osmand/plus/inapp/InAppHelper.java +++ b/OsmAnd/src/net/osmand/plus/inapp/InAppHelper.java @@ -173,6 +173,18 @@ public class InAppHelper { return lastValidationCheckTime != 0; } + public static boolean isPurchased(OsmandApplication ctx, String inAppSku) { + OsmandSettings settings = ctx.getSettings(); + if (inAppSku.equals(SKU_FULL_VERSION_PRICE)) { + return settings.FULL_VERSION_PURCHASED.get(); + } else if (inAppSku.equals(SKU_LIVE_UPDATES_FULL) || inAppSku.equals(SKU_LIVE_UPDATES_FREE)) { + return settings.LIVE_UPDATES_PURCHASED.get(); + } else if (inAppSku.equals(SKU_DEPTH_CONTOURS_FULL) || inAppSku.equals(SKU_DEPTH_CONTOURS_FREE)) { + return settings.DEPTH_CONTOURS_PURCHASED.get(); + } + return false; + } + public void exec(final @NonNull InAppRunnable runnable) { this.stopAfterResult = true;