Fixed tracking selected account type

This commit is contained in:
dankito 2020-04-29 22:06:14 +02:00
parent db948ddb08
commit d1b320307e
2 changed files with 23 additions and 6 deletions

View File

@ -0,0 +1,12 @@
package net.dankito.banking.ui.model
enum class SelectedAccountType {
AllAccounts,
SingleAccount,
SingleBankAccount
}

View File

@ -8,6 +8,7 @@ import net.dankito.banking.ui.IRouter
import net.dankito.banking.ui.model.Account import net.dankito.banking.ui.model.Account
import net.dankito.banking.ui.model.AccountTransaction import net.dankito.banking.ui.model.AccountTransaction
import net.dankito.banking.ui.model.BankAccount import net.dankito.banking.ui.model.BankAccount
import net.dankito.banking.ui.model.SelectedAccountType
import net.dankito.banking.ui.model.parameters.TransferMoneyData import net.dankito.banking.ui.model.parameters.TransferMoneyData
import net.dankito.banking.ui.model.responses.AddAccountResponse import net.dankito.banking.ui.model.responses.AddAccountResponse
import net.dankito.banking.ui.model.responses.BankingClientResponse import net.dankito.banking.ui.model.responses.BankingClientResponse
@ -54,7 +55,7 @@ open class BankingPresenter(
protected var selectedBankAccountsField = mutableListOf<BankAccount>() protected var selectedBankAccountsField = mutableListOf<BankAccount>()
protected var userSelectedSingleAccount = false protected var selectedAccountType = SelectedAccountType.AllAccounts
protected var saveAccountOnNextEnterTanInvocation = false protected var saveAccountOnNextEnterTanInvocation = false
@ -384,30 +385,34 @@ open class BankingPresenter(
open val balanceOfSelectedBankAccounts: BigDecimal open val balanceOfSelectedBankAccounts: BigDecimal
get() = sumBalance(selectedBankAccounts.map { it.balance }) get() = sumBalance(selectedBankAccounts.map { it.balance })
open val areAllAccountSelected: Boolean
get() = selectedAccountType == SelectedAccountType.AllAccounts
open fun isSingleSelectedAccount(account: Account): Boolean { open fun isSingleSelectedAccount(account: Account): Boolean {
return userSelectedSingleAccount return selectedAccountType == SelectedAccountType.SingleAccount
&& selectedBankAccountsField.map { it.account }.toSet().containsExactly(account) && selectedBankAccountsField.map { it.account }.toSet().containsExactly(account)
} }
open fun isSingleSelectedBankAccount(bankAccount: BankAccount): Boolean { open fun isSingleSelectedBankAccount(bankAccount: BankAccount): Boolean {
return userSelectedSingleAccount == false return selectedAccountType == SelectedAccountType.SingleBankAccount
&& selectedBankAccountsField.containsExactly(bankAccount) && selectedBankAccountsField.containsExactly(bankAccount)
} }
open fun selectedAllBankAccounts() { open fun selectedAllBankAccounts() {
userSelectedSingleAccount = false selectedAccountType = SelectedAccountType.AllAccounts
setSelectedBankAccounts(bankAccounts) setSelectedBankAccounts(bankAccounts)
} }
open fun selectedAccount(account: Account) { open fun selectedAccount(account: Account) {
userSelectedSingleAccount = true selectedAccountType = SelectedAccountType.SingleAccount
setSelectedBankAccounts(account.bankAccounts) setSelectedBankAccounts(account.bankAccounts)
} }
open fun selectedBankAccount(bankAccount: BankAccount) { open fun selectedBankAccount(bankAccount: BankAccount) {
userSelectedSingleAccount = false selectedAccountType = SelectedAccountType.SingleBankAccount
setSelectedBankAccounts(listOf(bankAccount)) setSelectedBankAccounts(listOf(bankAccount))
} }