Hide inapp banner when already purchased
This commit is contained in:
parent
267a560c98
commit
5bd92b5ae9
2 changed files with 22 additions and 2 deletions
|
@ -39,6 +39,7 @@ public class DiscountHelper {
|
||||||
private static String mUrl;
|
private static String mUrl;
|
||||||
private static boolean mBannerVisible;
|
private static boolean mBannerVisible;
|
||||||
private static final String URL = "http://osmand.net/api/motd";
|
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) {
|
public static void checkAndDisplay(final MapActivity mapActivity) {
|
||||||
|
@ -105,6 +106,13 @@ public class DiscountHelper {
|
||||||
int maxTotalShow = obj.getInt("max_total_show");
|
int maxTotalShow = obj.getInt("max_total_show");
|
||||||
JSONObject application = obj.getJSONObject("application");
|
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();
|
String appName = app.getPackageName();
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
if (application.has(appName) && application.getBoolean(appName)
|
if (application.has(appName) && application.getBoolean(appName)
|
||||||
|
@ -113,7 +121,7 @@ public class DiscountHelper {
|
||||||
OsmandSettings settings = app.getSettings();
|
OsmandSettings settings = app.getSettings();
|
||||||
int discountId = getDiscountId(message, description, start, end);
|
int discountId = getDiscountId(message, description, start, end);
|
||||||
boolean discountChanged = settings.DISCOUNT_ID.get() != discountId;
|
boolean discountChanged = settings.DISCOUNT_ID.get() != discountId;
|
||||||
if(discountChanged) {
|
if (discountChanged) {
|
||||||
settings.DISCOUNT_TOTAL_SHOW.set(0);
|
settings.DISCOUNT_TOTAL_SHOW.set(0);
|
||||||
}
|
}
|
||||||
if (discountChanged
|
if (discountChanged
|
||||||
|
@ -200,7 +208,7 @@ public class DiscountHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void openUrl(final MapActivity mapActivity, String url) {
|
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)) {
|
if (url.contains(InAppHelper.SKU_FULL_VERSION_PRICE)) {
|
||||||
mapActivity.execInAppTask(new InAppHelper.InAppRunnable() {
|
mapActivity.execInAppTask(new InAppHelper.InAppRunnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -173,6 +173,18 @@ public class InAppHelper {
|
||||||
return lastValidationCheckTime != 0;
|
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) {
|
public void exec(final @NonNull InAppRunnable runnable) {
|
||||||
this.stopAfterResult = true;
|
this.stopAfterResult = true;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue