forked from organicmaps/organicmaps
[android] Removed redundant code regarding purchase and wrong querying product details
This commit is contained in:
parent
018f228cca
commit
9e40b3afec
6 changed files with 22 additions and 123 deletions
|
@ -467,7 +467,7 @@ public class AdsRemovalPurchaseDialog extends BaseMwmDialogFragment
|
|||
P1W;
|
||||
|
||||
@Nullable
|
||||
public static Period getInstance(@Nullable String subscriptionPeriod)
|
||||
static Period getInstance(@Nullable String subscriptionPeriod)
|
||||
{
|
||||
for (Period each : values())
|
||||
{
|
||||
|
|
|
@ -40,18 +40,6 @@ class PlayStoreBillingManager implements BillingManager<PlayStoreBillingCallback
|
|||
mProductType = productType;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected String getProductType()
|
||||
{
|
||||
return mProductType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected PlayStoreBillingCallback getCallback()
|
||||
{
|
||||
return mCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(@NonNull Activity context)
|
||||
{
|
||||
|
@ -90,7 +78,7 @@ class PlayStoreBillingManager implements BillingManager<PlayStoreBillingCallback
|
|||
purchaseToken));
|
||||
}
|
||||
|
||||
protected void executeBillingRequest(@NonNull BillingRequest request)
|
||||
private void executeBillingRequest(@NonNull BillingRequest request)
|
||||
{
|
||||
switch (mConnection.getState())
|
||||
{
|
||||
|
@ -177,7 +165,7 @@ class PlayStoreBillingManager implements BillingManager<PlayStoreBillingCallback
|
|||
}
|
||||
|
||||
@NonNull
|
||||
protected BillingClient getClientOrThrow()
|
||||
private BillingClient getClientOrThrow()
|
||||
{
|
||||
if (mBillingClient == null)
|
||||
throw new IllegalStateException("Manager must be initialized! Call 'initialize' method first.");
|
||||
|
|
|
@ -21,7 +21,7 @@ public class PurchaseFactory
|
|||
@NonNull Context context)
|
||||
{
|
||||
BillingManager<PlayStoreBillingCallback> billingManager
|
||||
= new SubscriptionPlayStoreBillingManager(BillingClient.SkuType.SUBS);
|
||||
= new PlayStoreBillingManager(BillingClient.SkuType.SUBS);
|
||||
PurchaseValidationObservable observable = PurchaseValidationObservable.from(context);
|
||||
PurchaseValidator<ValidationCallback> validator = new DefaultPurchaseValidator(observable);
|
||||
String yearlyProduct = PrivateVariables.adsRemovalYearlyProductId();
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.support.annotation.Nullable;
|
|||
import com.android.billingclient.api.BillingClient;
|
||||
import com.android.billingclient.api.SkuDetails;
|
||||
import com.android.billingclient.api.SkuDetailsParams;
|
||||
import com.mapswithme.util.CrashlyticsUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -48,7 +49,7 @@ class QueryProductDetailsRequest extends PlayStoreBillingRequest<PlayStoreBillin
|
|||
return;
|
||||
}
|
||||
|
||||
if (skuDetails == null || skuDetails.isEmpty() || hasIncorrectSkuDetails(skuDetails))
|
||||
if (skuDetails == null || skuDetails.isEmpty())
|
||||
{
|
||||
LOGGER.w(TAG, "Purchase details not found");
|
||||
if (getCallback() != null)
|
||||
|
@ -56,17 +57,30 @@ class QueryProductDetailsRequest extends PlayStoreBillingRequest<PlayStoreBillin
|
|||
return;
|
||||
}
|
||||
|
||||
if (hasIncorrectSkuDetails(skuDetails))
|
||||
{
|
||||
LOGGER.w(TAG, "Purchase details incorrect");
|
||||
if (getCallback() != null)
|
||||
getCallback().onPurchaseDetailsFailure();
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.i(TAG, "Purchase details obtained: " + skuDetails);
|
||||
if (getCallback() != null)
|
||||
getCallback().onPurchaseDetailsLoaded(skuDetails);
|
||||
}
|
||||
|
||||
private boolean hasIncorrectSkuDetails(@NonNull List<SkuDetails> skuDetails)
|
||||
private static boolean hasIncorrectSkuDetails(@NonNull List<SkuDetails> skuDetails)
|
||||
{
|
||||
for (SkuDetails each : skuDetails)
|
||||
{
|
||||
if (AdsRemovalPurchaseDialog.Period.getInstance(each.getSubscriptionPeriod()) == null)
|
||||
{
|
||||
String msg = "Unsupported subscription period: '" + each.getSubscriptionPeriod() + "'";
|
||||
CrashlyticsUtils.logException(new IllegalStateException(msg));
|
||||
LOGGER.e(TAG, msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,104 +0,0 @@
|
|||
package com.mapswithme.maps.purchase;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.android.billingclient.api.Purchase;
|
||||
import com.android.billingclient.api.SkuDetails;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class SubscriptionPlayStoreBillingManager extends PlayStoreBillingManager
|
||||
{
|
||||
SubscriptionPlayStoreBillingManager(@NonNull String productType)
|
||||
{
|
||||
super(productType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queryProductDetails(@NonNull List<String> productIds)
|
||||
{
|
||||
executeBillingRequest(new QueryExistingPurchases(getClientOrThrow(), getProductType(),
|
||||
new QueryExistingPurchaseCallback(productIds)));
|
||||
}
|
||||
|
||||
private class QueryExistingPurchaseCallback implements PlayStoreBillingCallback
|
||||
{
|
||||
@NonNull
|
||||
private final List<String> mProductIds;
|
||||
|
||||
public QueryExistingPurchaseCallback(@NonNull List<String> productIds)
|
||||
{
|
||||
mProductIds = productIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchaseDetailsLoaded(@NonNull List<SkuDetails> details)
|
||||
{
|
||||
if (getCallback() != null)
|
||||
getCallback().onPurchaseDetailsLoaded(details);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchaseSuccessful(@NonNull List<Purchase> purchases)
|
||||
{
|
||||
if (getCallback() != null)
|
||||
getCallback().onPurchaseSuccessful(purchases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchaseFailure(int error)
|
||||
{
|
||||
if (getCallback() != null)
|
||||
getCallback().onPurchaseFailure(error);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchaseDetailsFailure()
|
||||
{
|
||||
if (getCallback() != null)
|
||||
getCallback().onPurchaseDetailsFailure();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStoreConnectionFailed()
|
||||
{
|
||||
if (getCallback() != null)
|
||||
getCallback().onStoreConnectionFailed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchasesLoaded(@NonNull List<Purchase> purchases)
|
||||
{
|
||||
if (purchases.isEmpty())
|
||||
launchDefaultFlow();
|
||||
else
|
||||
validateExistingPurchases(purchases);
|
||||
}
|
||||
|
||||
private void validateExistingPurchases(@NonNull List<Purchase> purchases)
|
||||
{
|
||||
if (getCallback() != null)
|
||||
getCallback().onPurchasesLoaded(purchases);
|
||||
}
|
||||
|
||||
private void launchDefaultFlow()
|
||||
{
|
||||
executeBillingRequest(new QueryProductDetailsRequest(getClientOrThrow(), getProductType(),
|
||||
getCallback(), mProductIds));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConsumptionSuccess()
|
||||
{
|
||||
if (getCallback() != null)
|
||||
getCallback().onConsumptionSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConsumptionFailure()
|
||||
{
|
||||
if (getCallback() != null)
|
||||
getCallback().onConsumptionFailure();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -684,7 +684,8 @@ public class Utils
|
|||
}
|
||||
}
|
||||
|
||||
public static <T> T[] concatArrays(T[] a, T... b)
|
||||
@NonNull
|
||||
public static <T> T[] concatArrays(@Nullable T[] a, T... b)
|
||||
{
|
||||
if (a == null || a.length == 0)
|
||||
return b;
|
||||
|
|
Loading…
Add table
Reference in a new issue