mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-24 14:45:46 +00:00
Fixes #1386
This commit is contained in:
parent
4ea15382f5
commit
f3eefa5712
5 changed files with 17 additions and 12 deletions
|
|
@ -19,9 +19,7 @@ import org.solovyev.android.checkout.ResponseCodes
|
|||
import retrofit2.HttpException
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by Negue on 26.11.2015.
|
||||
*/
|
||||
|
||||
class HabiticaPurchaseVerifier(context: Context, apiClient: ApiClient) : BasePurchaseVerifier() {
|
||||
private val apiClient: ApiClient
|
||||
private val purchasedOrderList: MutableSet<String> = HashSet()
|
||||
|
|
@ -39,8 +37,8 @@ class HabiticaPurchaseVerifier(context: Context, apiClient: ApiClient) : BasePur
|
|||
apiClient.validatePurchase(validationRequest).subscribe({
|
||||
purchasedOrderList.add(purchase.orderId)
|
||||
requestListener.onSuccess(verifiedPurchases)
|
||||
EventBus.getDefault().post(ConsumablePurchasedEvent(purchase))
|
||||
removeGift(purchase.sku)
|
||||
val giftedID = removeGift(purchase.sku)
|
||||
EventBus.getDefault().post(ConsumablePurchasedEvent(purchase, giftedID))
|
||||
}) { throwable: Throwable ->
|
||||
handleError(throwable, purchase, requestListener, verifiedPurchases)
|
||||
}
|
||||
|
|
@ -50,8 +48,8 @@ class HabiticaPurchaseVerifier(context: Context, apiClient: ApiClient) : BasePur
|
|||
apiClient.validateNoRenewSubscription(validationRequest).subscribe({
|
||||
purchasedOrderList.add(purchase.orderId)
|
||||
requestListener.onSuccess(verifiedPurchases)
|
||||
EventBus.getDefault().post(ConsumablePurchasedEvent(purchase))
|
||||
removeGift(purchase.sku)
|
||||
val giftedID = removeGift(purchase.sku)
|
||||
EventBus.getDefault().post(ConsumablePurchasedEvent(purchase, giftedID))
|
||||
}) { throwable: Throwable ->
|
||||
handleError(throwable, purchase, requestListener, verifiedPurchases)
|
||||
}
|
||||
|
|
@ -138,9 +136,10 @@ class HabiticaPurchaseVerifier(context: Context, apiClient: ApiClient) : BasePur
|
|||
savePendingGifts()
|
||||
}
|
||||
|
||||
private fun removeGift(sku: String) {
|
||||
pendingGifts.remove(sku)
|
||||
private fun removeGift(sku: String): String? {
|
||||
val giftedID = pendingGifts.remove(sku)
|
||||
savePendingGifts()
|
||||
return giftedID
|
||||
}
|
||||
|
||||
private fun savePendingGifts() {
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@ package com.habitrpg.android.habitica.events
|
|||
|
||||
import org.solovyev.android.checkout.Purchase
|
||||
|
||||
class ConsumablePurchasedEvent(internal val purchase: Purchase)
|
||||
class ConsumablePurchasedEvent(internal val purchase: Purchase, val recipientID: String? = null)
|
||||
|
|
|
|||
|
|
@ -149,7 +149,9 @@ class GiftGemsActivity : BaseActivity() {
|
|||
fun onConsumablePurchased(event: ConsumablePurchasedEvent) {
|
||||
purchaseHandler?.consumePurchase(event.purchase)
|
||||
runOnUiThread {
|
||||
displayConfirmationDialog()
|
||||
if (event.recipientID == giftedUserID) {
|
||||
displayConfirmationDialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.purchases
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
|
@ -24,6 +25,7 @@ class GiftBalanceGemsFragment : BaseFragment<FragmentGiftGemBalanceBinding>() {
|
|||
}
|
||||
|
||||
var giftedMember: Member? = null
|
||||
@SuppressLint("SetTextI18n")
|
||||
set(value) {
|
||||
field = value
|
||||
field?.let {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.purchases
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
|
@ -30,6 +31,7 @@ class GiftPurchaseGemsFragment : BaseFragment<FragmentGiftGemPurchaseBinding>()
|
|||
}
|
||||
|
||||
var giftedMember: Member? = null
|
||||
@SuppressLint("SetTextI18n")
|
||||
set(value) {
|
||||
field = value
|
||||
field?.let {
|
||||
|
|
@ -52,7 +54,7 @@ class GiftPurchaseGemsFragment : BaseFragment<FragmentGiftGemPurchaseBinding>()
|
|||
binding?.gems4View?.setOnPurchaseClickListener { purchaseGems(PurchaseTypes.Purchase4Gems) }
|
||||
binding?.gems21View?.setOnPurchaseClickListener { purchaseGems(PurchaseTypes.Purchase21Gems) }
|
||||
binding?.gems42View?.setOnPurchaseClickListener { purchaseGems(PurchaseTypes.Purchase42Gems) }
|
||||
binding?.gems84View?.setOnPurchaseClickListener({ purchaseGems(PurchaseTypes.Purchase84Gems) })
|
||||
binding?.gems84View?.setOnPurchaseClickListener { purchaseGems(PurchaseTypes.Purchase84Gems) }
|
||||
}
|
||||
|
||||
fun setupCheckout() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue