mirror of
https://github.com/readest/readest.git
synced 2026-04-29 12:00:49 +00:00
This commit is contained in:
parent
669d3950e2
commit
5141be1c3f
18 changed files with 140 additions and 8 deletions
|
|
@ -8,6 +8,8 @@ import kotlinx.coroutines.CoroutineScope
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import com.google.android.gms.common.GoogleApiAvailability
|
||||
import com.google.android.gms.common.ConnectionResult
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
|
|
@ -16,12 +18,27 @@ class BillingManager(private val activity: Activity) : PurchasesUpdatedListener
|
|||
private val productsCache = mutableMapOf<String, ProductDetails>()
|
||||
private var purchaseCallback: ((PurchaseData?) -> Unit)? = null
|
||||
private val scope = CoroutineScope(Dispatchers.Main)
|
||||
private val isGooglePlayAvailable: Boolean by lazy {
|
||||
val availability = GoogleApiAvailability.getInstance()
|
||||
val resultCode = availability.isGooglePlayServicesAvailable(activity)
|
||||
resultCode == ConnectionResult.SUCCESS
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "BillingManager"
|
||||
}
|
||||
|
||||
fun isBillingAvailable(): Boolean {
|
||||
return isGooglePlayAvailable
|
||||
}
|
||||
|
||||
fun initialize(callback: (Boolean) -> Unit) {
|
||||
if (!isGooglePlayAvailable) {
|
||||
Log.d(TAG, "Google Play Services not available, skipping billing setup")
|
||||
callback(false)
|
||||
return
|
||||
}
|
||||
|
||||
billingClient = BillingClient.newBuilder(activity)
|
||||
.setListener(this)
|
||||
.enablePendingPurchases()
|
||||
|
|
|
|||
|
|
@ -511,6 +511,14 @@ class NativeBridgePlugin(private val activity: Activity): Plugin(activity) {
|
|||
invoke.resolve(ret)
|
||||
}
|
||||
|
||||
@Command
|
||||
fun iap_is_available(invoke: Invoke) {
|
||||
val isAvailable = billingManager.isBillingAvailable()
|
||||
val result = JSObject()
|
||||
result.put("available", isAvailable)
|
||||
invoke.resolve(result)
|
||||
}
|
||||
|
||||
@Command
|
||||
fun iap_initialize(invoke: Invoke) {
|
||||
billingManager.initialize { success ->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue