Fix billing and choose plan UI
This commit is contained in:
parent
b71194d7fc
commit
90c502a0ce
4 changed files with 38 additions and 19 deletions
|
@ -70,7 +70,7 @@
|
|||
android:layout_gravity="center"
|
||||
android:layout_marginStart="@dimen/list_header_padding"
|
||||
android:layout_marginLeft="@dimen/list_header_padding"
|
||||
android:src="@drawable/ic_action_singleselect" />
|
||||
android:src="@drawable/img_feature_purchased" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -353,7 +353,6 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
|
|||
for (final InAppSubscription s : visibleSubscriptions) {
|
||||
InAppSubscriptionIntroductoryInfo introductoryInfo = s.getIntroductoryInfo();
|
||||
boolean hasIntroductoryInfo = introductoryInfo != null;
|
||||
CharSequence priceTitle = hasIntroductoryInfo ? introductoryInfo.getFormattedDescription(ctx) : s.getPrice(ctx);
|
||||
CharSequence descriptionText = hasIntroductoryInfo ?
|
||||
introductoryInfo.getDescriptionTitle(ctx) : s.getDescription(ctx, purchaseHelper.getMonthlyLiveUpdates());
|
||||
if (s.isPurchased()) {
|
||||
|
@ -366,8 +365,10 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
|
|||
View buttonView = buttonPurchased.findViewById(R.id.button_view);
|
||||
View buttonCancelView = buttonPurchased.findViewById(R.id.button_cancel_view);
|
||||
View div = buttonPurchased.findViewById(R.id.div);
|
||||
AppCompatImageView rightImage = buttonPurchased.findViewById(R.id.right_image);
|
||||
AppCompatImageView rightImage = (AppCompatImageView) buttonPurchased.findViewById(R.id.right_image);
|
||||
|
||||
CharSequence priceTitle = hasIntroductoryInfo ?
|
||||
introductoryInfo.getFormattedDescription(ctx, buttonTitle.getCurrentTextColor()) : s.getPrice(ctx);
|
||||
title.setText(s.getTitle(ctx));
|
||||
description.setText(descriptionText);
|
||||
buttonTitle.setText(priceTitle);
|
||||
|
@ -395,13 +396,13 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
|
|||
buttonView = buttonCancel.findViewById(R.id.button_view);
|
||||
buttonCancelView = buttonCancel.findViewById(R.id.button_cancel_view);
|
||||
div = buttonCancel.findViewById(R.id.div);
|
||||
rightImage = buttonPurchased.findViewById(R.id.right_image);
|
||||
rightImage = (AppCompatImageView) buttonCancel.findViewById(R.id.right_image);
|
||||
|
||||
title.setText(getString(R.string.osm_live_payment_current_subscription));
|
||||
description.setText(s.getRenewDescription(ctx));
|
||||
buttonView.setVisibility(View.GONE);
|
||||
buttonCancelView.setVisibility(View.VISIBLE);
|
||||
buttonCancel.setOnClickListener(new OnClickListener() {
|
||||
buttonCancelView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
manageSubscription(ctx, s.getSku());
|
||||
|
@ -426,9 +427,10 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
|
|||
boolean showSolidButton = !anyPurchasedOrIntroducted || hasIntroductoryInfo;
|
||||
buttonView.setVisibility(!showSolidButton ? View.VISIBLE : View.GONE);
|
||||
buttonExView.setVisibility(showSolidButton ? View.VISIBLE : View.GONE);
|
||||
|
||||
View div = button.findViewById(R.id.div);
|
||||
|
||||
CharSequence priceTitle = hasIntroductoryInfo ?
|
||||
introductoryInfo.getFormattedDescription(ctx, buttonExTitle.getCurrentTextColor()) : s.getPrice(ctx);
|
||||
title.setText(s.getTitle(ctx));
|
||||
description.setText(descriptionText);
|
||||
buttonTitle.setText(priceTitle);
|
||||
|
|
|
@ -240,7 +240,7 @@ public class InAppPurchaseHelper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPurchasesUpdated(List<Purchase> purchases) {
|
||||
public void onPurchasesUpdated(final List<Purchase> purchases) {
|
||||
|
||||
// Have we been disposed of in the meantime? If so, quit.
|
||||
if (billingManager == null) {
|
||||
|
@ -253,6 +253,9 @@ public class InAppPurchaseHelper {
|
|||
for (InAppPurchase purchase : getInAppPurchases().getAllInAppPurchases(false)) {
|
||||
skuInApps.add(purchase.getSku());
|
||||
}
|
||||
for (Purchase p : purchases) {
|
||||
skuInApps.add(p.getSku());
|
||||
}
|
||||
billingManager.querySkuDetailsAsync(SkuType.INAPP, skuInApps, new SkuDetailsResponseListener() {
|
||||
@Override
|
||||
public void onSkuDetailsResponse(BillingResult billingResult, final List<SkuDetails> skuDetailsListInApps) {
|
||||
|
@ -268,6 +271,9 @@ public class InAppPurchaseHelper {
|
|||
for (InAppSubscription subscription : getInAppPurchases().getAllInAppSubscriptions()) {
|
||||
skuSubscriptions.add(subscription.getSku());
|
||||
}
|
||||
for (Purchase p : purchases) {
|
||||
skuSubscriptions.add(p.getSku());
|
||||
}
|
||||
|
||||
// Have we been disposed of in the meantime? If so, quit.
|
||||
if (billingManager == null) {
|
||||
|
@ -415,8 +421,7 @@ public class InAppPurchaseHelper {
|
|||
private List<String> getAllOwnedSubscriptionSkus() {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (Purchase p : billingManager.getPurchases()) {
|
||||
InAppPurchase inAppPurchase = getInAppPurchases().getInAppPurchaseBySku(p.getSku());
|
||||
if (inAppPurchase instanceof InAppSubscription) {
|
||||
if (getInAppPurchases().getInAppSubscriptionBySku(p.getSku()) != null) {
|
||||
result.add(p.getSku());
|
||||
}
|
||||
}
|
||||
|
@ -451,14 +456,14 @@ public class InAppPurchaseHelper {
|
|||
*/
|
||||
|
||||
List<String> allOwnedSubscriptionSkus = getAllOwnedSubscriptionSkus();
|
||||
for (InAppPurchase p : getLiveUpdates().getAllSubscriptions()) {
|
||||
if (hasDetails(p.getSku())) {
|
||||
Purchase purchase = getPurchase(p.getSku());
|
||||
SkuDetails liveUpdatesDetails = getSkuDetails(p.getSku());
|
||||
for (InAppSubscription s : getLiveUpdates().getAllSubscriptions()) {
|
||||
if (hasDetails(s.getSku())) {
|
||||
Purchase purchase = getPurchase(s.getSku());
|
||||
SkuDetails liveUpdatesDetails = getSkuDetails(s.getSku());
|
||||
if (liveUpdatesDetails != null) {
|
||||
fetchInAppPurchase(p, liveUpdatesDetails, purchase);
|
||||
fetchInAppPurchase(s, liveUpdatesDetails, purchase);
|
||||
}
|
||||
allOwnedSubscriptionSkus.remove(p.getSku());
|
||||
allOwnedSubscriptionSkus.remove(s.getSku());
|
||||
}
|
||||
}
|
||||
for (String sku : allOwnedSubscriptionSkus) {
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package net.osmand.plus.inapp;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
|
@ -146,6 +147,16 @@ public class InAppPurchases {
|
|||
return liveUpdates.getAllSubscriptions();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public InAppSubscription getInAppSubscriptionBySku(@NonNull String sku) {
|
||||
for (InAppSubscription s : liveUpdates.getAllSubscriptions()) {
|
||||
if (sku.startsWith(s.getSkuNoVersion())) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isFullVersion(String sku) {
|
||||
return FULL_VERSION.getSku().equals(sku);
|
||||
}
|
||||
|
@ -570,7 +581,7 @@ public class InAppPurchases {
|
|||
return ctx.getString(R.string.get_discount_title, totalPeriods, unitStr, discountPercent + "%");
|
||||
}
|
||||
|
||||
public CharSequence getFormattedDescription(@NonNull Context ctx) {
|
||||
public CharSequence getFormattedDescription(@NonNull Context ctx, @ColorInt int textColor) {
|
||||
long totalPeriods = getTotalPeriods();
|
||||
String singleUnitStr = getUnitString(ctx).toLowerCase();
|
||||
String unitStr = getTotalUnitsString(ctx, false).toLowerCase();
|
||||
|
@ -614,9 +625,10 @@ public class InAppPurchases {
|
|||
SpannableStringBuilder thenPart = new SpannableStringBuilder(ctx.getString(R.string.get_discount_second_part, originalPricePeriod));
|
||||
Typeface typefaceRegular = FontCache.getRobotoRegular(ctx);
|
||||
Typeface typefaceBold = FontCache.getRobotoMedium(ctx);
|
||||
mainPart.setSpan(new ForegroundColorSpan(textColor), 0, mainPart.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
mainPart.setSpan(new CustomTypefaceSpan(typefaceBold), 0, mainPart.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
int textColor = ContextCompat.getColor(ctx, R.color.white_50_transparent);
|
||||
thenPart.setSpan(new ForegroundColorSpan(textColor), 0, thenPart.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
int secondaryTextColor = Color.argb(128, Color.red(textColor), Color.green(textColor), Color.blue(textColor));
|
||||
thenPart.setSpan(new ForegroundColorSpan(secondaryTextColor), 0, thenPart.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
thenPart.setSpan(new CustomTypefaceSpan(typefaceRegular), 0, thenPart.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
|
||||
return new SpannableStringBuilder(mainPart).append("\n").append(thenPart);
|
||||
|
|
Loading…
Reference in a new issue