Fixed that if hideAccount changes also selectedAccounts have to be updated (e.g. a now hidden account should not be displayed and not be selected anymore)

This commit is contained in:
dankito 2021-11-06 14:19:06 +01:00
parent ab9de8ebdb
commit 8687320ef3
5 changed files with 28 additions and 7 deletions

View File

@ -115,10 +115,11 @@ open class BankAccountSettingsDialog : SettingsDialogBase() {
override fun saveChanges() {
account.userSetDisplayName = edtxtBankAccountName.text
val didHideAccountChange = account.hideAccount != swtchHideAccount.isChecked
account.hideAccount = swtchHideAccount.isChecked
account.includeInAutomaticAccountsUpdate = swtchIncludeInAutomaticAccountsUpdate.isChecked
presenter.accountUpdated(account)
presenter.accountUpdated(account, didHideAccountChange)
}
}

View File

@ -117,8 +117,8 @@ open class BankSettingsDialog : SettingsDialogBase() {
oldItem.displayIndex = oldPosition
newItem.displayIndex = newPosition
presenter.accountUpdated(oldItem)
presenter.accountUpdated(newItem)
presenter.accountUpdated(oldItem, false)
presenter.accountUpdated(newItem, false)
}

View File

@ -578,7 +578,11 @@ open class BankingPresenter(
}
}
open fun accountUpdated(account: TypedBankAccount) {
open fun accountUpdated(account: TypedBankAccount, didHideAccountChange: Boolean) {
if (didHideAccountChange) {
updateSelectedAccounts(account)
}
persistBankAsync(account.bank)
callBanksChangedListeners()
@ -969,6 +973,21 @@ open class BankingPresenter(
setSelectedAccounts(listOf(account))
}
private fun updateSelectedAccounts(changedAccount: TypedBankAccount) {
if (areAllAccountSelected) {
selectedAllAccounts()
} else if (isSingleSelectedBank(changedAccount.bank as TypedBankData)) {
selectedBank(changedAccount.bank as TypedBankData)
} else if (isSingleSelectedAccount(changedAccount) && changedAccount.hideAccount) {
// if bank of this account has other non hidden accounts, then select this bank
if (changedAccount.bank.accounts.withoutHiddenOnes().isNotEmpty()) {
selectedBank(changedAccount.bank as TypedBankData)
} else { // otherwise select all accounts
selectedAllAccounts()
}
}
}
protected open fun setSelectedAccounts(accounts: List<TypedBankAccount>) {
this._selectedAccounts = ArrayList(accounts.withoutHiddenOnes()) // make a copy

View File

@ -47,6 +47,6 @@ fun <T : IAccountTransaction> Iterable<T>.sortedByDate(): List<T> {
return this.sortedByDescending { it.valueDate.millisSinceEpoch }
}
fun <T : TypedBankAccount> Iterable<T>.withoutHiddenOnes(): List<T> {
fun <T : IBankAccount<*>> Iterable<T>.withoutHiddenOnes(): List<T> {
return this.filter { it.hideAccount == false }
}

View File

@ -157,11 +157,12 @@ struct BankAccountSettingsDialog: View {
private func donePressed() {
if hasUnsavedData {
account.userSetDisplayName = displayName
let didHideAccountChange = account.hideAccount != hideAccount
account.hideAccount = hideAccount
account.includeInAutomaticAccountsUpdate = includeInAutomaticAccountsUpdate
presenter.accountUpdated(account: account)
presenter.accountUpdated(account: account, didHideAccountChange: didHideAccountChange)
}
closeDialog()