From 598fa3b3ea8a5c14525b20c62869770801448bf3 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 20 May 2022 17:26:32 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../tangem/tap/common/extensions/Specific.kt | 54 ++- .../redux/reducers/OnWalletLoadedReducer.kt | 2 +- .../wallet/redux/reducers/WalletReducer.kt | 11 +- .../wallet/ui/adapters/WalletAdapter.kt | 47 +-- .../main/res/layout/item_currency_wallet.xml | 312 ++++++++---------- app/src/main/res/values/styles.xml | 7 +- 6 files changed, 215 insertions(+), 218 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/common/extensions/Specific.kt b/app/src/main/java/com/tangem/tap/common/extensions/Specific.kt index 2d0253eb8c..638995ef6f 100644 --- a/app/src/main/java/com/tangem/tap/common/extensions/Specific.kt +++ b/app/src/main/java/com/tangem/tap/common/extensions/Specific.kt @@ -39,10 +39,23 @@ fun BigDecimal.toFormattedCurrencyString( return "$formattedAmount $currency" } -fun BigDecimal.toFiatString(rateValue: BigDecimal, fiatCurrencyName: String): String { +fun BigDecimal.toFiatRateString( + fiatCurrencyName: String +): String { + val value = this + .setScale(2, RoundingMode.HALF_UP) + .formatWithSpaces() + return "$value $fiatCurrencyName" +} + +fun BigDecimal.toFiatString( + rateValue: BigDecimal, + fiatCurrencyName: String, + formatWithSpaces: Boolean = false +): String { var fiatValue = rateValue.multiply(this) fiatValue = fiatValue.setScale(2, RoundingMode.HALF_UP) - return "≈ ${fiatCurrencyName}  $fiatValue" + return fiatValue.toFormattedFiatValue(fiatCurrencyName, formatWithSpaces) } fun BigDecimal.toFiatValue(rateValue: BigDecimal): BigDecimal { @@ -50,8 +63,12 @@ fun BigDecimal.toFiatValue(rateValue: BigDecimal): BigDecimal { return fiatValue.setScale(2, RoundingMode.HALF_UP) } -fun BigDecimal.toFormattedFiatValue(fiatCurrencyName: String): String { - return "≈ ${fiatCurrencyName}  $this" +fun BigDecimal.toFormattedFiatValue( + fiatCurrencyName: String, + formatWithSpaces: Boolean = false +): String { + val fiatValue = if (formatWithSpaces) this.formatWithSpaces() else this + return " ${fiatValue}  $fiatCurrencyName" } fun BigDecimal.stripZeroPlainString(): String = this.stripTrailingZeros().toPlainString() @@ -111,4 +128,33 @@ fun BigDecimal.formatAmountAsSpannedString( append(' ') append(currencySymbol) } +} + +fun BigDecimal.formatWithSpaces(): String { + val str = this.toString() + var integerStr = str.substringBefore('.') + val reminderStr = str.substringAfter('.') + val packets = arrayListOf() + + var index: Int = integerStr.length + while (0 < index) { + if (index <= 3) { + packets.add(0, integerStr) + break + } + index -= 3 + packets.add(integerStr.substring(startIndex = index)) + integerStr = integerStr.substring(startIndex = 0, endIndex = index) + } + + return buildString { + packets.forEachIndexed { index, packet -> + append(packet) + if (index != packets.lastIndex) append(' ') + } + if (reminderStr.isNotBlank()) { + append('.') + append(reminderStr) + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/OnWalletLoadedReducer.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/OnWalletLoadedReducer.kt index 4b4d1cce5d..8f73d616d4 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/OnWalletLoadedReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/OnWalletLoadedReducer.kt @@ -65,7 +65,7 @@ class OnWalletLoadedReducer { amount = coinAmountValue, amountFormatted = formattedAmount, fiatAmount = fiatAmount, - fiatAmountFormatted = fiatAmount?.toFormattedFiatValue(fiatCurrency.code) + fiatAmountFormatted = fiatAmount?.toFormattedFiatValue(fiatCurrency.symbol) ), pendingTransactions = pendingTransactions.removeUnknownTransactions(), mainButton = WalletMainButton.SendButton(coinSendButton), diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/WalletReducer.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/WalletReducer.kt index eb079d3116..34aaba509d 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/WalletReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/reducers/WalletReducer.kt @@ -5,9 +5,9 @@ import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.Wallet import com.tangem.domain.common.TwinCardNumber import com.tangem.tap.common.entities.FiatCurrency +import com.tangem.tap.common.extensions.toFiatRateString import com.tangem.tap.common.extensions.toFiatString import com.tangem.tap.common.extensions.toFiatValue -import com.tangem.tap.common.extensions.toFormattedCurrencyString import com.tangem.tap.common.extensions.toFormattedFiatValue import com.tangem.tap.common.redux.AppState import com.tangem.tap.domain.TapError @@ -20,7 +20,6 @@ import com.tangem.tap.features.wallet.ui.BalanceWidgetData import com.tangem.tap.store import org.rekotlin.Action import java.math.BigDecimal -import java.math.RoundingMode class WalletReducer { companion object { @@ -383,10 +382,8 @@ private fun setNewFiatRate( state: WalletState ): WalletState { val rate = fiatRate.second ?: return state - val rateFormatted = rate.toFormattedCurrencyString( - decimals = 2, - currency = appCurrency.code, - roundingMode = RoundingMode.HALF_UP + val rateFormatted = rate.toFiatRateString( + fiatCurrencyName = appCurrency.symbol ) val currency = fiatRate.first @@ -415,7 +412,7 @@ private fun setMultiWalletFiatRate( is Currency.Token -> wallet?.getTokenAmount(currency.token)?.value?.toFiatValue(rate) } - val fiatAmountFormatted = fiatAmount?.toFormattedFiatValue(appCurrency.code) + val fiatAmountFormatted = fiatAmount?.toFormattedFiatValue(appCurrency.symbol) val newWalletData = state.getWalletData(currency)?.copy( currencyData = walletData.currencyData.copy( fiatAmountFormatted = fiatAmountFormatted, diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/WalletAdapter.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/WalletAdapter.kt index 244c223194..8328274be6 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/WalletAdapter.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/WalletAdapter.kt @@ -10,7 +10,6 @@ import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.Token import com.tangem.domain.common.TapWorkarounds.derivationStyle import com.tangem.tap.common.extensions.getString -import com.tangem.tap.common.extensions.hide import com.tangem.tap.common.extensions.loadCurrenciesIcon import com.tangem.tap.common.extensions.show import com.tangem.tap.features.wallet.redux.Currency @@ -63,9 +62,7 @@ class WalletAdapter fun bind(wallet: WalletData) = with(binding) { tvCurrency.text = wallet.currencyData.currency - tvAmount.text = wallet.currencyData.amountFormatted?.takeWhile { !it.isWhitespace() } - tvCurrencySymbol.text = - wallet.currencyData.amountFormatted?.takeLastWhile { !it.isWhitespace() } + tvAmount.text = wallet.currencyData.amountFormatted.orEmpty() tvAmountFiat.text = wallet.currencyData.fiatAmountFormatted tvExchangeRate.text = wallet.fiatRateString cardWallet.setOnClickListener { @@ -74,8 +71,8 @@ class WalletAdapter val blockchain = wallet.currency.blockchain val token = (wallet.currency as? Currency.Token)?.token - val isCustom = - wallet.currency.isCustomCurrency(store.state.globalState.scanResponse?.card?.derivationStyle) + val isCustom = wallet.currency + .isCustomCurrency(store.state.globalState.scanResponse?.card?.derivationStyle) tvExchangeRate.show(!isCustom) tvCustomCurrency.show(isCustom) @@ -86,43 +83,35 @@ class WalletAdapter ) when (wallet.currencyData.status) { - BalanceStatus.VerifiedOnline, BalanceStatus.SameCurrencyTransactionInProgress -> hideWarning(isCustom) - BalanceStatus.Loading -> { - hideWarning(isCustom) - if (wallet.currencyData.amountFormatted == null) { - tvExchangeRate.text = root.getString(R.string.wallet_balance_loading) - } + BalanceStatus.VerifiedOnline, + BalanceStatus.SameCurrencyTransactionInProgress -> hideMessage() + BalanceStatus.Loading -> if (wallet.currencyData.amountFormatted == null) { + showMessage(root.getString(R.string.wallet_balance_loading)) } BalanceStatus.TransactionInProgress -> - showWarning(root.getString(R.string.wallet_balance_tx_in_progress), isCustom) + showMessage(root.getString(R.string.wallet_balance_tx_in_progress)) BalanceStatus.Unreachable -> - showWarning(root.getString(R.string.wallet_balance_blockchain_unreachable), isCustom) + showMessage(root.getString(R.string.wallet_balance_blockchain_unreachable)) BalanceStatus.NoAccount -> - showWarning(root.getString(R.string.wallet_error_no_account), isCustom) + showMessage(root.getString(R.string.wallet_error_no_account)) else -> { } } } - private fun showWarning(message: String, isCustom: Boolean = false) { - toggleWarning(true, isCustom) - binding.tvStatusErrorMessage.text = message + private fun showMessage(message: String) { + toggleMessage(true) + binding.tvStatus.text = message } - private fun hideWarning(isCustom: Boolean = false) { - toggleWarning(false, isCustom) + private fun hideMessage() { + toggleMessage(false) } - private fun toggleWarning(show: Boolean, isCustom: Boolean = false) { - if (!show) { - binding.tvExchangeRate.show(!isCustom) - binding.tvCustomCurrency.show(isCustom) - } else { - binding.tvExchangeRate.hide() - binding.tvCustomCurrency.hide() - } - binding.tvStatusErrorMessage.show(show) + private fun toggleMessage(show: Boolean) { + binding.tvAmount.show(!show) + binding.tvStatus.show(show) } } } \ No newline at end of file diff --git a/app/src/main/res/layout/item_currency_wallet.xml b/app/src/main/res/layout/item_currency_wallet.xml index a2ebdd3909..aba8fd02f1 100644 --- a/app/src/main/res/layout/item_currency_wallet.xml +++ b/app/src/main/res/layout/item_currency_wallet.xml @@ -1,205 +1,165 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content"> - - + android:layout_marginStart="16dp" + android:layout_marginEnd="16dp" + android:layout_marginBottom="8dp" + android:background="@android:color/white" + android:elevation="3dp"> - - - - - + android:layout_marginTop="12dp" + android:layout_marginBottom="12dp" + android:layout_marginStart="16dp" + android:layout_marginEnd="16dp"> + + + android:id="@+id/tv_token_letter" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="2dp" + android:textColor="@android:color/white" + android:textSize="25sp" + android:textStyle="bold" + app:layout_constraintBottom_toBottomOf="@id/iv_currency" + app:layout_constraintEnd_toEndOf="@id/iv_currency" + app:layout_constraintStart_toStartOf="@id/iv_currency" + app:layout_constraintTop_toTopOf="@id/iv_currency" + tools:text="J" /> + android:id="@+id/guideline" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" + app:layout_constraintGuide_percent="0.5" /> + android:id="@+id/tv_currency" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:ellipsize="end" + android:maxLines="1" + android:textColor="@color/darkGray6" + android:textSize="16sp" + android:textStyle="bold" + app:lineHeight="24dp" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintBottom_toTopOf="@id/guideline" + app:layout_constraintStart_toEndOf="@id/iv_currency" + app:layout_constraintEnd_toStartOf="@+id/tv_amount" + tools:text="Binance Smart Chain Optimal" /> + + + android:id="@+id/tv_amount_fiat" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:maxEms="12" + android:maxLength="12" + android:maxLines="1" + android:textColor="@color/darkGray6" + android:textSize="16sp" + android:textStyle="bold" + android:textAlignment="viewEnd" + app:lineHeight="24dp" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintBottom_toTopOf="@id/guideline" + app:layout_constraintStart_toEndOf="@+id/guideline2" + app:layout_constraintEnd_toEndOf="parent" + tools:text="12300.43 $" /> + android:id="@+id/tv_amount" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:maxEms="12" + android:maxLength="12" + android:maxLines="1" + android:textColor="@color/darkGray2" + android:textSize="12sp" + android:textAlignment="viewEnd" + app:lineHeight="20dp" + app:layout_constraintTop_toBottomOf="@id/guideline" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toEndOf="@id/guideline2" + app:layout_constraintEnd_toEndOf="parent" + tools:text="2.002134 BTC" /> + android:id="@+id/tv_status" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:visibility="gone" + android:maxLines="1" + android:ellipsize="end" + android:textColor="@color/darkGray2" + android:textSize="12sp" + android:textAlignment="viewEnd" + app:lineHeight="20dp" + app:layout_constraintTop_toBottomOf="@id/guideline" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toEndOf="@id/guideline2" + app:layout_constraintEnd_toEndOf="parent" + tools:text="Unreachable..." /> + android:id="@+id/tv_exchange_rate" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:maxLines="1" + android:textColor="@color/darkGray2" + android:textSize="12sp" + app:lineHeight="20dp" + app:layout_constraintTop_toBottomOf="@id/guideline" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toEndOf="@id/iv_currency" + app:layout_constraintEnd_toStartOf="@id/guideline2" + tools:text="46 908 $" /> - - + android:id="@+id/tv_custom_currency" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:textColor="@color/darkGray2" + android:textSize="14sp" + android:text="@string/common_custom" + android:visibility="gone" + app:layout_constraintTop_toBottomOf="@id/guideline" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toEndOf="@id/iv_currency" + app:layout_constraintEnd_toStartOf="@id/guideline2" /> - - diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 10c1c9cb80..49c8fefbbb 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -11,6 +11,7 @@ @null @color/menu_accent_color + @style/Widget.AppTheme.CardView + + @@ -163,4 +168,4 @@ - \ No newline at end of file +