|
|
@@ -3,6 +3,7 @@ package com.adealink.weparty.wallet.recharge.dialog
|
|
|
import androidx.fragment.app.activityViewModels
|
|
|
import com.adealink.frame.aab.util.getCompatString
|
|
|
import com.adealink.frame.base.Rlt
|
|
|
+import com.adealink.frame.log.Log
|
|
|
import com.adealink.frame.mvvm.view.viewBinding
|
|
|
import com.adealink.frame.util.onClick
|
|
|
import com.adealink.weparty.commonui.text.filter.SimplePositiveDecimalFilter
|
|
|
@@ -23,7 +24,7 @@ class ConvertCurrencyDialog : BottomDialogFragment(R.layout.dialog_convert_curre
|
|
|
var fromCurrency: Currency = Currency.COIN
|
|
|
var toCurrency: Currency = Currency.DIAMOND
|
|
|
|
|
|
- private var exchangeRatio: Double? = null
|
|
|
+ // private var exchangeRatio: Double? = null
|
|
|
private var maxExchangeInput: Double? = null
|
|
|
|
|
|
private var inputExchange: Double? = null
|
|
|
@@ -140,6 +141,12 @@ class ConvertCurrencyDialog : BottomDialogFragment(R.layout.dialog_convert_curre
|
|
|
binding.etFromCurrencyAmount.setSelection(it)
|
|
|
},
|
|
|
afterTextChanged = {
|
|
|
+ if (it.isEmpty()) {
|
|
|
+ binding.etFromCurrencyAmount.hint =
|
|
|
+ getCompatString(R.string.wallet_convert_please_fill)
|
|
|
+ } else {
|
|
|
+ binding.etFromCurrencyAmount.hint = null
|
|
|
+ }
|
|
|
notifyInputChanged(it.toDoubleOrNull() ?: 0.0)
|
|
|
}
|
|
|
).also {
|
|
|
@@ -151,25 +158,30 @@ class ConvertCurrencyDialog : BottomDialogFragment(R.layout.dialog_convert_curre
|
|
|
override fun loadData() {
|
|
|
super.loadData()
|
|
|
walletViewModel.refreshWalletData()
|
|
|
- walletViewModel.loadConvertConfig(fromCurrency, toCurrency)
|
|
|
- .observe(viewLifecycleOwner) { rlt ->
|
|
|
- when (rlt) {
|
|
|
- is Rlt.Failed -> {
|
|
|
- showFailedToast(rlt)
|
|
|
- exchangeRatio = null
|
|
|
- notifyExchangeStateChanged()
|
|
|
- }
|
|
|
-
|
|
|
- is Rlt.Success -> {
|
|
|
- exchangeRatio = rlt.data
|
|
|
- notifyExchangeStateChanged()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+// walletViewModel.loadConvertConfig(fromCurrency, toCurrency)
|
|
|
+// .observe(viewLifecycleOwner) { rlt ->
|
|
|
+// when (rlt) {
|
|
|
+// is Rlt.Failed -> {
|
|
|
+// showFailedToast(rlt)
|
|
|
+// exchangeRatio = null
|
|
|
+// notifyExchangeStateChanged()
|
|
|
+// }
|
|
|
+//
|
|
|
+// is Rlt.Success -> {
|
|
|
+// exchangeRatio = rlt.data
|
|
|
+// notifyExchangeStateChanged()
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
private fun notifyExchangeStateChanged() {
|
|
|
- if (exchangeRatio == null || maxExchangeInput == null) {
|
|
|
+// if (exchangeRatio == null || maxExchangeInput == null) {
|
|
|
+// binding.etFromCurrencyAmount.isEnabled = false
|
|
|
+// } else {
|
|
|
+// binding.etFromCurrencyAmount.isEnabled = true
|
|
|
+// }
|
|
|
+ if (maxExchangeInput == null) {
|
|
|
binding.etFromCurrencyAmount.isEnabled = false
|
|
|
} else {
|
|
|
binding.etFromCurrencyAmount.isEnabled = true
|
|
|
@@ -177,13 +189,31 @@ class ConvertCurrencyDialog : BottomDialogFragment(R.layout.dialog_convert_curre
|
|
|
}
|
|
|
|
|
|
private fun notifyInputChanged(inputNumber: Double) {
|
|
|
- inputExchange = inputNumber
|
|
|
- val ratio = exchangeRatio
|
|
|
- if (ratio == null || ratio == 0.0) {
|
|
|
- binding.tvToCurrencyAmount.text = formatNumberStr(0.0, false)
|
|
|
+ if (inputExchange == inputNumber) {
|
|
|
return
|
|
|
}
|
|
|
- binding.tvToCurrencyAmount.text = formatNumberStr(inputNumber / ratio, false)
|
|
|
+ inputExchange = inputNumber
|
|
|
+ walletViewModel.preConvert(fromCurrency, toCurrency, inputNumber)
|
|
|
+ .observe(viewLifecycleOwner) { rlt ->
|
|
|
+ when (rlt) {
|
|
|
+ is Rlt.Failed -> {
|
|
|
+ showFailedToast(rlt)
|
|
|
+ }
|
|
|
+
|
|
|
+ is Rlt.Success -> {
|
|
|
+ if (rlt.data.first != inputExchange) {
|
|
|
+ return@observe
|
|
|
+ }
|
|
|
+ binding.tvToCurrencyAmount.text = formatNumberStr(rlt.data.second, false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+// val ratio = exchangeRatio
|
|
|
+// if (ratio == null || ratio == 0.0) {
|
|
|
+// binding.tvToCurrencyAmount.text = formatNumberStr(0.0, false)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// binding.tvToCurrencyAmount.text = formatNumberStr(inputNumber / ratio, false)
|
|
|
}
|
|
|
|
|
|
private fun allExchanged() {
|