Search in sources :

Example 1 with InAppSubscription

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

the class OsmAndProPlanFragment method getVisibleSubscriptions.

public static List<InAppSubscription> getVisibleSubscriptions(OsmandApplication app, InAppPurchaseHelper purchaseHelper) {
    InAppPurchases purchases = app.getInAppPurchaseHelper().getInAppPurchases();
    List<InAppSubscription> subscriptions = new ArrayList<>();
    List<InAppSubscription> visibleSubscriptions = purchaseHelper.getSubscriptions().getVisibleSubscriptions();
    for (InAppSubscription subscription : visibleSubscriptions) {
        if (purchases.isOsmAndProSubscription(subscription)) {
            subscriptions.add(subscription);
        }
    }
    return subscriptions;
}
Also used : ArrayList(java.util.ArrayList) InAppPurchases(net.osmand.plus.inapp.InAppPurchases) InAppSubscription(net.osmand.plus.inapp.InAppPurchases.InAppSubscription)

Example 2 with InAppSubscription

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

the class MapsPlusPlanFragment method collectPriceButtons.

public static List<PriceButton<?>> collectPriceButtons(OsmandApplication app, InAppPurchaseHelper purchaseHelper, boolean nightMode) {
    List<InAppSubscription> subscriptions = getVisibleSubscriptions(app, purchaseHelper);
    List<PriceButton<?>> priceButtons = new ArrayList<>(PurchasingUtils.collectSubscriptionButtons(app, purchaseHelper, subscriptions, nightMode));
    OneTimePaymentButton oneTimePaymentButton = PurchasingUtils.getOneTimePaymentButton(app);
    if (oneTimePaymentButton != null) {
        priceButtons.add(oneTimePaymentButton);
    }
    return priceButtons;
}
Also used : PriceButton(net.osmand.plus.chooseplan.button.PriceButton) ArrayList(java.util.ArrayList) OneTimePaymentButton(net.osmand.plus.chooseplan.button.OneTimePaymentButton) InAppSubscription(net.osmand.plus.inapp.InAppPurchases.InAppSubscription)

Example 3 with InAppSubscription

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

the class MapsPlusPlanFragment method getVisibleSubscriptions.

protected static List<InAppSubscription> getVisibleSubscriptions(OsmandApplication app, InAppPurchaseHelper purchaseHelper) {
    InAppPurchases purchases = app.getInAppPurchaseHelper().getInAppPurchases();
    List<InAppSubscription> subscriptions = new ArrayList<>();
    List<InAppSubscription> visibleSubscriptions = purchaseHelper.getSubscriptions().getVisibleSubscriptions();
    for (InAppSubscription subscription : visibleSubscriptions) {
        if (purchases.isMapsSubscription(subscription)) {
            subscriptions.add(subscription);
        }
    }
    return subscriptions;
}
Also used : ArrayList(java.util.ArrayList) InAppPurchases(net.osmand.plus.inapp.InAppPurchases) InAppSubscription(net.osmand.plus.inapp.InAppPurchases.InAppSubscription)

Example 4 with InAppSubscription

use of net.osmand.plus.inapp.InAppPurchases.InAppSubscription 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 5 with InAppSubscription

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

the class InAppPurchaseHelperImpl method fetchInAppPurchase.

private void fetchInAppPurchase(@NonNull InAppPurchase inAppPurchase, @NonNull SkuDetails skuDetails, @Nullable Purchase purchase) {
    if (purchase != null) {
        inAppPurchase.setPurchaseState(PurchaseState.PURCHASED);
        inAppPurchase.setPurchaseInfo(ctx, getPurchaseInfo(purchase));
    } else {
        inAppPurchase.setPurchaseState(PurchaseState.NOT_PURCHASED);
        inAppPurchase.restorePurchaseInfo(ctx);
    }
    inAppPurchase.setPrice(skuDetails.getPrice());
    inAppPurchase.setOriginalPrice(skuDetails.getOriginalPrice());
    inAppPurchase.setPriceCurrencyCode(skuDetails.getPriceCurrencyCode());
    if (skuDetails.getPriceAmountMicros() > 0) {
        inAppPurchase.setPriceValue(skuDetails.getPriceAmountMicros() / 1000000d);
    }
    if (skuDetails.getOriginalPriceAmountMicros() > 0) {
        inAppPurchase.setOriginalPriceValue(skuDetails.getOriginalPriceAmountMicros() / 1000000d);
    }
    String subscriptionPeriod = skuDetails.getSubscriptionPeriod();
    if (!Algorithms.isEmpty(subscriptionPeriod)) {
        if (inAppPurchase instanceof InAppSubscription) {
            try {
                ((InAppSubscription) inAppPurchase).setSubscriptionPeriodString(subscriptionPeriod);
            } catch (ParseException e) {
                LOG.error(e);
            }
        }
    }
    if (inAppPurchase instanceof InAppSubscription) {
        InAppSubscription s = (InAppSubscription) inAppPurchase;
        s.restoreState(ctx);
        s.restoreExpireTime(ctx);
        SubscriptionStateHolder stateHolder = subscriptionStateMap.get(s.getSku());
        if (stateHolder != null) {
            s.setState(ctx, stateHolder.state);
            s.setExpireTime(ctx, stateHolder.expireTime);
        }
        if (s.getState().isGone() && s.hasStateChanged()) {
            ctx.getSettings().LIVE_UPDATES_EXPIRED_FIRST_DLG_SHOWN_TIME.set(0L);
            ctx.getSettings().LIVE_UPDATES_EXPIRED_SECOND_DLG_SHOWN_TIME.set(0L);
        }
        String introductoryPrice = skuDetails.getIntroductoryPrice();
        String introductoryPricePeriod = skuDetails.getIntroductoryPricePeriod();
        int introductoryPriceCycles = skuDetails.getIntroductoryPriceCycles();
        long introductoryPriceAmountMicros = skuDetails.getIntroductoryPriceAmountMicros();
        if (!Algorithms.isEmpty(introductoryPrice)) {
            try {
                s.setIntroductoryInfo(new InAppPurchases.InAppSubscriptionIntroductoryInfo(s, introductoryPrice, introductoryPriceAmountMicros, introductoryPricePeriod, introductoryPriceCycles));
            } catch (ParseException e) {
                LOG.error(e);
            }
        }
    }
}
Also used : InAppSubscription(net.osmand.plus.inapp.InAppPurchases.InAppSubscription) ParseException(java.text.ParseException)

Aggregations

InAppSubscription (net.osmand.plus.inapp.InAppPurchases.InAppSubscription)14 ArrayList (java.util.ArrayList)7 ParseException (java.text.ParseException)4 InAppPurchase (net.osmand.plus.inapp.InAppPurchases.InAppPurchase)4 OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)3 NonNull (androidx.annotation.NonNull)2 BillingResult (com.android.billingclient.api.BillingResult)2 Purchase (com.android.billingclient.api.Purchase)2 SkuDetails (com.android.billingclient.api.SkuDetails)2 SkuDetailsResponseListener (com.android.billingclient.api.SkuDetailsResponseListener)2 List (java.util.List)2 InAppPurchases (net.osmand.plus.inapp.InAppPurchases)2 InAppSubscriptionIntroductoryInfo (net.osmand.plus.inapp.InAppPurchases.InAppSubscriptionIntroductoryInfo)2 PurchaseInfo (net.osmand.plus.inapp.InAppPurchases.PurchaseInfo)2 InAppPurchaseLiveUpdatesOldSubscription (net.osmand.plus.inapp.InAppPurchasesImpl.InAppPurchaseLiveUpdatesOldSubscription)2 BillingManager (net.osmand.plus.inapp.util.BillingManager)2 Activity (android.app.Activity)1 Spannable (android.text.Spannable)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1