Auto commit (MindMachine) Thu Apr 16 08:01:01 PM CDT 2026

This commit is contained in:
Tretzi
2026-04-16 20:01:01 -05:00
parent 7d7057f640
commit 260d0a1e84
2 changed files with 39 additions and 33 deletions

View File

@@ -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<String>
) {
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<Purchase>) {