From 059fbb4fd3c5378e935d8e6a40f3e9f5374ef0bc Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Fri, 4 May 2018 22:31:52 +0300 Subject: [PATCH] Do not show restart dialog on osmlive renew --- .../activities/OsmandInAppPurchaseActivity.java | 17 ++++++++++------- .../chooseplan/ChoosePlanDialogFragment.java | 8 ++++---- .../plus/chooseplan/OsmLiveCancelledDialog.java | 2 +- .../ui/DownloadResourceGroupFragment.java | 2 +- .../osmand/plus/inapp/InAppPurchaseHelper.java | 17 +++++++++++------ .../plus/liveupdates/LiveUpdatesFragment.java | 4 ++-- .../plus/liveupdates/SubscriptionFragment.java | 2 +- 7 files changed, 30 insertions(+), 22 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/OsmandInAppPurchaseActivity.java b/OsmAnd/src/net/osmand/plus/activities/OsmandInAppPurchaseActivity.java index 56b5829d36..3ba69e5c6e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/OsmandInAppPurchaseActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/OsmandInAppPurchaseActivity.java @@ -175,23 +175,26 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In } @Override - public void onItemPurchased(String sku) { + public void onItemPurchased(String sku, boolean active) { if (purchaseHelper != null && purchaseHelper.getSkuLiveUpdates().equals(sku)) { getMyApplication().logEvent(this, "live_osm_subscription_purchased"); - OsmLiveRestartBottomSheetDialogFragment fragment = new OsmLiveRestartBottomSheetDialogFragment(); - fragment.setUsedOnMap(this instanceof MapActivity); - fragment.show(getSupportFragmentManager(), OsmLiveRestartBottomSheetDialogFragment.TAG); + if (!active) { + OsmLiveRestartBottomSheetDialogFragment fragment = new OsmLiveRestartBottomSheetDialogFragment(); + fragment.setUsedOnMap(this instanceof MapActivity); + fragment.show(getSupportFragmentManager(), OsmLiveRestartBottomSheetDialogFragment.TAG); + } } onInAppPurchaseItemPurchased(sku); - fireInAppPurchaseItemPurchasedOnFragments(getSupportFragmentManager(), sku); + fireInAppPurchaseItemPurchasedOnFragments(getSupportFragmentManager(), sku, active); } - public void fireInAppPurchaseItemPurchasedOnFragments(@NonNull FragmentManager fragmentManager, String sku) { + public void fireInAppPurchaseItemPurchasedOnFragments(@NonNull FragmentManager fragmentManager, + String sku, boolean active) { List fragments = fragmentManager.getFragments(); for (Fragment f : fragments) { if (f instanceof InAppPurchaseListener && f.isAdded()) { - ((InAppPurchaseListener) f).onItemPurchased(sku); + ((InAppPurchaseListener) f).onItemPurchased(sku, active); } } } diff --git a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java index 92d64f12db..b29271a193 100644 --- a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java @@ -4,7 +4,6 @@ import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; -import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.support.annotation.ColorRes; @@ -39,8 +38,6 @@ import net.osmand.plus.base.BaseOsmAndDialogFragment; import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener; import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseTaskType; -import net.osmand.plus.liveupdates.OsmLiveActivity; -import net.osmand.plus.liveupdates.SubscriptionFragment; import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.widgets.TextViewEx; @@ -84,6 +81,9 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment } public boolean isFeaturePurchased(OsmandApplication ctx) { + if (InAppPurchaseHelper.isSubscribedToLiveUpdates(ctx)) { + return true; + } switch (this) { case DAILY_MAP_UPDATES: case DONATION_TO_OSM: @@ -447,7 +447,7 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment } @Override - public void onItemPurchased(String sku) { + public void onItemPurchased(String sku, boolean active) { } @Override diff --git a/OsmAnd/src/net/osmand/plus/chooseplan/OsmLiveCancelledDialog.java b/OsmAnd/src/net/osmand/plus/chooseplan/OsmLiveCancelledDialog.java index c54afd120f..29c1bd33ec 100644 --- a/OsmAnd/src/net/osmand/plus/chooseplan/OsmLiveCancelledDialog.java +++ b/OsmAnd/src/net/osmand/plus/chooseplan/OsmLiveCancelledDialog.java @@ -169,7 +169,7 @@ public class OsmLiveCancelledDialog extends BaseOsmAndDialogFragment implements } @Override - public void onItemPurchased(String sku) { + public void onItemPurchased(String sku, boolean active) { } @Override diff --git a/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java index b266d9b8b9..0a2fb28888 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java @@ -345,7 +345,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow } @Override - public void onItemPurchased(String sku) { + public void onItemPurchased(String sku, boolean active) { getMyApplication().getDownloadThread().runReloadIndexFilesSilent(); } diff --git a/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java b/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java index 94afb04aad..f16bdc241b 100644 --- a/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java +++ b/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java @@ -97,7 +97,7 @@ public class InAppPurchaseHelper { void onGetItems(); - void onItemPurchased(String sku); + void onItemPurchased(String sku, boolean active); void showProgress(InAppPurchaseTaskType taskType); @@ -604,11 +604,16 @@ public class InAppPurchaseHelper { sendToken(purchase.getToken(), new OnRequestResultListener() { @Override public void onResult(String result) { + boolean active = ctx.getSettings().LIVE_UPDATES_PURCHASED.get(); ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true); ctx.getSettings().getCustomRenderBooleanProperty("depthContours").set(true); + ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_TIME.set(0L); + ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_FIRST_DLG_SHOWN.set(false); + ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_SECOND_DLG_SHOWN.set(false); + notifyDismissProgress(InAppPurchaseTaskType.PURCHASE_LIVE_UPDATES); - notifyItemPurchased(SKU_LIVE_UPDATES); + notifyItemPurchased(SKU_LIVE_UPDATES, active); stop(true); } }); @@ -620,7 +625,7 @@ public class InAppPurchaseHelper { ctx.getSettings().FULL_VERSION_PURCHASED.set(true); notifyDismissProgress(InAppPurchaseTaskType.PURCHASE_FULL_VERSION); - notifyItemPurchased(SKU_FULL_VERSION_PRICE); + notifyItemPurchased(SKU_FULL_VERSION_PRICE, false); stop(true); } else if (purchase.getSku().equals(SKU_DEPTH_CONTOURS)) { @@ -631,7 +636,7 @@ public class InAppPurchaseHelper { ctx.getSettings().getCustomRenderBooleanProperty("depthContours").set(true); notifyDismissProgress(InAppPurchaseTaskType.PURCHASE_DEPTH_CONTOURS); - notifyItemPurchased(SKU_DEPTH_CONTOURS); + notifyItemPurchased(SKU_DEPTH_CONTOURS, false); stop(true); } else { @@ -748,9 +753,9 @@ public class InAppPurchaseHelper { } } - private void notifyItemPurchased(String sku) { + private void notifyItemPurchased(String sku, boolean active) { if (uiActivity != null) { - uiActivity.onItemPurchased(sku); + uiActivity.onItemPurchased(sku, active); } } diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java index 0ba61a3fef..973428dffd 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java @@ -715,7 +715,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc } @Override - public void onItemPurchased(String sku) { + public void onItemPurchased(String sku, boolean active) { InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper(); if (purchaseHelper != null && purchaseHelper.getSkuLiveUpdates().equals(sku)) { updateSubscriptionHeader(); @@ -723,7 +723,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc OsmandInAppPurchaseActivity activity = getInAppPurchaseActivity(); if (activity != null) { - activity.fireInAppPurchaseItemPurchasedOnFragments(getChildFragmentManager(), sku); + activity.fireInAppPurchaseItemPurchasedOnFragments(getChildFragmentManager(), sku, active); } } diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/SubscriptionFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/SubscriptionFragment.java index dd089c9a7d..a80f5e9f8a 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/SubscriptionFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/SubscriptionFragment.java @@ -355,7 +355,7 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In } @Override - public void onItemPurchased(String sku) { + public void onItemPurchased(String sku, boolean active) { dismiss(); }