From ab9de8ebdb0d46f0735732d4f0817cd716e1cf30 Mon Sep 17 00:00:00 2001 From: dankito Date: Sat, 6 Nov 2021 13:54:52 +0100 Subject: [PATCH] Fixed that allAccounts and allTransactions also contained hidden accounts --- .../banking/ui/presenter/BankingPresenter.kt | 30 +++++++++---------- .../net/dankito/banking/util/Extensions.kt | 6 ++++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt index a6501cf9..57d44d1d 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -388,7 +388,7 @@ open class BankingPresenter( } open fun updateAllAccountsTransactionsAsync(callback: ((GetTransactionsResponse?) -> Unit)? = null) { - val accountsToUpdate = allAccounts.filter { considerAccountInAutomaticUpdates(it) } + val accountsToUpdate = allVisibleAccounts.filter { considerAccountInAutomaticUpdates(it) } if (accountsToUpdate.isNotEmpty()) { updateAccountsTransactionsAsync(accountsToUpdate, true, callback) @@ -641,7 +641,7 @@ open class BankingPresenter( // TODO: show originatorInformation to user val transferMoneyData = TransferMoneyData( - allAccounts.first(), + allVisibleAccounts.first(), epcQrCode.receiverName, epcQrCode.iban, epcQrCode.bic ?: "", @@ -671,7 +671,7 @@ open class BankingPresenter( if (invoiceData.potentialTotalAmount != null || invoiceData.potentialIban != null) { // if at least an amount or IBAN could get extracted val transferMoneyData = TransferMoneyData( - allAccounts.first(), "", + allVisibleAccounts.first(), "", invoiceData.potentialIban ?: "", invoiceData.potentialBic ?: "", invoiceData.potentialTotalAmount ?: BigDecimal.Zero, "") @@ -954,7 +954,7 @@ open class BankingPresenter( open fun selectedAllAccounts() { selectedAccountType = SelectedAccountType.AllAccounts - setSelectedAccounts(allAccounts) + setSelectedAccounts(allVisibleAccounts) } open fun selectedBank(bank: TypedBankData) { @@ -970,7 +970,7 @@ open class BankingPresenter( } protected open fun setSelectedAccounts(accounts: List) { - this._selectedAccounts = ArrayList(accounts.filter { it.hideAccount == false }) // make a copy + this._selectedAccounts = ArrayList(accounts.withoutHiddenOnes()) // make a copy callSelectedAccountsChangedListeners(_selectedAccounts) } @@ -982,24 +982,24 @@ open class BankingPresenter( open val allBanksSortedByDisplayIndex: List get() = allBanks.sortedByDisplayIndex() - open val allAccounts: List - get() = allBanks.flatMap { it.accounts } + open val allVisibleAccounts: List + get() = allBanks.flatMap { it.accounts }.withoutHiddenOnes() open val allTransactions: List - get() = getTransactionsForAccounts(allAccounts) + get() = getTransactionsForAccounts(allVisibleAccounts) open val allTransactionsSorted: List - get() = getTransactionsForAccountsSorted(allAccounts) + get() = getTransactionsForAccountsSorted(allVisibleAccounts) open val balanceOfAllAccounts: BigDecimal get() = getBalanceForBanks(allBanks) open val accountsSupportingRetrievingAccountTransactions: List - get() = allAccounts.filter { it.supportsRetrievingAccountTransactions } + get() = allVisibleAccounts.filter { it.supportsRetrievingAccountTransactions } open val hasAccountsSupportingRetrievingTransactions: Boolean - get() = doAccountsSupportRetrievingTransactions(allAccounts) + get() = doAccountsSupportRetrievingTransactions(allVisibleAccounts) open val doSelectedAccountsSupportRetrievingTransactions: Boolean get() = doAccountsSupportRetrievingTransactions(selectedAccounts) @@ -1010,10 +1010,10 @@ open class BankingPresenter( open val accountsSupportingRetrievingBalance: List - get() = allAccounts.filter { it.supportsRetrievingBalance } + get() = allVisibleAccounts.filter { it.supportsRetrievingBalance } open val hasAccountsSupportingRetrievingBalance: Boolean - get() = doAccountsSupportRetrievingBalance(allAccounts) + get() = doAccountsSupportRetrievingBalance(allVisibleAccounts) open val doSelectedAccountsSupportRetrievingBalance: Boolean get() = doAccountsSupportRetrievingBalance(selectedAccounts) @@ -1024,14 +1024,14 @@ open class BankingPresenter( open val accountsSupportingTransferringMoney: List - get() = allAccounts.filter { it.supportsTransferringMoney } + get() = allVisibleAccounts.filter { it.supportsTransferringMoney } open val accountsSupportingTransferringMoneySortedByDisplayIndex: List get() = accountsSupportingTransferringMoney .sortedWith(BankAccountComparator()) open val hasAccountsSupportTransferringMoney: Boolean - get() = doAccountsSupportTransferringMoney(allAccounts) + get() = doAccountsSupportTransferringMoney(allVisibleAccounts) open val doSelectedAccountsSupportTransferringMoney: Boolean get() = doAccountsSupportTransferringMoney(selectedAccounts) diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/util/Extensions.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/util/Extensions.kt index e93694ff..f2e905cb 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/util/Extensions.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/util/Extensions.kt @@ -1,7 +1,9 @@ package net.dankito.banking.util import net.dankito.banking.ui.model.IAccountTransaction +import net.dankito.banking.ui.model.IBankAccount import net.dankito.banking.ui.model.OrderedDisplayable +import net.dankito.banking.ui.model.TypedBankAccount fun String.ofMaxLength(maxLength: Int): String { @@ -43,4 +45,8 @@ fun Collection.sortedByDisplayIndex(): Collection fun Iterable.sortedByDate(): List { return this.sortedByDescending { it.valueDate.millisSinceEpoch } +} + +fun Iterable.withoutHiddenOnes(): List { + return this.filter { it.hideAccount == false } } \ No newline at end of file