Search in sources :

Example 1 with Purchase

use of com.android.billingclient.api.Purchase in project zype-android by zype.

the class SubscriptionsHelper method updateSubscriptionCount.

/**
 * Update settings with native subscriptions count
 * @param purchases
 */
public static void updateSubscriptionCount(List<Purchase> purchases) {
    if (purchases != null && !purchases.isEmpty()) {
        int subscriptionCount = 0;
        for (Purchase item : purchases) {
            if (getSkuList().contains(item.getSku())) {
                subscriptionCount += 1;
            }
        }
        Logger.d("updateSubscriptionCount(): Native purchases count: " + subscriptionCount);
        SettingsProvider.getInstance().saveSubscriptionCount(subscriptionCount);
    } else {
        Logger.d("updateSubscriptionCount(): No native purchases");
        SettingsProvider.getInstance().saveSubscriptionCount(0);
    }
}
Also used : Purchase(com.android.billingclient.api.Purchase)

Example 2 with Purchase

use of com.android.billingclient.api.Purchase in project Shuttle by timusus.

the class BaseActivity method onCreate.

@CallSuper
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Permiso.getInstance().setActivity(this);
    Permiso.getInstance().requestPermissions(new Permiso.IOnPermissionResult() {

        @Override
        public void onPermissionResult(Permiso.ResultSet resultSet) {
            if (resultSet.areAllPermissionsGranted()) {
                bindService();
            } else {
                Toast.makeText(BaseActivity.this, "Permission check failed", Toast.LENGTH_LONG).show();
                finish();
            }
        }

        @Override
        public void onRationaleRequested(Permiso.IOnRationaleProvided callback, String... permissions) {
            callback.onRationaleProvided();
        }
    }, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.WAKE_LOCK);
    billingManager = new BillingManager(this, new BillingManager.BillingUpdatesListener() {

        @Override
        public void onPurchasesUpdated(List<Purchase> purchases) {
            for (Purchase purchase : purchases) {
                if (purchase.getSku().equals(Config.SKU_PREMIUM)) {
                    ShuttleApplication.getInstance().setIsUpgraded(true);
                }
            }
        }

        @Override
        public void onPremiumPurchaseCompleted() {
            ShuttleApplication.getInstance().setIsUpgraded(true);
            UpgradeDialog.getUpgradeSuccessDialog(BaseActivity.this).show();
        }

        @Override
        public void onPremiumPurchaseRestored() {
            ShuttleApplication.getInstance().setIsUpgraded(true);
            Toast.makeText(BaseActivity.this, R.string.iab_purchase_restored, Toast.LENGTH_SHORT).show();
        }
    });
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
Also used : Permiso(com.greysonparrelli.permiso.Permiso) Purchase(com.android.billingclient.api.Purchase) BillingManager(com.simplecity.amp_library.billing.BillingManager) List(java.util.List) CallSuper(android.support.annotation.CallSuper)

Example 3 with Purchase

use of com.android.billingclient.api.Purchase in project Shuttle by timusus.

the class BillingManager method onPurchasesUpdated.

@SuppressLint("DefaultLocale")
@Override
public void onPurchasesUpdated(int resultCode, @Nullable List<Purchase> purchases) {
    if (resultCode == BillingClient.BillingResponse.OK && purchases != null) {
        Purchase premiumPurchase = null;
        for (Purchase purchase : purchases) {
            if (purchase.getSku().equals(Config.SKU_PREMIUM)) {
                premiumPurchase = purchase;
            }
        }
        if (purchaseFlowInitiated || restorePurchasesInitiated) {
            if (premiumPurchase != null) {
                if (purchaseFlowInitiated) {
                    updatesListener.onPremiumPurchaseCompleted();
                    purchaseFlowInitiated = false;
                }
                if (restorePurchasesInitiated) {
                    updatesListener.onPremiumPurchaseRestored();
                    restorePurchasesInitiated = false;
                }
            }
        } else {
            updatesListener.onPurchasesUpdated(purchases);
        }
    } else if (resultCode == BillingClient.BillingResponse.USER_CANCELED) {
        Log.i(TAG, "onPurchasesUpdated() - user cancelled the purchase flow - skipping");
    } else {
        LogUtils.logException(TAG, String.format("onPurchasesUpdated() got unknown resultCode: %d", resultCode), null);
    }
}
Also used : Purchase(com.android.billingclient.api.Purchase) SuppressLint(android.annotation.SuppressLint)

Aggregations

Purchase (com.android.billingclient.api.Purchase)3 SuppressLint (android.annotation.SuppressLint)1 CallSuper (android.support.annotation.CallSuper)1 Permiso (com.greysonparrelli.permiso.Permiso)1 BillingManager (com.simplecity.amp_library.billing.BillingManager)1 List (java.util.List)1