From 260d0a1e8429554f5efa6bad85f8cc4a917aa813 Mon Sep 17 00:00:00 2001 From: Tretzi Date: Thu, 16 Apr 2026 20:01:01 -0500 Subject: [PATCH] Auto commit (MindMachine) Thu Apr 16 08:01:01 PM CDT 2026 --- ...kotlin-compiler-4880113023722938435.salive | 0 .../mindmachine/mvp/billing/BillingManager.kt | 72 ++++++++++--------- 2 files changed, 39 insertions(+), 33 deletions(-) delete mode 100644 .kotlin/sessions/kotlin-compiler-4880113023722938435.salive diff --git a/.kotlin/sessions/kotlin-compiler-4880113023722938435.salive b/.kotlin/sessions/kotlin-compiler-4880113023722938435.salive deleted file mode 100644 index e69de29..0000000 diff --git a/app/src/main/java/com/mindmachine/mvp/billing/BillingManager.kt b/app/src/main/java/com/mindmachine/mvp/billing/BillingManager.kt index 9d62979..d5c61a8 100644 --- a/app/src/main/java/com/mindmachine/mvp/billing/BillingManager.kt +++ b/app/src/main/java/com/mindmachine/mvp/billing/BillingManager.kt @@ -54,36 +54,36 @@ class BillingManager( @Volatile private var isConnecting = false - + fun start() { log("BillingManager.start() - isReady=${billingClient.isReady}, isConnecting=$isConnecting") - + if (billingClient.isReady) { log("Billing client already ready") refresh() return } - + if (isConnecting) { log("Billing client connection already in progress") return } - + isConnecting = true log("Calling startConnection()") - + billingClient.startConnection(object : BillingClientStateListener { override fun onBillingSetupFinished(result: BillingResult) { isConnecting = false log("Billing setup finished: ${result.responseCode} ${result.debugMessage}") - + if (result.responseCode == BillingClient.BillingResponseCode.OK) { refresh() } else { logError("Billing setup failed: ${result.responseCode} ${result.debugMessage}") } } - + override fun onBillingServiceDisconnected() { isConnecting = false log("Billing service disconnected") @@ -150,55 +150,55 @@ class BillingManager( log("Billing client not ready") return } - + val featureResult = billingClient.isFeatureSupported(BillingClient.FeatureType.PRODUCT_DETAILS) log("PRODUCT_DETAILS support: ${featureResult.responseCode} ${featureResult.debugMessage}") if (featureResult.responseCode != BillingClient.BillingResponseCode.OK) { logError("PRODUCT_DETAILS feature not supported") return } - + queryProductDetailsForType( productType = BillingClient.ProductType.SUBS, productIds = listOf(BillingProducts.SUB_REMOVE_ADS_MONTHLY) ) - + queryProductDetailsForType( productType = BillingClient.ProductType.INAPP, productIds = listOf(BillingProducts.INAPP_REMOVE_ADS_FOREVER) ) } - + private fun queryProductDetailsForType( productType: String, productIds: List ) { try { log("Querying $productType product details for $productIds") - + val products = productIds.map { productId -> QueryProductDetailsParams.Product.newBuilder() .setProductId(productId) .setProductType(productType) .build() } - + val params = QueryProductDetailsParams.newBuilder() .setProductList(products) .build() - - billingClient.queryProductDetailsAsync(params) { result, queryResult -> - log("queryProductDetailsAsync($productType) result: ${result.responseCode} ${result.debugMessage}") - + + billingClient.queryProductDetailsAsync(params) { billingResult, queryResult -> + log("queryProductDetailsAsync($productType) result: ${billingResult.responseCode} ${billingResult.debugMessage}") + val detailsList = queryResult.productDetailsList - log("Fetched $productType products: ${detailsList.map { it.productId }}") - + log("Fetched $productType products: ${detailsList?.map { it.productId } ?: emptyList()}") + if (queryResult.unfetchedProductList.isNotEmpty()) { logError("Unfetched $productType products: ${queryResult.unfetchedProductList}") } - - if (result.responseCode == BillingClient.BillingResponseCode.OK) { - _productDetails.value = _productDetails.value + detailsList.associateBy { it.productId } + + if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) { + _productDetails.value = _productDetails.value + (detailsList?.associateBy { it.productId } ?: emptyMap()) log("Product details cache now has: ${_productDetails.value.keys}") } } @@ -214,23 +214,29 @@ class BillingManager( return } - val listener = PurchasesResponseListener { result, purchases -> - if (result.responseCode == BillingClient.BillingResponseCode.OK) { - log("Query purchases returned ${purchases.size} items") + billingClient.queryPurchasesAsync( + QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.SUBS).build() + ) { billingResult, queryResult -> + val purchases = queryResult.purchasesList + if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) { + log("Query SUBS purchases returned ${purchases.size} items") handlePurchases(purchases) } else { - logError("Query purchases failed: ${result.responseCode} ${result.debugMessage}") + logError("Query SUBS purchases failed: ${billingResult.responseCode} ${billingResult.debugMessage}") } } billingClient.queryPurchasesAsync( - QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.SUBS).build(), - listener - ) - billingClient.queryPurchasesAsync( - QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.INAPP).build(), - listener - ) + QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.INAPP).build() + ) { billingResult, queryResult -> + val purchases = queryResult.purchasesList + if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) { + log("Query INAPP purchases returned ${purchases.size} items") + handlePurchases(purchases) + } else { + logError("Query INAPP purchases failed: ${billingResult.responseCode} ${billingResult.debugMessage}") + } + } } private fun handlePurchases(purchases: List) {