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;
}
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;
}
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;
}
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;
}
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);
}
}
}
}
Aggregations