|
|
|
@ -3,6 +3,7 @@ package net.pokeranalytics.android.util.billing |
|
|
|
import android.app.Activity |
|
|
|
import android.app.Activity |
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
import com.android.billingclient.api.* |
|
|
|
import com.android.billingclient.api.* |
|
|
|
|
|
|
|
import net.pokeranalytics.android.BuildConfig |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import timber.log.Timber |
|
|
|
import timber.log.Timber |
|
|
|
import java.io.IOException |
|
|
|
import java.io.IOException |
|
|
|
@ -40,11 +41,23 @@ object AppGuard : PurchasesUpdatedListener { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private var billingClientAvailable: Boolean = false |
|
|
|
private var billingClientAvailable: Boolean = false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Returns the true state of the user's pro subscription |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private var _isProUser: Boolean = false |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns whether the user has the pro subscription |
|
|
|
* Returns whether the user has the pro subscription |
|
|
|
|
|
|
|
* Always true for debugging |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
var isProUser: Boolean = false |
|
|
|
val isProUser: Boolean |
|
|
|
private set |
|
|
|
get() { |
|
|
|
|
|
|
|
return if (BuildConfig.DEBUG) { |
|
|
|
|
|
|
|
true |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this._isProUser |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* A delegate to notify when the purchase has succeeded |
|
|
|
* A delegate to notify when the purchase has succeeded |
|
|
|
@ -118,7 +131,7 @@ object AppGuard : PurchasesUpdatedListener { |
|
|
|
* This is done before restoring in order to ensure that subscriptions stops |
|
|
|
* This is done before restoring in order to ensure that subscriptions stops |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun resetPurchases() { |
|
|
|
private fun resetPurchases() { |
|
|
|
this.isProUser = false |
|
|
|
this._isProUser = false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -191,9 +204,9 @@ object AppGuard : PurchasesUpdatedListener { |
|
|
|
|
|
|
|
|
|
|
|
val date = Date(purchase.purchaseTime) |
|
|
|
val date = Date(purchase.purchaseTime) |
|
|
|
Timber.d("*** Auto renewing = ${purchase.isAutoRenewing}") |
|
|
|
Timber.d("*** Auto renewing = ${purchase.isAutoRenewing}") |
|
|
|
Timber.d("*** purchaseTime = ${date}") |
|
|
|
Timber.d("*** purchaseTime = $date") |
|
|
|
|
|
|
|
|
|
|
|
this.isProUser = true |
|
|
|
this._isProUser = true |
|
|
|
this.purchaseDelegate?.let { |
|
|
|
this.purchaseDelegate?.let { |
|
|
|
it.purchaseDidSucceed(purchase) |
|
|
|
it.purchaseDidSucceed(purchase) |
|
|
|
this.purchaseDelegate = null |
|
|
|
this.purchaseDelegate = null |
|
|
|
|