mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-14 18:21:57 +00:00
small changes to IAP code
This commit is contained in:
parent
24aab1ed38
commit
f4179c5750
7 changed files with 48 additions and 39 deletions
|
|
@ -155,8 +155,8 @@ android {
|
|||
buildConfigField "String", "TESTING_LEVEL", "\"production\""
|
||||
resConfigs "en", "bg", "de", "en-rGB", "es", "fr", "hr-rHR", "in", "it", "iw", "ja", "ko", "lt", "nl", "pl", "pt-rBR", "pt-rPT", "ru", "tr", "zh", "zh-rTW"
|
||||
|
||||
versionCode 3059
|
||||
versionName "3.4"
|
||||
versionCode 3063
|
||||
versionName "3.4.0.1"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.habitrpg.android.habitica
|
|||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.google.firebase.analytics.FirebaseAnalytics
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
|
|
@ -76,10 +77,9 @@ class HabiticaPurchaseVerifier(context: Context, apiClient: ApiClient) : BasePur
|
|||
}
|
||||
}
|
||||
}
|
||||
val edit = preferences?.edit()
|
||||
edit?.putStringSet(PURCHASED_PRODUCTS_KEY, purchasedOrderList)
|
||||
edit?.apply()
|
||||
savePendingGifts()
|
||||
preferences?.edit {
|
||||
edit?.putStringSet(PURCHASED_PRODUCTS_KEY, purchasedOrderList)
|
||||
}
|
||||
}
|
||||
|
||||
private fun processedPurchase(
|
||||
|
|
@ -154,6 +154,7 @@ class HabiticaPurchaseVerifier(context: Context, apiClient: ApiClient) : BasePur
|
|||
private const val PENDING_GIFTS_KEY = "PENDING_GIFTS"
|
||||
private var pendingGifts: MutableMap<String?, String?> = HashMap()
|
||||
private var preferences: SharedPreferences? = null
|
||||
|
||||
fun addGift(sku: String?, userID: String?) {
|
||||
pendingGifts[sku] = userID
|
||||
savePendingGifts()
|
||||
|
|
@ -168,10 +169,9 @@ class HabiticaPurchaseVerifier(context: Context, apiClient: ApiClient) : BasePur
|
|||
private fun savePendingGifts() {
|
||||
val jsonObject = JSONObject(pendingGifts as Map<*, *>)
|
||||
val jsonString = jsonObject.toString()
|
||||
val editor = preferences?.edit()
|
||||
editor?.remove(PENDING_GIFTS_KEY)
|
||||
editor?.putString(PENDING_GIFTS_KEY, jsonString)
|
||||
editor?.apply()
|
||||
preferences?.edit {
|
||||
putString(PENDING_GIFTS_KEY, jsonString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import android.app.Activity
|
|||
import android.content.Intent
|
||||
import com.habitrpg.android.habitica.HabiticaBaseApplication
|
||||
import com.habitrpg.android.habitica.proxy.AnalyticsManager
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.solovyev.android.checkout.*
|
||||
import java.util.*
|
||||
import kotlin.coroutines.resume
|
||||
|
|
@ -74,16 +76,18 @@ open class PurchaseHandler(activity: Activity, val analyticsManager: AnalyticsMa
|
|||
return purchases.skus.firstOrNull()
|
||||
}
|
||||
|
||||
private suspend fun loadInventory(type: String, skus: List<String>): Inventory.Products? = suspendCoroutine { cont ->
|
||||
val request = Inventory.Request.create().loadAllPurchases().loadSkus(type, skus)
|
||||
try {
|
||||
inventory?.load(request) {
|
||||
cont.resume(it)
|
||||
private suspend fun loadInventory(type: String, skus: List<String>): Inventory.Products? = withContext(Dispatchers.Main) {
|
||||
suspendCoroutine { cont ->
|
||||
val request = Inventory.Request.create().loadAllPurchases().loadSkus(type, skus)
|
||||
try {
|
||||
inventory?.load(request) {
|
||||
cont.resume(it)
|
||||
}
|
||||
} catch (e: NullPointerException) {
|
||||
cont.resumeWithException(e)
|
||||
}
|
||||
} catch (e: NullPointerException) {
|
||||
cont.resumeWithException(e)
|
||||
if (inventory == null) cont.resume(null)
|
||||
}
|
||||
if (inventory == null) cont.resume(null)
|
||||
}
|
||||
|
||||
fun purchaseSubscription(sku: Sku, onSuccess: (() -> Unit)) {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.habitrpg.android.habitica.models.user.Gear
|
|||
import com.habitrpg.android.habitica.models.user.Outfit
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.inventory.equipment.EquipmentOverviewViewModel
|
||||
import com.habitrpg.android.habitica.ui.views.equipment.EquipmentOverviewView
|
||||
|
||||
class EquipmentOverviewFragment : BaseMainFragment<FragmentEquipmentOverviewBinding>() {
|
||||
|
||||
|
|
@ -47,13 +48,7 @@ class EquipmentOverviewFragment : BaseMainFragment<FragmentEquipmentOverviewBind
|
|||
binding?.autoEquipSwitch?.isChecked = user?.preferences?.autoEquip ?: false
|
||||
binding?.costumeSwitch?.isChecked = user?.preferences?.costume ?: false
|
||||
|
||||
if (user?.preferences?.costume == true) {
|
||||
binding?.costumeView?.alpha = 1.0f
|
||||
binding?.costumeView?.isEnabled = true
|
||||
} else {
|
||||
binding?.costumeView?.alpha = 0.6f
|
||||
binding?.costumeView?.isEnabled = false
|
||||
}
|
||||
binding?.costumeView?.isEnabled = user?.preferences?.costume == true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -66,17 +61,17 @@ class EquipmentOverviewFragment : BaseMainFragment<FragmentEquipmentOverviewBind
|
|||
}
|
||||
|
||||
private fun updateGearData(gear: Gear) {
|
||||
updateOutfit(gear.equipped)
|
||||
updateOutfit(gear.costume)
|
||||
updateOutfit(binding?.battlegearView, gear.equipped)
|
||||
updateOutfit(binding?.costumeView, gear.costume)
|
||||
}
|
||||
|
||||
private fun updateOutfit(outfit: Outfit?) {
|
||||
private fun updateOutfit(view: EquipmentOverviewView?, outfit: Outfit?) {
|
||||
if (outfit?.weapon?.isNotEmpty() == true) {
|
||||
viewModel.getGear(outfit.weapon) {
|
||||
binding?.battlegearView?.updateData(outfit, it.twoHanded)
|
||||
view?.updateData(outfit, it.twoHanded)
|
||||
}
|
||||
} else {
|
||||
binding?.battlegearView?.updateData(outfit)
|
||||
view?.updateData(outfit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
|
|||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import javax.inject.Inject
|
||||
|
||||
class GemsPurchaseFragment : BaseFragment<FragmentGemPurchaseBinding>(), GemPurchaseActivity.CheckoutFragment {
|
||||
|
|
@ -98,8 +99,10 @@ class GemsPurchaseFragment : BaseFragment<FragmentGemPurchaseBinding>(), GemPurc
|
|||
override fun setupCheckout() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val skus = purchaseHandler?.getAllGemSKUs()
|
||||
for (sku in skus ?: emptyList()) {
|
||||
updateButtonLabel(sku.id.code, sku.price)
|
||||
withContext(Dispatchers.Main) {
|
||||
for (sku in skus ?: emptyList()) {
|
||||
updateButtonLabel(sku.id.code, sku.price)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import com.habitrpg.android.habitica.ui.fragments.BaseFragment
|
|||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import javax.inject.Inject
|
||||
|
||||
class GiftPurchaseGemsFragment : BaseFragment<FragmentGiftGemPurchaseBinding>() {
|
||||
|
|
@ -63,8 +64,10 @@ class GiftPurchaseGemsFragment : BaseFragment<FragmentGiftGemPurchaseBinding>()
|
|||
fun setupCheckout() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val skus = purchaseHandler?.getAllGemSKUs()
|
||||
for (sku in skus ?: emptyList()) {
|
||||
updateButtonLabel(sku.id.code, sku.price)
|
||||
withContext(Dispatchers.Main) {
|
||||
for (sku in skus ?: emptyList()) {
|
||||
updateButtonLabel(sku.id.code, sku.price)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import com.habitrpg.android.habitica.ui.views.subscriptions.SubscriptionOptionVi
|
|||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.solovyev.android.checkout.Inventory
|
||||
import org.solovyev.android.checkout.Purchase
|
||||
|
|
@ -145,12 +146,15 @@ class SubscriptionFragment : BaseFragment<FragmentSubscriptionBinding>(), GemPur
|
|||
override fun setupCheckout() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val subscriptions = purchaseHandler?.getAllSubscriptionProducts() ?: return@launch
|
||||
for (sku in subscriptions.skus) {
|
||||
updateButtonLabel(sku, sku.price, subscriptions)
|
||||
skus = subscriptions.skus
|
||||
withContext(Dispatchers.Main) {
|
||||
for (sku in subscriptions.skus) {
|
||||
updateButtonLabel(sku, sku.price, subscriptions)
|
||||
}
|
||||
selectSubscription(PurchaseTypes.Subscription1Month)
|
||||
hasLoadedSubscriptionOptions = true
|
||||
updateSubscriptionInfo()
|
||||
}
|
||||
selectSubscription(PurchaseTypes.Subscription1Month)
|
||||
hasLoadedSubscriptionOptions = true
|
||||
updateSubscriptionInfo()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue