diff --git a/android/src/com/mapswithme/maps/purchase/AbstractPurchaseController.java b/android/src/com/mapswithme/maps/purchase/AbstractPurchaseController.java index 4d4b7f7584..dedc6266de 100644 --- a/android/src/com/mapswithme/maps/purchase/AbstractPurchaseController.java +++ b/android/src/com/mapswithme/maps/purchase/AbstractPurchaseController.java @@ -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 implements PurchaseController +abstract class AbstractPurchaseController implements PurchaseController { @NonNull private final PurchaseValidator mValidator; @NonNull private final BillingManager mBillingManager; + @Nullable + private UiCallback mUiCallback; AbstractPurchaseController(@NonNull PurchaseValidator validator, @NonNull BillingManager billingManager) @@ -33,6 +36,24 @@ abstract class AbstractPurchaseController 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() { diff --git a/android/src/com/mapswithme/maps/purchase/AdsRemovalPurchaseCallback.java b/android/src/com/mapswithme/maps/purchase/AdsRemovalPurchaseCallback.java new file mode 100644 index 0000000000..ad7f738d68 --- /dev/null +++ b/android/src/com/mapswithme/maps/purchase/AdsRemovalPurchaseCallback.java @@ -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 details); + void onFailure(); +} diff --git a/android/src/com/mapswithme/maps/purchase/AdsRemovalPurchaseController.java b/android/src/com/mapswithme/maps/purchase/AdsRemovalPurchaseController.java index 87cd4a5761..8d296b3da2 100644 --- a/android/src/com/mapswithme/maps/purchase/AdsRemovalPurchaseController.java +++ b/android/src/com/mapswithme/maps/purchase/AdsRemovalPurchaseController.java @@ -13,7 +13,8 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -class AdsRemovalPurchaseController extends AbstractPurchaseController +class AdsRemovalPurchaseController extends AbstractPurchaseController { 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 details) { - // Coming soon. + if (getUiCallback() != null) + getUiCallback().onProductDetailsLoaded(details); } @Override @@ -79,7 +81,8 @@ class AdsRemovalPurchaseController extends AbstractPurchaseController { /** * 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(); } diff --git a/android/src/com/mapswithme/maps/purchase/PurchaseFactory.java b/android/src/com/mapswithme/maps/purchase/PurchaseFactory.java index 740ad0a4c3..d4e0060325 100644 --- a/android/src/com/mapswithme/maps/purchase/PurchaseFactory.java +++ b/android/src/com/mapswithme/maps/purchase/PurchaseFactory.java @@ -27,7 +27,8 @@ public enum PurchaseFactory { BillingManager billingManager = createBillingManager(); PurchaseValidator validator = createPurchaseValidator(); - return new AdsRemovalPurchaseController(validator, billingManager, "ads.removal.monthly.test"); + return new AdsRemovalPurchaseController(validator, billingManager, + "ads.removal.monthly.test"); } };