Fix old live updates in-apps
This commit is contained in:
parent
78d29e470d
commit
b406f76920
3 changed files with 39 additions and 10 deletions
|
@ -154,6 +154,11 @@ public class InAppPurchaseHelper {
|
|||
return purchases.getMonthlyLiveUpdates();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public InAppSubscription getPurchasedMonthlyLiveUpdates() {
|
||||
return purchases.getPurchasedMonthlyLiveUpdates();
|
||||
}
|
||||
|
||||
public InAppPurchaseHelper(OsmandApplication ctx) {
|
||||
this.ctx = ctx;
|
||||
isDeveloperVersion = Version.isDeveloperVersion(ctx);
|
||||
|
|
|
@ -48,6 +48,7 @@ public class InAppPurchases {
|
|||
private InAppPurchase depthContours;
|
||||
private InAppPurchase contourLines;
|
||||
private InAppSubscription monthlyLiveUpdates;
|
||||
private InAppSubscription discountedMonthlyLiveUpdates;
|
||||
private InAppSubscriptionList liveUpdates;
|
||||
|
||||
InAppPurchases(OsmandApplication ctx) {
|
||||
|
@ -59,8 +60,11 @@ public class InAppPurchases {
|
|||
}
|
||||
for (InAppSubscription s : liveUpdates.getAllSubscriptions()) {
|
||||
if (s instanceof InAppPurchaseLiveUpdatesMonthly) {
|
||||
monthlyLiveUpdates = s;
|
||||
break;
|
||||
if (s.isDiscounted()) {
|
||||
discountedMonthlyLiveUpdates = s;
|
||||
} else {
|
||||
monthlyLiveUpdates = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Version.isFreeVersion(ctx)) {
|
||||
|
@ -91,6 +95,16 @@ public class InAppPurchases {
|
|||
return monthlyLiveUpdates;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public InAppSubscription getPurchasedMonthlyLiveUpdates() {
|
||||
if (monthlyLiveUpdates.isAnyPurchased()) {
|
||||
return monthlyLiveUpdates;
|
||||
} else if (discountedMonthlyLiveUpdates.isAnyPurchased()) {
|
||||
return discountedMonthlyLiveUpdates;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public InAppSubscriptionList getLiveUpdates() {
|
||||
return liveUpdates;
|
||||
}
|
||||
|
@ -559,17 +573,22 @@ public class InAppPurchases {
|
|||
|
||||
InAppPurchaseLiveUpdatesMonthly(String skuNoVersion, int version) {
|
||||
super(skuNoVersion, version);
|
||||
donationSupported = true;
|
||||
}
|
||||
|
||||
InAppPurchaseLiveUpdatesMonthly(@NonNull String sku, boolean discounted) {
|
||||
super(sku, discounted);
|
||||
donationSupported = true;
|
||||
}
|
||||
|
||||
InAppPurchaseLiveUpdatesMonthly(@NonNull String sku) {
|
||||
super(sku, false);
|
||||
this(sku, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriceValue(double priceValue) {
|
||||
super.setPriceValue(priceValue);
|
||||
monthlyPriceValue = priceValue;
|
||||
donationSupported = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -789,9 +808,9 @@ public class InAppPurchases {
|
|||
}
|
||||
}
|
||||
|
||||
public static class InAppPurchaseLiveUpdatesOldMonthly extends InAppSubscription {
|
||||
public static class InAppPurchaseLiveUpdatesOldMonthly extends InAppPurchaseLiveUpdatesMonthly {
|
||||
|
||||
private InAppPurchaseLiveUpdatesOldMonthly(String sku) {
|
||||
InAppPurchaseLiveUpdatesOldMonthly(String sku) {
|
||||
super(sku, true);
|
||||
}
|
||||
|
||||
|
@ -800,6 +819,11 @@ public class InAppPurchases {
|
|||
return ctx.getString(R.string.osm_live_default_price);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultMonthlyPrice(Context ctx) {
|
||||
return ctx.getString(R.string.osm_live_default_price);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected InAppSubscription newInstance(@NonNull String sku) {
|
||||
|
|
|
@ -192,8 +192,8 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
|
|||
String countryName = getSettings().BILLING_USER_COUNTRY.get();
|
||||
InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper();
|
||||
if (purchaseHelper != null) {
|
||||
InAppSubscription s = purchaseHelper.getMonthlyLiveUpdates();
|
||||
if (s.isDonationSupported() && s.isAnyPurchased()) {
|
||||
InAppSubscription monthlyPurchased = purchaseHelper.getPurchasedMonthlyLiveUpdates();
|
||||
if (monthlyPurchased != null && monthlyPurchased.isDonationSupported()) {
|
||||
if (Algorithms.isEmpty(countryName)) {
|
||||
if (getSettings().BILLING_USER_COUNTRY_DOWNLOAD_NAME.get().equals(OsmandSettings.BILLING_USER_DONATION_NONE_PARAMETER)) {
|
||||
regionNameHeaderTextView.setText(R.string.default_buttons_support);
|
||||
|
@ -324,8 +324,8 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
|
|||
private boolean isDonationSupported() {
|
||||
InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper();
|
||||
if (purchaseHelper != null) {
|
||||
InAppSubscription s = purchaseHelper.getMonthlyLiveUpdates();
|
||||
return s.isDonationSupported() && s.isAnyPurchased();
|
||||
InAppSubscription monthlyPurchased = purchaseHelper.getPurchasedMonthlyLiveUpdates();
|
||||
return monthlyPurchased != null && monthlyPurchased.isDonationSupported();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue