From 31cc59c88eea4411c759637638c7678267d5e1cb Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 30 Sep 2020 04:39:26 +0200 Subject: [PATCH] Fixed that update(All|Selected)AccountsTransactionsAsync() didn't call callback if there are no accounts to update so that UI couldn't update / reset its state --- .../banking/ui/presenter/BankingPresenter.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 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 b2d3544a..2fe350c0 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 @@ -348,20 +348,30 @@ open class BankingPresenter( updateAllAccountsTransactionsAsync() } - open fun updateAllAccountsTransactionsAsync(callback: ((GetTransactionsResponse) -> Unit)? = null) { + open fun updateAllAccountsTransactionsAsync(done: (() -> Unit)? = null) { val accountsToUpdate = allAccounts.filter { considerAccountInAutomaticUpdates(it) } - updateAccountsTransactionsAsync(accountsToUpdate, true, callback) + if (accountsToUpdate.isNotEmpty()) { + updateAccountsTransactionsAsync(accountsToUpdate, true) { done?.invoke() } + } + else if (allAccounts.isNotEmpty()) { + done?.invoke() + } } - open fun updateSelectedAccountsTransactionsAsync(callback: ((GetTransactionsResponse) -> Unit)? = null) { + open fun updateSelectedAccountsTransactionsAsync(done: (() -> Unit)? = null) { var accountsToUpdate = selectedAccounts.filter { considerAccountInAutomaticUpdates(it) } if (accountsToUpdate.isEmpty() && (selectedAccountType == SelectedAccountType.SingleAccount || (selectedAccountType == SelectedAccountType.SingleBank && selectedAccounts.size == 1))) { accountsToUpdate = selectedAccounts } - updateAccountsTransactionsAsync(accountsToUpdate, false, callback) + if (accountsToUpdate.isNotEmpty()) { + updateAccountsTransactionsAsync(accountsToUpdate, false) { done?.invoke() } + } + else if (allAccounts.isNotEmpty()) { + done?.invoke() + } } protected open fun considerAccountInAutomaticUpdates(account: TypedBankAccount): Boolean {