forked from organicmaps/organicmaps
[android] Extracted getting of product ids into subscription type class, refactored the purchase factory class
This commit is contained in:
parent
0a77b44e08
commit
4dac25e744
4 changed files with 45 additions and 41 deletions
|
@ -8,8 +8,6 @@ import android.net.Uri;
|
|||
import android.net.http.SslError;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
|
@ -25,6 +23,8 @@ import android.webkit.WebView;
|
|||
import android.webkit.WebViewClient;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.android.billingclient.api.SkuDetails;
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.PrivateVariables;
|
||||
|
@ -159,7 +159,7 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment
|
|||
mFailedPurchaseController.initialize(requireActivity());
|
||||
mFailedPurchaseController.validateExistingPurchases();
|
||||
mPurchaseChecker = new FailedBookmarkPurchaseChecker();
|
||||
mProductDetailsLoadingManager = PurchaseFactory.createInAppBillingManager(requireContext());
|
||||
mProductDetailsLoadingManager = PurchaseFactory.createInAppBillingManager();
|
||||
mProductDetailsLoadingManager.initialize(requireActivity());
|
||||
mProductDetailsLoadingCallback = new ProductDetailsLoadingCallback();
|
||||
View root = inflater.inflate(R.layout.fragment_bookmarks_catalog, container, false);
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package com.mapswithme.maps.purchase;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.billingclient.api.BillingClient;
|
||||
import com.mapswithme.maps.PrivateVariables;
|
||||
import com.mapswithme.maps.PurchaseOperationObservable;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
||||
public class PurchaseFactory
|
||||
{
|
||||
|
@ -16,41 +14,32 @@ public class PurchaseFactory
|
|||
// Utility class.
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static PurchaseController<PurchaseCallback> createAdsRemovalPurchaseController(
|
||||
@NonNull Context context)
|
||||
{
|
||||
BillingManager<PlayStoreBillingCallback> billingManager
|
||||
= new PlayStoreBillingManager(BillingClient.SkuType.SUBS);
|
||||
PurchaseOperationObservable observable = PurchaseOperationObservable.from(context);
|
||||
PurchaseValidator<ValidationCallback> validator = new DefaultPurchaseValidator(observable);
|
||||
String yearlyProduct = PrivateVariables.adsRemovalYearlyProductId();
|
||||
String monthlyProduct = PrivateVariables.adsRemovalMonthlyProductId();
|
||||
String weeklyProduct = PrivateVariables.adsRemovalWeeklyProductId();
|
||||
String[] productIds = Utils.concatArrays(PrivateVariables.adsRemovalNotUsedList(),
|
||||
yearlyProduct, monthlyProduct, weeklyProduct);
|
||||
return new SubscriptionPurchaseController(validator, billingManager,
|
||||
SubscriptionType.ADS_REMOVAL, productIds);
|
||||
return createSubscriptionPurchaseController(context, SubscriptionType.ADS_REMOVAL);
|
||||
}
|
||||
|
||||
public static PurchaseController<PurchaseCallback> createBookmarksSubscriptionPurchaseController(
|
||||
@NonNull Context context)
|
||||
{
|
||||
return createSubscriptionPurchaseController(context, SubscriptionType.BOOKMARKS);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static PurchaseController<PurchaseCallback> createBookmarksSubscriptionPurchaseController(
|
||||
@NonNull Context context)
|
||||
private static PurchaseController<PurchaseCallback> createSubscriptionPurchaseController(
|
||||
@NonNull Context context, @NonNull SubscriptionType type)
|
||||
{
|
||||
BillingManager<PlayStoreBillingCallback> billingManager
|
||||
= new PlayStoreBillingManager(BillingClient.SkuType.SUBS);
|
||||
PurchaseOperationObservable observable = PurchaseOperationObservable.from(context);
|
||||
PurchaseValidator<ValidationCallback> validator = new DefaultPurchaseValidator(observable);
|
||||
String yearlyProduct = PrivateVariables.bookmarksSubscriptionYearlyProductId();
|
||||
String monthlyProduct = PrivateVariables.bookmarksSubscriptionMonthlyProductId();
|
||||
String[] productIds = Utils.concatArrays(PrivateVariables.bookmarksSubscriptionNotUsedList(),
|
||||
yearlyProduct, monthlyProduct);
|
||||
return new SubscriptionPurchaseController(validator, billingManager,
|
||||
SubscriptionType.BOOKMARKS, productIds);
|
||||
String[] productIds = type.getProductIds();
|
||||
return new SubscriptionPurchaseController(validator, billingManager, type, productIds);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static PurchaseController<PurchaseCallback> createBookmarkPurchaseController(
|
||||
static PurchaseController<PurchaseCallback> createBookmarkPurchaseController(
|
||||
@NonNull Context context, @Nullable String productId, @Nullable String serverId)
|
||||
{
|
||||
BillingManager<PlayStoreBillingCallback> billingManager
|
||||
|
@ -60,13 +49,6 @@ public class PurchaseFactory
|
|||
return new BookmarkPurchaseController(validator, billingManager, productId, serverId);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static PurchaseController<PurchaseCallback> createBookmarkPurchaseController(
|
||||
@NonNull Context context)
|
||||
{
|
||||
return createBookmarkPurchaseController(context, null, null);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static PurchaseController<FailedPurchaseChecker> createFailedBookmarkPurchaseController(
|
||||
@NonNull Context context)
|
||||
|
@ -79,14 +61,13 @@ public class PurchaseFactory
|
|||
}
|
||||
|
||||
@NonNull
|
||||
public static BillingManager<PlayStoreBillingCallback> createInAppBillingManager(
|
||||
@NonNull Context context)
|
||||
public static BillingManager<PlayStoreBillingCallback> createInAppBillingManager()
|
||||
{
|
||||
return new PlayStoreBillingManager(BillingClient.SkuType.INAPP);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static BillingManager<PlayStoreBillingCallback> createSubscriptionBillingManager()
|
||||
static BillingManager<PlayStoreBillingCallback> createSubscriptionBillingManager()
|
||||
{
|
||||
return new PlayStoreBillingManager(BillingClient.SkuType.SUBS);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.mapswithme.maps.purchase;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.mapswithme.maps.PrivateVariables;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
||||
public enum SubscriptionType
|
||||
{
|
||||
|
@ -21,6 +21,16 @@ public enum SubscriptionType
|
|||
{
|
||||
return PrivateVariables.adsRemovalVendor();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
String[] getProductIds()
|
||||
{
|
||||
return Utils.concatArrays(PrivateVariables.adsRemovalNotUsedList(),
|
||||
PrivateVariables.adsRemovalYearlyProductId(),
|
||||
PrivateVariables.adsRemovalMonthlyProductId(),
|
||||
PrivateVariables.adsRemovalWeeklyProductId());
|
||||
}
|
||||
},
|
||||
BOOKMARKS
|
||||
{
|
||||
|
@ -37,6 +47,15 @@ public enum SubscriptionType
|
|||
{
|
||||
return PrivateVariables.bookmarksSubscriptionVendor();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
String[] getProductIds()
|
||||
{
|
||||
return Utils.concatArrays(PrivateVariables.bookmarksSubscriptionNotUsedList(),
|
||||
PrivateVariables.bookmarksSubscriptionYearlyProductId(),
|
||||
PrivateVariables.bookmarksSubscriptionMonthlyProductId());
|
||||
}
|
||||
};
|
||||
|
||||
@NonNull
|
||||
|
@ -44,4 +63,7 @@ public enum SubscriptionType
|
|||
|
||||
@NonNull
|
||||
abstract String getVendor();
|
||||
|
||||
@NonNull
|
||||
abstract String[] getProductIds();
|
||||
}
|
||||
|
|
|
@ -296,15 +296,16 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment
|
|||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||
{
|
||||
mAdsRemovalPurchaseController = PurchaseFactory.createAdsRemovalPurchaseController(getContext());
|
||||
mAdsRemovalPurchaseController.initialize(getActivity());
|
||||
mAdsRemovalPurchaseController = PurchaseFactory.createAdsRemovalPurchaseController(requireContext());
|
||||
mAdsRemovalPurchaseController.initialize(requireActivity());
|
||||
return super.onCreateView(inflater, container, savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView()
|
||||
{
|
||||
mAdsRemovalPurchaseController.destroy();
|
||||
if (mAdsRemovalPurchaseController != null)
|
||||
mAdsRemovalPurchaseController.destroy();
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue