fix:修复google不可用情况下 无法使用金币开通问题
This commit is contained in:
@@ -231,7 +231,9 @@ class VipMainActivity : BaseViewBindingActivity<ActivityVipMainBinding>(),
|
||||
buyVip()
|
||||
}
|
||||
}
|
||||
|
||||
requestChargeList{
|
||||
loadChargeList(it)
|
||||
}
|
||||
initBilling()
|
||||
}
|
||||
|
||||
@@ -309,40 +311,54 @@ class VipMainActivity : BaseViewBindingActivity<ActivityVipMainBinding>(),
|
||||
@SuppressLint("CheckResult", "SetTextI18n")
|
||||
override fun onBillingClientSetupFinished() {
|
||||
Log.i(TAG, "onBillingClientSetupFinished")
|
||||
val call: ((List<ChargeBean>) -> Unit) = { list ->
|
||||
loadChargeList(list)
|
||||
val productKeys = ArrayList<String>()
|
||||
list.forEach {
|
||||
productKeys.add(it.getChargeProdId())
|
||||
}
|
||||
billingManager?.querySkuDetailsAsync(productKeys,
|
||||
object : IBillingService.ProductDetailsResponseListener {
|
||||
override fun onProductDetailsResponse(
|
||||
billingResult: IBillingResult,
|
||||
productDetails: List<IProductDetails>
|
||||
) {
|
||||
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<ChargeBean>) -> Unit) {
|
||||
PayModel.get().vipList
|
||||
.compose(bindToLifecycle())
|
||||
.subscribe(
|
||||
{
|
||||
val list = it
|
||||
loadChargeList(list)
|
||||
val productKeys = ArrayList<String>()
|
||||
list.forEach {
|
||||
productKeys.add(it.getChargeProdId())
|
||||
}
|
||||
billingManager?.querySkuDetailsAsync(productKeys,
|
||||
object : IBillingService.ProductDetailsResponseListener {
|
||||
override fun onProductDetailsResponse(
|
||||
billingResult: IBillingResult,
|
||||
productDetails: List<IProductDetails>
|
||||
) {
|
||||
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<ActivityVipMainBinding>(),
|
||||
}
|
||||
|
||||
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<ActivityVipMainBinding>(),
|
||||
)
|
||||
}
|
||||
setOnGoogleChargeClick {
|
||||
if (googleUnavailable) {
|
||||
toast(getString(R.string.Recharge_failure))
|
||||
return@setOnGoogleChargeClick
|
||||
}
|
||||
currentChargeInfo?.let { charge ->
|
||||
buyProduct(charge.productDetails)
|
||||
}
|
||||
|
Reference in New Issue
Block a user