From 8b90c472e305b036ff146c88bdbf1b9c2112ca2b Mon Sep 17 00:00:00 2001 From: max Date: Thu, 18 Apr 2024 15:00:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8Dgoogle=E4=B8=8D=E5=8F=AF?= =?UTF-8?q?=E7=94=A8=E6=83=85=E5=86=B5=E4=B8=8B=20=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E9=87=91=E5=B8=81=E5=BC=80=E9=80=9A=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/chwl/app/vip/VipMainActivity.kt | 100 +++++++++++------- 1 file changed, 60 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/com/chwl/app/vip/VipMainActivity.kt b/app/src/main/java/com/chwl/app/vip/VipMainActivity.kt index 45d3f50b2..94325809b 100644 --- a/app/src/main/java/com/chwl/app/vip/VipMainActivity.kt +++ b/app/src/main/java/com/chwl/app/vip/VipMainActivity.kt @@ -231,7 +231,9 @@ class VipMainActivity : BaseViewBindingActivity(), buyVip() } } - + requestChargeList{ + loadChargeList(it) + } initBilling() } @@ -309,40 +311,54 @@ class VipMainActivity : BaseViewBindingActivity(), @SuppressLint("CheckResult", "SetTextI18n") override fun onBillingClientSetupFinished() { Log.i(TAG, "onBillingClientSetupFinished") + val call: ((List) -> Unit) = { list -> + loadChargeList(list) + val productKeys = ArrayList() + list.forEach { + productKeys.add(it.getChargeProdId()) + } + billingManager?.querySkuDetailsAsync(productKeys, + object : IBillingService.ProductDetailsResponseListener { + override fun onProductDetailsResponse( + billingResult: IBillingResult, + productDetails: List + ) { + if (!billingResult.isResponseOk()) { + Log.w( + TAG, + "Unsuccessful query for Error code: " + billingResult.getResponseCode() + ) + } else if (productDetails.isNotEmpty()) { + for (item in list) { + for (skuDetails in productDetails) { + if (skuDetails.getProductId() == item.getChargeProdId()) { + item.productDetails = skuDetails + break + } + } + } + loadChargeList(list) + } + } + }) + } + val list = chargeList + if (list.isNullOrEmpty()) { + requestChargeList{ + call.invoke(it) + } + } else { + call.invoke(list) + } + } + + @SuppressLint("CheckResult") + private fun requestChargeList(call: (List) -> Unit) { PayModel.get().vipList .compose(bindToLifecycle()) .subscribe( { - val list = it - loadChargeList(list) - val productKeys = ArrayList() - list.forEach { - productKeys.add(it.getChargeProdId()) - } - billingManager?.querySkuDetailsAsync(productKeys, - object : IBillingService.ProductDetailsResponseListener { - override fun onProductDetailsResponse( - billingResult: IBillingResult, - productDetails: List - ) { - if (!billingResult.isResponseOk()) { - Log.w( - TAG, - "Unsuccessful query for Error code: " + billingResult.getResponseCode() - ) - } else if (productDetails.isNotEmpty()) { - for (item in list) { - for (skuDetails in productDetails) { - if (skuDetails.getProductId() == item.getChargeProdId()) { - item.productDetails = skuDetails - break - } - } - } - loadChargeList(list) - } - } - }) + call.invoke(it) }, { it.printStackTrace() } @@ -569,17 +585,17 @@ class VipMainActivity : BaseViewBindingActivity(), } private fun buyVip() { - if ((currentChargeInfo?.productDetails?.getOneTimePurchaseOfferDetails() - ?.getPriceAmountMicros() - ?: "0") == "0" - ) { - toast(getString(R.string.Recharge_failure)) - return + val googleUnavailable = ((currentChargeInfo?.productDetails?.getOneTimePurchaseOfferDetails() + ?.getPriceAmountMicros() + ?: "0") == "0") + var text = + currentChargeInfo?.productDetails?.getOneTimePurchaseOfferDetails()?.getFormattedPrice() + if (text.isNullOrEmpty()) { + text = ((currentChargeInfo?.money ?: 0.0) * 1000).toInt().toString() } SelectPayTypeDialog.newInstance( - currentChargeInfo?.productDetails?.getOneTimePurchaseOfferDetails()?.getFormattedPrice() - ?: "0", - true, + text, + !googleUnavailable, currentChargeInfo?.getMoney() ?: 0.0 ) .apply { @@ -589,6 +605,10 @@ class VipMainActivity : BaseViewBindingActivity(), ) } setOnGoogleChargeClick { + if (googleUnavailable) { + toast(getString(R.string.Recharge_failure)) + return@setOnGoogleChargeClick + } currentChargeInfo?.let { charge -> buyProduct(charge.productDetails) }