Search in sources :

Example 1 with InAppPurchaseInitCallback

use of net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseInitCallback in project Osmand by osmandapp.

the class OsmandInAppPurchaseActivity method initInAppPurchaseHelper.

private void initInAppPurchaseHelper() {
    deinitInAppPurchaseHelper();
    OsmandApplication app = getMyApplication();
    OsmandSettings settings = app.getSettings();
    if (purchaseHelper == null) {
        InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();
        if (settings.isInternetConnectionAvailable() && isInAppPurchaseAllowed() && Version.isInAppPurchaseSupported()) {
            this.purchaseHelper = purchaseHelper;
        }
    }
    if (purchaseHelper != null) {
        final WeakReference<OsmandInAppPurchaseActivity> activityRef = new WeakReference<>(this);
        purchaseHelper.isInAppPurchaseSupported(this, new InAppPurchaseInitCallback() {

            @Override
            public void onSuccess() {
                OsmandInAppPurchaseActivity activity = activityRef.get();
                if (!activityDestroyed && AndroidUtils.isActivityNotDestroyed(activity)) {
                    purchaseHelper.setUiActivity(activity);
                    if (purchaseHelper.needRequestInventory()) {
                        purchaseHelper.requestInventory(false);
                    }
                }
            }

            @Override
            public void onFail() {
            }
        });
    } else if (isInAppPurchaseAllowed() && settings.isInternetConnectionAvailable()) {
        InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();
        if (purchaseHelper != null && purchaseHelper.needRequestPromo()) {
            purchaseHelper.checkPromoAsync(null);
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) WeakReference(java.lang.ref.WeakReference) InAppPurchaseHelper(net.osmand.plus.inapp.InAppPurchaseHelper) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) InAppPurchaseInitCallback(net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseInitCallback)

Aggregations

WeakReference (java.lang.ref.WeakReference)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 InAppPurchaseHelper (net.osmand.plus.inapp.InAppPurchaseHelper)1 InAppPurchaseInitCallback (net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseInitCallback)1 OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)1