Hide inapp banner when already purchased

This commit is contained in:
Alexey Kulish 2017-04-14 10:48:00 +03:00
parent 9ae7e2263f
commit 1a6d8bc76d
2 changed files with 22 additions and 2 deletions

View file

@ -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

View file

@ -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;