From 8687320ef395fe0f45b5faca2d2842c0b1ccfa4a Mon Sep 17 00:00:00 2001 From: dankito Date: Sat, 6 Nov 2021 14:19:06 +0100 Subject: [PATCH] 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) --- .../settings/BankAccountSettingsDialog.kt | 3 ++- .../dialogs/settings/BankSettingsDialog.kt | 4 ++-- .../banking/ui/presenter/BankingPresenter.kt | 21 ++++++++++++++++++- .../net/dankito/banking/util/Extensions.kt | 2 +- .../dialogs/BankAccountSettingsDialog.swift | 5 +++-- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankAccountSettingsDialog.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankAccountSettingsDialog.kt index c4470971..669eefb5 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankAccountSettingsDialog.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankAccountSettingsDialog.kt @@ -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) } } \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankSettingsDialog.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankSettingsDialog.kt index b52e0b2e..5009c749 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankSettingsDialog.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankSettingsDialog.kt @@ -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) } 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 57d44d1d..ca9b9755 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 @@ -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) { this._selectedAccounts = ArrayList(accounts.withoutHiddenOnes()) // make a copy 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 f2e905cb..4c15faaf 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 @@ -47,6 +47,6 @@ fun Iterable.sortedByDate(): List { return this.sortedByDescending { it.valueDate.millisSinceEpoch } } -fun Iterable.withoutHiddenOnes(): List { +fun > Iterable.withoutHiddenOnes(): List { return this.filter { it.hideAccount == false } } \ No newline at end of file diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/BankAccountSettingsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/BankAccountSettingsDialog.swift index a2e1df63..df7f4ec0 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/BankAccountSettingsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/BankAccountSettingsDialog.swift @@ -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()