|
|
@@ -5,6 +5,7 @@ import com.adealink.frame.base.Rlt
|
|
|
import com.adealink.frame.data.json.toJsonErrorNull
|
|
|
import com.adealink.frame.frame.BaseFrame
|
|
|
import com.adealink.frame.log.Log
|
|
|
+import com.adealink.frame.storage.cache.TimeoutLruCache
|
|
|
import com.adealink.weparty.App
|
|
|
import com.adealink.weparty.commonui.ext.isSuccess
|
|
|
import com.adealink.weparty.config.Config
|
|
|
@@ -18,6 +19,7 @@ import com.adealink.weparty.wallet.datasource.remote.WalletHttpService
|
|
|
import com.adealink.weparty.wallet.recharge.data.ConvertCurrencyReq
|
|
|
import com.adealink.weparty.wallet.recharge.data.PayFailReq
|
|
|
import com.adealink.weparty.wallet.recharge.data.PaySuccessReq
|
|
|
+import com.adealink.weparty.wallet.recharge.data.RechargeConfigReq
|
|
|
import com.adealink.weparty.wallet.recharge.data.RechargeProduct
|
|
|
import com.android.billingclient.api.BillingResult
|
|
|
import com.android.billingclient.api.Purchase
|
|
|
@@ -36,6 +38,12 @@ class WalletManager : BaseFrame<IWalletListener>(), IWalletManager {
|
|
|
private var diamond: Double = 0.0
|
|
|
private var bean: Double = 0.0
|
|
|
|
|
|
+ private var rechargeConfig =
|
|
|
+ TimeoutLruCache<Currency, List<RechargeProduct>>(
|
|
|
+ 1000,
|
|
|
+ 60 * 60 * 1000
|
|
|
+ )//最多缓存1000个,缓存时长60分钟
|
|
|
+
|
|
|
override fun getWalletData() {
|
|
|
launch {
|
|
|
notifyCurrencyChanged()
|
|
|
@@ -61,6 +69,25 @@ class WalletManager : BaseFrame<IWalletListener>(), IWalletManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ override suspend fun getRechargeConfig(currency: Currency): List<RechargeProduct> {
|
|
|
+ val configs = rechargeConfig[currency]
|
|
|
+ if (configs != null) {
|
|
|
+ return configs
|
|
|
+ }
|
|
|
+ val rlt = walletHttpService.rechargeConfig(RechargeConfigReq(currency = currency.type))
|
|
|
+ when (rlt) {
|
|
|
+ is Rlt.Failed -> {
|
|
|
+ return emptyList()
|
|
|
+ }
|
|
|
+
|
|
|
+ is Rlt.Success -> {
|
|
|
+ val items = rlt.data.data?.items ?: emptyList()
|
|
|
+ rechargeConfig.put(currency, items)
|
|
|
+ return items
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
override suspend fun pullWalletData(): Rlt<Map<Currency, Double>> {
|
|
|
val rlt = walletHttpService.pullWallet()
|
|
|
when (rlt) {
|