diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/token/TokenBalanceModule.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/token/TokenBalanceModule.kt index 1fa093e8acd..25633a8f905 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/token/TokenBalanceModule.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/token/TokenBalanceModule.kt @@ -41,7 +41,7 @@ class TokenBalanceModule { balanceService, BalanceViewItemFactory(), tokenTransactionsService, - TransactionViewItemFactory(App.evmLabelManager, App.contactsRepository), + TransactionViewItemFactory(App.evmLabelManager, App.contactsRepository, App.balanceHiddenManager), App.balanceHiddenManager, App.connectivityManager ) as T diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionViewItemFactory.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionViewItemFactory.kt index 8ee704c6182..6c67d0d8045 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionViewItemFactory.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionViewItemFactory.kt @@ -2,6 +2,7 @@ package io.horizontalsystems.bankwallet.modules.transactions import io.horizontalsystems.bankwallet.R import io.horizontalsystems.bankwallet.core.App +import io.horizontalsystems.bankwallet.core.managers.BalanceHiddenManager import io.horizontalsystems.bankwallet.core.managers.EvmLabelManager import io.horizontalsystems.bankwallet.core.providers.Translator import io.horizontalsystems.bankwallet.entities.CurrencyValue @@ -42,11 +43,24 @@ import java.util.Date class TransactionViewItemFactory( private val evmLabelManager: EvmLabelManager, - private val contactsRepository: ContactsRepository + private val contactsRepository: ContactsRepository, + private val balanceHiddenManager: BalanceHiddenManager, ) { private val cache = mutableMapOf>() + fun updateCache() { + cache.forEach { (recordUid, map) -> + map.forEach { (createdAt, viewItem) -> + cache[recordUid] = mapOf( + createdAt to viewItem.copy( + showAmount = !balanceHiddenManager.balanceHidden, + ) + ) + } + } + } + fun convertToViewItemCached(transactionItem: TransactionItem): TransactionViewItem { cache[transactionItem.record.uid]?.get(transactionItem.createdAt)?.let { return it @@ -66,6 +80,7 @@ class TransactionViewItemFactory( is TransactionValue.NftValue -> { TransactionViewItem.Icon.Regular(nftMetadata[value.nftUid]?.previewImageUrl, R.drawable.icon_24_nft_placeholder, rectangle = true) } + is TransactionValue.CoinValue, is TransactionValue.RawValue, is TransactionValue.TokenValue -> { @@ -92,6 +107,7 @@ class TransactionViewItemFactory( frontUrl = nftMetadata[primaryValue.nftUid]?.previewImageUrl frontPlaceHolder = R.drawable.icon_24_nft_placeholder } + is TransactionValue.CoinValue, is TransactionValue.RawValue, is TransactionValue.TokenValue -> { @@ -113,6 +129,7 @@ class TransactionViewItemFactory( backUrl = nftMetadata[secondaryValue.nftUid]?.previewImageUrl backPlaceHolder = R.drawable.icon_24_nft_placeholder } + is TransactionValue.CoinValue, is TransactionValue.RawValue, is TransactionValue.TokenValue -> { @@ -142,12 +159,15 @@ class TransactionViewItemFactory( incomingValues.size == 1 && outgoingValues.isEmpty() -> { singleValueIconType(incomingValues[0], nftMetadata) } + incomingValues.isEmpty() && outgoingValues.size == 1 -> { singleValueIconType(outgoingValues[0], nftMetadata) } + incomingValues.size == 1 && outgoingValues.size == 1 -> { doubleValueIconType(incomingValues[0], outgoingValues[0], nftMetadata) } + else -> { TransactionViewItem.Icon.Platform(blockchainType) } @@ -185,12 +205,14 @@ class TransactionViewItemFactory( progress, icon ) + is BinanceChainOutgoingTransactionRecord -> createViewItemFromBinanceChainOutgoingTransactionRecord( record, transactionItem.currencyValue, progress, icon ) + is BitcoinIncomingTransactionRecord -> createViewItemFromBitcoinIncomingTransactionRecord( record, transactionItem.currencyValue, @@ -198,6 +220,7 @@ class TransactionViewItemFactory( lastBlockTimestamp, icon ) + is BitcoinOutgoingTransactionRecord -> createViewItemFromBitcoinOutgoingTransactionRecord( record, transactionItem.currencyValue, @@ -205,6 +228,7 @@ class TransactionViewItemFactory( lastBlockTimestamp, icon ) + is ContractCallTransactionRecord -> { val (incomingValues, outgoingValues) = EvmTransactionRecord.combined(record.incomingEvents, record.outgoingEvents) createViewItemFromContractCallTransactionRecord( @@ -221,6 +245,7 @@ class TransactionViewItemFactory( nftMetadata = transactionItem.nftMetadata ) } + is ExternalContractCallTransactionRecord -> { val (incomingValues, outgoingValues) = EvmTransactionRecord.combined(record.incomingEvents, record.outgoingEvents) createViewItemFromExternalContractCallTransactionRecord( @@ -384,6 +409,7 @@ class TransactionViewItemFactory( icon = icon ) } + else -> throw IllegalArgumentException("Undefined record type ${record.javaClass.name}") } } @@ -405,6 +431,7 @@ class TransactionViewItemFactory( subtitle = Translator.getString(R.string.Transactions_Unknown_Description), primaryValue = primaryValue, secondaryValue = secondaryValue, + showAmount = !balanceHiddenManager.balanceHidden, date = Date(record.timestamp * 1000), icon = icon ?: iconType(record.blockchainType, incomingValues, outgoingValues, mutableMapOf()) ) @@ -431,6 +458,7 @@ class TransactionViewItemFactory( subtitle = record.to?.let { to -> Translator.getString(R.string.Transactions_To, mapped(to, record.blockchainType)) } ?: "", primaryValue = primaryValue, secondaryValue = secondaryValue, + showAmount = !balanceHiddenManager.balanceHidden, date = Date(record.timestamp * 1000), sentToSelf = record.sentToSelf, icon = icon ?: singleValueIconType(record.value, nftMetadata) @@ -454,6 +482,7 @@ class TransactionViewItemFactory( subtitle = record.from?.let { from -> Translator.getString(R.string.Transactions_From, mapped(from, record.blockchainType)) } ?: "", primaryValue = primaryValue, secondaryValue = secondaryValue, + showAmount = !balanceHiddenManager.balanceHidden, date = Date(record.timestamp * 1000), icon = icon ?: singleValueIconType(record.value) ) @@ -484,6 +513,7 @@ class TransactionViewItemFactory( subtitle = mapped(record.exchangeAddress, record.blockchainType), primaryValue = primaryValue, secondaryValue = secondaryValue, + showAmount = !balanceHiddenManager.balanceHidden, date = Date(record.timestamp * 1000), icon = icon ?: doubleValueIconType(record.valueOut, record.valueIn) ) @@ -504,6 +534,7 @@ class TransactionViewItemFactory( subtitle = mapped(record.exchangeAddress, record.blockchainType), primaryValue = primaryValue, secondaryValue = secondaryValue, + showAmount = !balanceHiddenManager.balanceHidden, date = Date(record.timestamp * 1000), icon = icon ?: doubleValueIconType(record.valueOut, record.valueIn) ) @@ -574,6 +605,7 @@ class TransactionViewItemFactory( subtitle = Translator.getString(R.string.Transactions_To, mapped(to, blockchainType)), primaryValue = primaryValue, secondaryValue = secondaryValue, + showAmount = !balanceHiddenManager.balanceHidden, date = Date(timestamp * 1000), sentToSelf = sentToSelf, icon = icon ?: singleValueIconType(value, nftMetadata) @@ -612,6 +644,7 @@ class TransactionViewItemFactory( ), primaryValue = primaryValue, secondaryValue = secondaryValue, + showAmount = !balanceHiddenManager.balanceHidden, date = Date(timestamp * 1000), icon = icon ?: singleValueIconType(value) ) @@ -657,6 +690,7 @@ class TransactionViewItemFactory( subtitle = mapped(contractAddress, blockchainType), primaryValue = primaryValue, secondaryValue = secondaryValue, + showAmount = !balanceHiddenManager.balanceHidden, date = Date(timestamp * 1000), icon = icon ?: iconType(blockchainType, incomingValues, outgoingValues, nftMetadata) ) @@ -707,6 +741,7 @@ class TransactionViewItemFactory( subtitle = subTitle, primaryValue = primaryValue, secondaryValue = secondaryValue, + showAmount = !balanceHiddenManager.balanceHidden, date = Date(timestamp * 1000), icon = icon ?: iconType(blockchainType, incomingValues, outgoingValues, nftMetadata) ) @@ -750,6 +785,7 @@ class TransactionViewItemFactory( subtitle = subtitle, primaryValue = primaryValue, secondaryValue = secondaryValue, + showAmount = !balanceHiddenManager.balanceHidden, date = Date(record.timestamp * 1000), sentToSelf = record.sentToSelf, doubleSpend = record.conflictingHash != null, @@ -791,6 +827,7 @@ class TransactionViewItemFactory( subtitle = subtitle, primaryValue = primaryValue, secondaryValue = secondaryValue, + showAmount = !balanceHiddenManager.balanceHidden, date = Date(record.timestamp * 1000), sentToSelf = false, doubleSpend = record.conflictingHash != null, @@ -822,6 +859,7 @@ class TransactionViewItemFactory( subtitle = Translator.getString(R.string.Transactions_To, mapped(record.to, record.blockchainType)), primaryValue = primaryValue, secondaryValue = secondaryValue, + showAmount = !balanceHiddenManager.balanceHidden, date = Date(record.timestamp * 1000), sentToSelf = record.sentToSelf, icon = icon ?: singleValueIconType(record.value) @@ -849,6 +887,7 @@ class TransactionViewItemFactory( ), primaryValue = primaryValue, secondaryValue = secondaryValue, + showAmount = !balanceHiddenManager.balanceHidden, date = Date(record.timestamp * 1000), icon = icon ?: singleValueIconType(record.value) ) @@ -885,6 +924,7 @@ class TransactionViewItemFactory( subtitle = mapped(spender, blockchainType), primaryValue = primaryValue, secondaryValue = secondaryValue, + showAmount = !balanceHiddenManager.balanceHidden, date = Date(timestamp * 1000), icon = icon ?: singleValueIconType(value) ) @@ -900,6 +940,7 @@ class TransactionViewItemFactory( val text = nftMetadata[value.nftUid]?.name ?: value.tokenName?.let { "$it #${value.nftUid.tokenId}" } ?: "#${value.nftUid.tokenId}" getColoredValue(text, ColorName.Grey) } + is TransactionValue.CoinValue, is TransactionValue.RawValue, is TransactionValue.TokenValue -> { diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsModule.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsModule.kt index e22e504a1d2..91d121e8f1e 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsModule.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsModule.kt @@ -25,7 +25,8 @@ object TransactionsModule { TransactionFilterService(), NftMetadataService(App.nftMetadataManager) ), - TransactionViewItemFactory(App.evmLabelManager, App.contactsRepository) + TransactionViewItemFactory(App.evmLabelManager, App.contactsRepository, App.balanceHiddenManager), + App.balanceHiddenManager ) as T } } diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsScreen.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsScreen.kt index 676a8a41a86..25d66a0a20b 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsScreen.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsScreen.kt @@ -359,15 +359,18 @@ fun TransactionCell(item: TransactionViewItem, position: SectionItemPosition, on maxLines = 1, ) Spacer(Modifier.weight(1f)) - item.primaryValue?.let { coloredValue -> - Text( - text = coloredValue.value, - style = ComposeAppTheme.typography.body, - color = coloredValue.color.compose(), - overflow = TextOverflow.Ellipsis, - maxLines = 1, - ) + if (item.showAmount) { + item.primaryValue?.let { coloredValue -> + Text( + text = coloredValue.value, + style = ComposeAppTheme.typography.body, + color = coloredValue.color.compose(), + overflow = TextOverflow.Ellipsis, + maxLines = 1, + ) + } } + if (item.doubleSpend) { Image( modifier = Modifier.padding(start = 6.dp), @@ -399,13 +402,15 @@ fun TransactionCell(item: TransactionViewItem, position: SectionItemPosition, on .padding(end = 8.dp), maxLines = 2, ) - item.secondaryValue?.let { coloredValue -> - Text( - text = coloredValue.value, - style = ComposeAppTheme.typography.subhead2, - color = coloredValue.color.compose(), - maxLines = 1, - ) + if (item.showAmount) { + item.secondaryValue?.let { coloredValue -> + Text( + text = coloredValue.value, + style = ComposeAppTheme.typography.subhead2, + color = coloredValue.color.compose(), + maxLines = 1, + ) + } } } } diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsService.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsService.kt index e446bb41754..9e8bbf226f8 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsService.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsService.kt @@ -31,7 +31,7 @@ class TransactionsService( private val transactionAdapterManager: TransactionAdapterManager, private val walletManager: IWalletManager, private val transactionFilterService: TransactionFilterService, - private val nftMetadataService: NftMetadataService + private val nftMetadataService: NftMetadataService, ) : Clearable { val filterResetEnabled by transactionFilterService::resetEnabled @@ -274,6 +274,10 @@ class TransactionsService( private val executorService = Executors.newCachedThreadPool() + fun refreshList() { + itemsSubject.onNext(transactionItems) + } + fun setFilterType(f: FilterTransactionType) { executorService.submit { typesSubject.onNext(Pair(transactionFilterService.getFilterTypes(), f)) diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsViewModel.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsViewModel.kt index e6dff6f1c8c..ef568a8bb25 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsViewModel.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsViewModel.kt @@ -2,7 +2,9 @@ package io.horizontalsystems.bankwallet.modules.transactions import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import io.horizontalsystems.bankwallet.R +import io.horizontalsystems.bankwallet.core.managers.BalanceHiddenManager import io.horizontalsystems.bankwallet.core.providers.Translator import io.horizontalsystems.bankwallet.core.subscribeIO import io.horizontalsystems.bankwallet.entities.CurrencyValue @@ -16,12 +18,15 @@ import io.horizontalsystems.core.helpers.DateHelper import io.horizontalsystems.marketkit.models.Blockchain import io.horizontalsystems.marketkit.models.BlockchainType import io.reactivex.disposables.CompositeDisposable +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import java.util.Calendar import java.util.Date class TransactionsViewModel( private val service: TransactionsService, - private val transactionViewItem2Factory: TransactionViewItemFactory + private val transactionViewItem2Factory: TransactionViewItemFactory, + private val balanceHiddenManager: BalanceHiddenManager ) : ViewModel() { var tmpItemToShow: TransactionItem? = null @@ -90,6 +95,13 @@ class TransactionsViewModel( .let { disposables.add(it) } + + viewModelScope.launch(Dispatchers.IO) { + balanceHiddenManager.balanceHiddenFlow.collect { + transactionViewItem2Factory.updateCache() + service.refreshList() + } + } } fun setFilterTransactionType(filterType: FilterTransactionType) { @@ -142,6 +154,7 @@ data class TransactionViewItem( val primaryValue: ColoredValue?, val secondaryValue: ColoredValue?, val date: Date, + val showAmount: Boolean = true, val sentToSelf: Boolean = false, val doubleSpend: Boolean = false, val locked: Boolean? = null,