From 99fa99eba58515b0c82b1cec91d063475ff4a4f7 Mon Sep 17 00:00:00 2001 From: darken Date: Sat, 28 Oct 2023 17:46:27 +0200 Subject: [PATCH] Update billing client --- app/build.gradle.kts | 4 ++-- .../core/client/BillingClientConnection.kt | 22 ++++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 68de8c8e..0a06873c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -145,6 +145,6 @@ dependencies { addTesting() - "gplayImplementation"("com.android.billingclient:billing:5.1.0") - "gplayImplementation"("com.android.billingclient:billing-ktx:5.1.0") + "gplayImplementation"("com.android.billingclient:billing:6.0.1") + "gplayImplementation"("com.android.billingclient:billing-ktx:6.0.1") } \ No newline at end of file diff --git a/app/src/gplay/java/eu/darken/capod/common/upgrade/core/client/BillingClientConnection.kt b/app/src/gplay/java/eu/darken/capod/common/upgrade/core/client/BillingClientConnection.kt index 741ddd66..971c46e8 100644 --- a/app/src/gplay/java/eu/darken/capod/common/upgrade/core/client/BillingClientConnection.kt +++ b/app/src/gplay/java/eu/darken/capod/common/upgrade/core/client/BillingClientConnection.kt @@ -1,7 +1,13 @@ package eu.darken.capod.common.upgrade.core.client import android.app.Activity -import com.android.billingclient.api.* +import com.android.billingclient.api.AcknowledgePurchaseParams +import com.android.billingclient.api.BillingClient +import com.android.billingclient.api.BillingFlowParams +import com.android.billingclient.api.BillingResult +import com.android.billingclient.api.ProductDetails +import com.android.billingclient.api.Purchase +import com.android.billingclient.api.QueryProductDetailsParams import eu.darken.capod.common.debug.logging.Logging.Priority.INFO import eu.darken.capod.common.debug.logging.Logging.Priority.WARN import eu.darken.capod.common.debug.logging.log @@ -20,11 +26,15 @@ data class BillingClientConnection( ) { private val purchasesLocal = MutableStateFlow>(emptySet()) val purchases: Flow> = combine(purchasesGlobal, purchasesLocal) { global, local -> - val combined = mutableMapOf() - global.plus(local).toSet().sortedByDescending { it.purchaseTime }.forEach { purchase -> - combined[purchase.orderId] = purchase - } - combined.values + val combined = mutableSetOf() + + combined.addAll(local) + + global + .let { purchases -> purchases.filter { it.purchaseState == Purchase.PurchaseState.PURCHASED } } + .let { combined.addAll(it) } + + combined.sortedByDescending { it.purchaseTime } } .setupCommonEventHandlers(TAG) { "purchases" }