diff --git a/OsmAnd/res/layout/purchase_dialog_card.xml b/OsmAnd/res/layout/purchase_dialog_card.xml
index d511f68ece..2dde98ac32 100644
--- a/OsmAnd/res/layout/purchase_dialog_card.xml
+++ b/OsmAnd/res/layout/purchase_dialog_card.xml
@@ -43,6 +43,7 @@
android:layout_margin="@dimen/card_padding">
+
diff --git a/OsmAnd/res/layout/purchase_dialog_card_button_disabled.xml b/OsmAnd/res/layout/purchase_dialog_card_button_disabled.xml
new file mode 100644
index 0000000000..d54fefb6b5
--- /dev/null
+++ b/OsmAnd/res/layout/purchase_dialog_card_button_disabled.xml
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/purchase_dialog_card_button_ex.xml b/OsmAnd/res/layout/purchase_dialog_card_button_ex.xml
index 6a6a208620..2dba96adf7 100644
--- a/OsmAnd/res/layout/purchase_dialog_card_button_ex.xml
+++ b/OsmAnd/res/layout/purchase_dialog_card_button_ex.xml
@@ -47,8 +47,9 @@
@@ -120,6 +125,39 @@
+
+
+
+
+
+
+
+
+
+
+ Plan & Pricing
Pay monthly
Pay once in 3 months
Pay once a year
diff --git a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java
index 7b81d8e3ee..4b8ca2cb07 100644
--- a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java
@@ -43,6 +43,7 @@ import net.osmand.plus.download.DownloadValidationManager;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseTaskType;
+import net.osmand.plus.inapp.InAppPurchases.InAppPurchase;
import net.osmand.plus.inapp.InAppPurchases.InAppSubscription;
import net.osmand.plus.liveupdates.SubscriptionFragment;
import net.osmand.plus.srtmplugin.SRTMPlugin;
@@ -51,6 +52,8 @@ import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
+import java.util.List;
+
public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment implements InAppPurchaseListener {
public static final String TAG = ChoosePlanDialogFragment.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(ChoosePlanDialogFragment.class);
@@ -63,6 +66,7 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
private ViewGroup osmLiveCardButtonsContainer;
private ProgressBar osmLiveCardProgress;
private View planTypeCardButton;
+ private View planTypeCardButtonDisabled;
public interface ChoosePlanDialogListener {
void onChoosePlanDialogDismiss();
@@ -253,12 +257,25 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
public abstract String getPlanTypeHeaderDescription();
- public abstract String getPlanTypeButtonTitle();
+ public String getPlanTypeButtonTitle() {
+ InAppPurchase purchase = getPlanTypePurchase();
+ if (purchase != null) {
+ if (purchase.isPurchased()) {
+ return purchase.getPrice(getContext());
+ } else {
+ return getString(R.string.purchase_unlim_title, purchase.getPrice(getContext()));
+ }
+ }
+ return "";
+ }
public abstract String getPlanTypeButtonDescription();
public abstract void setPlanTypeButtonClickListener(View button);
+ @Nullable
+ public abstract InAppPurchase getPlanTypePurchase();
+
private View inflate(@LayoutRes int layoutId, @Nullable ViewGroup container) {
int themeRes = nightMode ? R.style.OsmandDarkTheme_DarkActionbar : R.style.OsmandLightTheme_DarkActionbar_LightStatusBar;
return LayoutInflater.from(new ContextThemeWrapper(getContext(), themeRes))
@@ -326,7 +343,15 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
View lastBtn = null;
InAppSubscription monthlyLiveUpdates = purchaseHelper.getMonthlyLiveUpdates();
double regularMonthlyPrice = monthlyLiveUpdates.getPriceValue();
- for (final InAppSubscription s : purchaseHelper.getLiveUpdates().getVisibleSubscriptions()) {
+ List visibleSubscriptions = purchaseHelper.getLiveUpdates().getVisibleSubscriptions();
+ boolean anyPurchased = false;
+ for (final InAppSubscription s : visibleSubscriptions) {
+ if (s.isPurchased()) {
+ anyPurchased = true;
+ break;
+ }
+ }
+ for (final InAppSubscription s : visibleSubscriptions) {
if (s.isPurchased()) {
View buttonPurchased = inflate(R.layout.purchase_dialog_card_button_active_ex, osmLiveCardButtonsContainer);
View buttonContainer = buttonPurchased.findViewById(R.id.button_container);
@@ -402,13 +427,22 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
View button = inflate(R.layout.purchase_dialog_card_button_ex, osmLiveCardButtonsContainer);
TextViewEx title = (TextViewEx) button.findViewById(R.id.title);
TextViewEx description = (TextViewEx) button.findViewById(R.id.description);
+
+ View buttonView = button.findViewById(R.id.button_view);
+ View buttonExView = button.findViewById(R.id.button_ex_view);
TextViewEx buttonTitle = (TextViewEx) button.findViewById(R.id.button_title);
+ TextViewEx buttonExTitle = (TextViewEx) button.findViewById(R.id.button_ex_title);
+ buttonView.setVisibility(anyPurchased ? View.VISIBLE : View.GONE);
+ buttonExView.setVisibility(!anyPurchased ? View.VISIBLE : View.GONE);
+
TextViewEx discountRegular = (TextViewEx) button.findViewById(R.id.discount_banner_regular);
TextViewEx discountActive = (TextViewEx) button.findViewById(R.id.discount_banner_active);
View div = button.findViewById(R.id.div);
+
title.setText(s.getTitle(ctx));
description.setText(s.getDescription(ctx));
buttonTitle.setText(s.getPrice(ctx));
+ buttonExTitle.setText(s.getPrice(ctx));
if (regularMonthlyPrice > 0 && s.getMonthlyPriceValue() > 0 && s.getMonthlyPriceValue() < regularMonthlyPrice) {
int discount = (int) ((1 - s.getMonthlyPriceValue() / regularMonthlyPrice) * 100d);
@@ -435,6 +469,21 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
subscribe(s.getSku());
}
});
+ if (anyPurchased) {
+ buttonView.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ subscribe(s.getSku());
+ }
+ });
+ } else {
+ buttonExView.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ subscribe(s.getSku());
+ }
+ });
+ }
div.setVisibility(View.VISIBLE);
osmLiveCardButtonsContainer.addView(button);
lastBtn = button;
@@ -538,27 +587,44 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
cardDescription.setText(R.string.in_app_purchase_desc_ex);
planTypeCardButton = cardView.findViewById(R.id.card_button);
+ planTypeCardButtonDisabled = cardView.findViewById(R.id.card_button_disabled);
return cardView;
}
- private void setupPlanTypeCardButton(boolean progress) {
- if (planTypeCardButton != null) {
+ private void setupPlanTypeCardButtons(boolean progress) {
+ if (planTypeCardButton != null && planTypeCardButtonDisabled != null) {
+ InAppPurchase purchase = getPlanTypePurchase();
+ boolean purchased = purchase != null && purchase.isPurchased();
+
ProgressBar progressBar = (ProgressBar) planTypeCardButton.findViewById(R.id.card_button_progress);
TextViewEx buttonTitle = (TextViewEx) planTypeCardButton.findViewById(R.id.card_button_title);
TextViewEx buttonSubtitle = (TextViewEx) planTypeCardButton.findViewById(R.id.card_button_subtitle);
buttonTitle.setText(getPlanTypeButtonTitle());
buttonSubtitle.setText(getPlanTypeButtonDescription());
if (progress) {
+ planTypeCardButton.setVisibility(View.VISIBLE);
+ planTypeCardButtonDisabled.setVisibility(View.GONE);
buttonTitle.setVisibility(View.GONE);
buttonSubtitle.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE);
planTypeCardButton.setOnClickListener(null);
} else {
- buttonTitle.setVisibility(View.VISIBLE);
- buttonSubtitle.setVisibility(View.VISIBLE);
- progressBar.setVisibility(View.GONE);
- setPlanTypeButtonClickListener(planTypeCardButton);
+ if (!purchased) {
+ planTypeCardButton.setVisibility(View.VISIBLE);
+ planTypeCardButtonDisabled.setVisibility(View.GONE);
+ buttonTitle.setVisibility(View.VISIBLE);
+ buttonSubtitle.setVisibility(View.VISIBLE);
+ progressBar.setVisibility(View.GONE);
+ setPlanTypeButtonClickListener(planTypeCardButton);
+ } else {
+ planTypeCardButton.setVisibility(View.GONE);
+ planTypeCardButtonDisabled.setVisibility(View.VISIBLE);
+ buttonTitle = (TextViewEx) planTypeCardButtonDisabled.findViewById(R.id.card_button_title);
+ buttonSubtitle = (TextViewEx) planTypeCardButtonDisabled.findViewById(R.id.card_button_subtitle);
+ buttonTitle.setText(getPlanTypeButtonTitle());
+ buttonSubtitle.setText(getPlanTypeButtonDescription());
+ }
}
}
}
@@ -586,7 +652,7 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
setupOsmLiveCardButtons(requestingInventory);
}
if (planTypeCardButton != null) {
- setupPlanTypeCardButton(requestingInventory);
+ setupPlanTypeCardButtons(requestingInventory);
}
}
@@ -604,7 +670,7 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
public void onError(InAppPurchaseTaskType taskType, String error) {
if (taskType == InAppPurchaseTaskType.REQUEST_INVENTORY) {
setupOsmLiveCardButtons(false);
- setupPlanTypeCardButton(false);
+ setupPlanTypeCardButtons(false);
}
}
@@ -627,7 +693,7 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
public void showProgress(InAppPurchaseTaskType taskType) {
if (taskType == InAppPurchaseTaskType.REQUEST_INVENTORY) {
setupOsmLiveCardButtons(true);
- setupPlanTypeCardButton(true);
+ setupPlanTypeCardButtons(true);
}
}
@@ -635,7 +701,7 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
public void dismissProgress(InAppPurchaseTaskType taskType) {
if (taskType == InAppPurchaseTaskType.REQUEST_INVENTORY) {
setupOsmLiveCardButtons(false);
- setupPlanTypeCardButton(false);
+ setupPlanTypeCardButtons(false);
}
}
diff --git a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanFreeBannerDialogFragment.java b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanFreeBannerDialogFragment.java
index d988b7d4bb..2544c037bb 100644
--- a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanFreeBannerDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanFreeBannerDialogFragment.java
@@ -1,12 +1,14 @@
package net.osmand.plus.chooseplan;
import android.app.Activity;
+import android.support.annotation.Nullable;
import android.view.View;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandInAppPurchaseActivity;
import net.osmand.plus.inapp.InAppPurchaseHelper;
+import net.osmand.plus.inapp.InAppPurchases.InAppPurchase;
public class ChoosePlanFreeBannerDialogFragment extends ChoosePlanDialogFragment {
public static final String TAG = ChoosePlanFreeBannerDialogFragment.class.getSimpleName();
@@ -72,12 +74,6 @@ public class ChoosePlanFreeBannerDialogFragment extends ChoosePlanDialogFragment
}
}
- @Override
- public String getPlanTypeButtonTitle() {
- InAppPurchaseHelper purchaseHelper = getOsmandApplication().getInAppPurchaseHelper();
- return getString(R.string.purchase_unlim_title, purchaseHelper.getFullVersion().getPrice(getContext()));
- }
-
@Override
public String getPlanTypeButtonDescription() {
return getString(R.string.in_app_purchase_desc);
@@ -102,4 +98,14 @@ public class ChoosePlanFreeBannerDialogFragment extends ChoosePlanDialogFragment
}
});
}
+
+ @Nullable
+ @Override
+ public InAppPurchase getPlanTypePurchase() {
+ InAppPurchaseHelper purchaseHelper = getOsmandApplication().getInAppPurchaseHelper();
+ if (purchaseHelper != null) {
+ return purchaseHelper.getFullVersion();
+ }
+ return null;
+ }
}
diff --git a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanHillshadeSrtmDialogFragment.java b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanHillshadeSrtmDialogFragment.java
index cc1d81e64c..4580830191 100644
--- a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanHillshadeSrtmDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanHillshadeSrtmDialogFragment.java
@@ -1,11 +1,13 @@
package net.osmand.plus.chooseplan;
import android.app.Activity;
+import android.support.annotation.Nullable;
import android.view.View;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandInAppPurchaseActivity;
import net.osmand.plus.inapp.InAppPurchaseHelper;
+import net.osmand.plus.inapp.InAppPurchases.InAppPurchase;
public class ChoosePlanHillshadeSrtmDialogFragment extends ChoosePlanDialogFragment {
public static final String TAG = ChoosePlanHillshadeSrtmDialogFragment.class.getSimpleName();
@@ -64,12 +66,6 @@ public class ChoosePlanHillshadeSrtmDialogFragment extends ChoosePlanDialogFragm
return getString(R.string.paid_plugin);
}
- @Override
- public String getPlanTypeButtonTitle() {
- InAppPurchaseHelper purchaseHelper = getOsmandApplication().getInAppPurchaseHelper();
- return getString(R.string.purchase_unlim_title, purchaseHelper.getContourLines().getPrice(getContext()));
- }
-
@Override
public String getPlanTypeButtonDescription() {
return getString(R.string.in_app_purchase_desc);
@@ -88,4 +84,14 @@ public class ChoosePlanHillshadeSrtmDialogFragment extends ChoosePlanDialogFragm
}
});
}
+
+ @Nullable
+ @Override
+ public InAppPurchase getPlanTypePurchase() {
+ InAppPurchaseHelper purchaseHelper = getOsmandApplication().getInAppPurchaseHelper();
+ if (purchaseHelper != null) {
+ return purchaseHelper.getContourLines();
+ }
+ return null;
+ }
}
diff --git a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanSeaDepthMapsDialogFragment.java b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanSeaDepthMapsDialogFragment.java
index b31eb52c17..f80cbc8e05 100644
--- a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanSeaDepthMapsDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanSeaDepthMapsDialogFragment.java
@@ -1,11 +1,13 @@
package net.osmand.plus.chooseplan;
import android.app.Activity;
+import android.support.annotation.Nullable;
import android.view.View;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandInAppPurchaseActivity;
import net.osmand.plus.inapp.InAppPurchaseHelper;
+import net.osmand.plus.inapp.InAppPurchases.InAppPurchase;
public class ChoosePlanSeaDepthMapsDialogFragment extends ChoosePlanDialogFragment {
public static final String TAG = ChoosePlanSeaDepthMapsDialogFragment.class.getSimpleName();
@@ -64,12 +66,6 @@ public class ChoosePlanSeaDepthMapsDialogFragment extends ChoosePlanDialogFragme
return getString(R.string.in_app_purchase);
}
- @Override
- public String getPlanTypeButtonTitle() {
- InAppPurchaseHelper purchaseHelper = getOsmandApplication().getInAppPurchaseHelper();
- return getString(R.string.purchase_unlim_title, purchaseHelper.getDepthContours().getPrice(getContext()));
- }
-
@Override
public String getPlanTypeButtonDescription() {
return getString(R.string.in_app_purchase_desc);
@@ -87,4 +83,14 @@ public class ChoosePlanSeaDepthMapsDialogFragment extends ChoosePlanDialogFragme
}
});
}
+
+ @Nullable
+ @Override
+ public InAppPurchase getPlanTypePurchase() {
+ InAppPurchaseHelper purchaseHelper = getOsmandApplication().getInAppPurchaseHelper();
+ if (purchaseHelper != null) {
+ return purchaseHelper.getDepthContours();
+ }
+ return null;
+ }
}
diff --git a/OsmAnd/src/net/osmand/plus/chooseplan/OsmLiveCancelledDialog.java b/OsmAnd/src/net/osmand/plus/chooseplan/OsmLiveCancelledDialog.java
index a2475939f8..9dac53298c 100644
--- a/OsmAnd/src/net/osmand/plus/chooseplan/OsmLiveCancelledDialog.java
+++ b/OsmAnd/src/net/osmand/plus/chooseplan/OsmLiveCancelledDialog.java
@@ -194,46 +194,29 @@ public class OsmLiveCancelledDialog extends BaseOsmAndDialogFragment implements
ProgressBar progressBar = (ProgressBar) osmLiveButton.findViewById(R.id.card_button_progress);
TextViewEx buttonTitle = (TextViewEx) osmLiveButton.findViewById(R.id.card_button_title);
TextViewEx buttonSubtitle = (TextViewEx) osmLiveButton.findViewById(R.id.card_button_subtitle);
- /*
- if (!purchaseHelper.hasPrices()) {
- buttonTitle.setText(getString(R.string.purchase_subscription_title, getString(R.string.osm_live_default_price)));
- } else {
- buttonTitle.setText(getString(R.string.purchase_subscription_title, purchaseHelper.getLiveUpdatesPrice()));
- }
- */
- buttonSubtitle.setText(R.string.osm_live_month_cost_desc);
+ buttonTitle.setText(getString(R.string.osm_live_plan_pricing));
+ buttonSubtitle.setVisibility(View.GONE);
if (progress) {
buttonTitle.setVisibility(View.GONE);
- buttonSubtitle.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE);
osmLiveButton.setOnClickListener(null);
} else {
buttonTitle.setVisibility(View.VISIBLE);
- buttonSubtitle.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
osmLiveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- subscript();
dismiss();
+ FragmentActivity activity = getActivity();
+ if (activity != null) {
+ ChoosePlanDialogFragment.showOsmLiveInstance(activity.getSupportFragmentManager());
+ }
}
});
}
}
}
- private void subscript() {
- FragmentActivity ctx = getActivity();
- if (ctx != null && purchaseHelper != null) {
- OsmandSettings settings = app.getSettings();
- purchaseHelper.purchaseLiveUpdates(ctx, "",
- settings.BILLING_USER_EMAIL.get(),
- settings.BILLING_USER_NAME.get(),
- settings.BILLING_USER_COUNTRY_DOWNLOAD_NAME.get(),
- settings.BILLING_HIDE_USER_NAME.get());
- }
- }
-
public static boolean shouldShowDialog(OsmandApplication app) {
OsmandSettings settings = app.getSettings();
long cancelledTime = settings.LIVE_UPDATES_PURCHASE_CANCELLED_TIME.get();