Merge pull request #1747 from Hafizzle/Fixes#1637

Fixes#1637 - Fix users unable to purchase gems because "you already own this item"
This commit is contained in:
Phillip Thelen 2022-04-18 15:00:31 +02:00 committed by GitHub
commit 9b5ff2b1e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 8 deletions

View file

@ -103,14 +103,7 @@ open class PurchaseHandler(
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
billingClientState = BillingClientState.READY
billingClient.queryPurchasesAsync(
BillingClient.SkuType.SUBS,
this@PurchaseHandler
)
billingClient.queryPurchasesAsync(
BillingClient.SkuType.INAPP,
this@PurchaseHandler
)
queryPurchases()
} else {
billingClientState = BillingClientState.UNAVAILABLE
}
@ -126,6 +119,19 @@ open class PurchaseHandler(
billingClient.endConnection()
}
fun queryPurchases(){
if (billingClientState == BillingClientState.READY){
billingClient.queryPurchasesAsync(
BillingClient.SkuType.SUBS,
this@PurchaseHandler
)
billingClient.queryPurchasesAsync(
BillingClient.SkuType.INAPP,
this@PurchaseHandler
)
}
}
suspend fun getAllGemSKUs(): List<SkuDetails> =
getSKUs(BillingClient.SkuType.INAPP, PurchaseTypes.allGemTypes)

View file

@ -91,6 +91,7 @@ class GemsPurchaseFragment : BaseFragment<FragmentGemPurchaseBinding>() {
override fun onResume() {
super.onResume()
purchaseHandler.queryPurchases()
loadInventory()
}

View file

@ -102,6 +102,7 @@ class SubscriptionFragment : BaseFragment<FragmentSubscriptionBinding>() {
override fun onResume() {
super.onResume()
purchaseHandler.queryPurchases()
refresh()
loadInventory()
}

View file

@ -49,6 +49,8 @@ class InsufficientGemsDialog(context: Context, var gemPrice: Int) : Insufficient
addCloseButton()
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
getActivity()?.let { activity ->