Fix subscription UI issues

This commit is contained in:
crimean 2018-11-02 16:42:59 +03:00
parent 1ee6f36724
commit 855b717dfe
9 changed files with 214 additions and 54 deletions

View file

@ -43,6 +43,7 @@
android:layout_margin="@dimen/card_padding">
<include layout="@layout/purchase_dialog_card_button"/>
<include layout="@layout/purchase_dialog_card_button_disabled"/>
</FrameLayout>

View file

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/wikivoyage_secondary_btn_bg">
<LinearLayout
android:id="@+id/card_button_disabled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:minHeight="@dimen/card_button_min_size"
android:orientation="vertical"
android:paddingLeft="@dimen/list_content_padding"
android:paddingTop="@dimen/list_header_padding"
android:paddingRight="@dimen/list_content_padding"
android:paddingBottom="@dimen/list_header_padding">
<ProgressBar
android:id="@+id/card_button_progress"
android:layout_width="@dimen/card_button_progress_size"
android:layout_height="@dimen/card_button_progress_size"
android:indeterminate="true"
android:visibility="gone" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/card_button_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:textColor="@color/wikivoyage_secondary_text"
android:textSize="@dimen/text_button_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="Buy - 5€" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/card_button_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:textColor="@color/wikivoyage_secondary_text"
android:textSize="@dimen/text_button_text_size"
osmand:typeface="@string/font_roboto_regular"
tools:text="One time purchase" />
</LinearLayout>
</FrameLayout>

View file

@ -47,8 +47,9 @@
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="?attr/card_description_text_color"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular"
@ -58,6 +59,7 @@
android:id="@+id/discount_banner_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginStart="@dimen/list_item_button_padding"
android:layout_marginLeft="@dimen/list_item_button_padding"
android:background="?attr/text_rounded_bg_regular"
@ -70,6 +72,7 @@
android:id="@+id/discount_banner_active"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginStart="@dimen/list_item_button_padding"
android:layout_marginLeft="@dimen/list_item_button_padding"
android:background="?attr/text_rounded_bg_active"
@ -83,6 +86,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/button_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -92,6 +96,7 @@
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_height"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:orientation="horizontal"
android:padding="@dimen/list_header_padding">
@ -120,6 +125,39 @@
</LinearLayout>
<LinearLayout
android:id="@+id/button_ex_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="?attr/wikivoyage_primary_btn_bg">
<LinearLayout
android:id="@+id/button_ex"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_height"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:orientation="horizontal"
android:padding="@dimen/list_header_padding">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_ex_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:maxWidth="@dimen/dialog_button_ex_max_width"
android:minWidth="@dimen/dialog_button_ex_min_width"
android:textColor="@color/color_white"
android:textSize="@dimen/text_button_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="7,99€" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<View

View file

@ -10,6 +10,7 @@
- For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
Thx - Hardy
-->
<string name="osm_live_plan_pricing">Plan &amp; Pricing</string>
<string name="osm_live_payment_monthly_title">Pay monthly</string>
<string name="osm_live_payment_3_months_title">Pay once in 3 months</string>
<string name="osm_live_payment_annual_title">Pay once a year</string>

View file

@ -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<InAppSubscription> 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);
}
}

View file

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

View file

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

View file

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

View file

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