forked from organicmaps/organicmaps
[android] Added ui callback into ads removal purchase controller
This commit is contained in:
parent
ee64e1a86b
commit
6a2bdc0451
5 changed files with 50 additions and 7 deletions
|
@ -2,13 +2,16 @@ package com.mapswithme.maps.purchase;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
abstract class AbstractPurchaseController<V, B> implements PurchaseController
|
||||
abstract class AbstractPurchaseController<V, B, UiCallback> implements PurchaseController<UiCallback>
|
||||
{
|
||||
@NonNull
|
||||
private final PurchaseValidator<V> mValidator;
|
||||
@NonNull
|
||||
private final BillingManager<B> mBillingManager;
|
||||
@Nullable
|
||||
private UiCallback mUiCallback;
|
||||
|
||||
AbstractPurchaseController(@NonNull PurchaseValidator<V> validator,
|
||||
@NonNull BillingManager<B> billingManager)
|
||||
|
@ -33,6 +36,24 @@ abstract class AbstractPurchaseController<V, B> implements PurchaseController
|
|||
onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCallback(@NonNull UiCallback callback)
|
||||
{
|
||||
mUiCallback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCallback()
|
||||
{
|
||||
mUiCallback = null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
UiCallback getUiCallback()
|
||||
{
|
||||
return mUiCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPurchaseDone()
|
||||
{
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package com.mapswithme.maps.purchase;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.android.billingclient.api.SkuDetails;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AdsRemovalPurchaseCallback
|
||||
{
|
||||
void onProductDetailsLoaded(@NonNull List<SkuDetails> details);
|
||||
void onFailure();
|
||||
}
|
|
@ -13,7 +13,8 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
class AdsRemovalPurchaseController extends AbstractPurchaseController<AdsRemovalValidationCallback, PlayStoreBillingCallback>
|
||||
class AdsRemovalPurchaseController extends AbstractPurchaseController<AdsRemovalValidationCallback,
|
||||
PlayStoreBillingCallback, AdsRemovalPurchaseCallback>
|
||||
{
|
||||
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.BILLING);
|
||||
private static final String TAG = AdsRemovalPurchaseController.class.getSimpleName();
|
||||
|
@ -62,7 +63,8 @@ class AdsRemovalPurchaseController extends AbstractPurchaseController<AdsRemoval
|
|||
@Override
|
||||
public void onPurchaseDetailsLoaded(@NonNull List<SkuDetails> details)
|
||||
{
|
||||
// Coming soon.
|
||||
if (getUiCallback() != null)
|
||||
getUiCallback().onProductDetailsLoaded(details);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -79,7 +81,8 @@ class AdsRemovalPurchaseController extends AbstractPurchaseController<AdsRemoval
|
|||
@Override
|
||||
public void onPurchaseFailure()
|
||||
{
|
||||
// Coming soon.
|
||||
if (getUiCallback() != null)
|
||||
getUiCallback().onFailure();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,7 +8,7 @@ import android.support.annotation.NonNull;
|
|||
* process. This controller has to be used only within {@link #initialize(Activity)} and {@link #destroy()}
|
||||
* interval.
|
||||
*/
|
||||
public interface PurchaseController
|
||||
public interface PurchaseController<T>
|
||||
{
|
||||
/**
|
||||
* Initializes the controller.
|
||||
|
@ -32,11 +32,16 @@ public interface PurchaseController
|
|||
boolean isPurchaseSupported();
|
||||
|
||||
/**
|
||||
* Launches the purchase flow for the specified product.
|
||||
* Launches the purchase flow for the specified product. The purchase results will be delivered
|
||||
* through {@link T} callback.
|
||||
*
|
||||
* @param productId id of the product which is going to be purchased.
|
||||
*/
|
||||
void launchPurchaseFlow(@NonNull String productId);
|
||||
|
||||
void addCallback(@NonNull T callback);
|
||||
|
||||
void removeCallback();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,7 +27,8 @@ public enum PurchaseFactory
|
|||
{
|
||||
BillingManager<PlayStoreBillingCallback> billingManager = createBillingManager();
|
||||
PurchaseValidator<AdsRemovalValidationCallback> validator = createPurchaseValidator();
|
||||
return new AdsRemovalPurchaseController(validator, billingManager, "ads.removal.monthly.test");
|
||||
return new AdsRemovalPurchaseController(validator, billingManager,
|
||||
"ads.removal.monthly.test");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue