Search in sources :

Example 1 with InAppSubscriptionIntroductoryInfo

use of net.osmand.plus.inapp.InAppPurchases.InAppSubscriptionIntroductoryInfo in project Osmand by osmandapp.

the class PurchasingUtils method collectSubscriptionButtons.

public static List<SubscriptionButton> collectSubscriptionButtons(@NonNull OsmandApplication app, @NonNull InAppPurchaseHelper purchaseHelper, @NonNull List<InAppSubscription> subscriptions, boolean nightMode) {
    List<SubscriptionButton> priceButtons = new ArrayList<>();
    InAppSubscription monthlySubscription = purchaseHelper.getMonthlySubscription();
    int primaryTextColor = ColorUtilities.getPrimaryTextColor(app, nightMode);
    for (InAppSubscription subscription : subscriptions) {
        SubscriptionButton subscriptionButton = new SubscriptionButton(subscription.getSku(), subscription);
        subscriptionButton.setTitle(subscription.getTitle(app));
        String discount = subscription.getDiscount(monthlySubscription);
        String discountTitle = subscription.getDiscountTitle(app, monthlySubscription);
        InAppSubscriptionIntroductoryInfo info = subscription.getIntroductoryInfo();
        if (info != null) {
            Pair<Spannable, Spannable> pair = info.getFormattedDescription(app, primaryTextColor);
            subscriptionButton.setDiscount(discount);
            subscriptionButton.setDiscountApplied(!Algorithms.isEmpty(discount));
            subscriptionButton.setPrice(pair.first.toString());
            subscriptionButton.setDescription(pair.second.toString());
        } else {
            subscriptionButton.setPrice(subscription.getPriceWithPeriod(app));
            boolean discountApplied = !Algorithms.stringsEqual(subscription.getPrice(app), subscription.getOriginalPrice(app));
            subscriptionButton.setDiscountApplied(discountApplied);
            subscriptionButton.setDiscount(discountApplied ? discount : discountTitle);
            if (!Algorithms.isEmpty(discount) && discountApplied) {
                String pattern = app.getString(R.string.ltr_or_rtl_combine_via_colon);
                String regularPrice = subscription.getRegularPrice(app);
                subscriptionButton.setDescription(String.format(pattern, app.getString(R.string.regular_price), regularPrice));
            }
        }
        priceButtons.add(subscriptionButton);
    }
    return priceButtons;
}
Also used : InAppSubscriptionIntroductoryInfo(net.osmand.plus.inapp.InAppPurchases.InAppSubscriptionIntroductoryInfo) ArrayList(java.util.ArrayList) InAppSubscription(net.osmand.plus.inapp.InAppPurchases.InAppSubscription) Spannable(android.text.Spannable)

Example 2 with InAppSubscriptionIntroductoryInfo

use of net.osmand.plus.inapp.InAppPurchases.InAppSubscriptionIntroductoryInfo in project Osmand by osmandapp.

the class InAppPurchaseHelperImpl method fetchInAppPurchase.

private void fetchInAppPurchase(@NonNull InAppPurchase inAppPurchase, @NonNull ProductInfo productInfo, @Nullable InAppPurchaseData purchaseData) {
    if (purchaseData != null) {
        inAppPurchase.setPurchaseState(InAppPurchase.PurchaseState.PURCHASED);
        inAppPurchase.setPurchaseInfo(ctx, getPurchaseInfo(purchaseData));
    } else {
        inAppPurchase.setPurchaseState(InAppPurchase.PurchaseState.NOT_PURCHASED);
        inAppPurchase.restorePurchaseInfo(ctx);
    }
    inAppPurchase.setPrice(productInfo.getPrice());
    inAppPurchase.setPriceCurrencyCode(productInfo.getCurrency());
    if (productInfo.getMicrosPrice() > 0) {
        inAppPurchase.setPriceValue(productInfo.getMicrosPrice() / 1000000d);
    }
    String subscriptionPeriod = productInfo.getSubPeriod();
    if (!Algorithms.isEmpty(subscriptionPeriod)) {
        if (inAppPurchase instanceof InAppSubscription) {
            try {
                ((InAppSubscription) inAppPurchase).setSubscriptionPeriodString(subscriptionPeriod);
            } catch (ParseException e) {
                LOG.error(e);
            }
        }
    }
    if (inAppPurchase instanceof InAppSubscription) {
        String introductoryPrice = productInfo.getSubSpecialPrice();
        String introductoryPricePeriod = productInfo.getSubPeriod();
        int introductoryPriceCycles = productInfo.getSubSpecialPeriodCycles();
        long introductoryPriceAmountMicros = productInfo.getSubSpecialPriceMicros();
        if (!Algorithms.isEmpty(introductoryPrice)) {
            InAppSubscription s = (InAppSubscription) inAppPurchase;
            try {
                s.setIntroductoryInfo(new InAppSubscriptionIntroductoryInfo(s, introductoryPrice, introductoryPriceAmountMicros, introductoryPricePeriod, introductoryPriceCycles));
            } catch (ParseException e) {
                LOG.error(e);
            }
        }
    }
}
Also used : InAppSubscriptionIntroductoryInfo(net.osmand.plus.inapp.InAppPurchases.InAppSubscriptionIntroductoryInfo) InAppSubscription(net.osmand.plus.inapp.InAppPurchases.InAppSubscription) ParseException(java.text.ParseException)

Aggregations

InAppSubscription (net.osmand.plus.inapp.InAppPurchases.InAppSubscription)2 InAppSubscriptionIntroductoryInfo (net.osmand.plus.inapp.InAppPurchases.InAppSubscriptionIntroductoryInfo)2 Spannable (android.text.Spannable)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1