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

This commit is contained in:
dankito 2020-09-30 04:39:26 +02:00
parent 75525d704a
commit 31cc59c88e
1 changed files with 14 additions and 4 deletions

View File

@ -348,20 +348,30 @@ open class BankingPresenter(
updateAllAccountsTransactionsAsync() updateAllAccountsTransactionsAsync()
} }
open fun updateAllAccountsTransactionsAsync(callback: ((GetTransactionsResponse) -> Unit)? = null) { open fun updateAllAccountsTransactionsAsync(done: (() -> Unit)? = null) {
val accountsToUpdate = allAccounts.filter { considerAccountInAutomaticUpdates(it) } 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) } var accountsToUpdate = selectedAccounts.filter { considerAccountInAutomaticUpdates(it) }
if (accountsToUpdate.isEmpty() && (selectedAccountType == SelectedAccountType.SingleAccount if (accountsToUpdate.isEmpty() && (selectedAccountType == SelectedAccountType.SingleAccount
|| (selectedAccountType == SelectedAccountType.SingleBank && selectedAccounts.size == 1))) { || (selectedAccountType == SelectedAccountType.SingleBank && selectedAccounts.size == 1))) {
accountsToUpdate = selectedAccounts 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 { protected open fun considerAccountInAutomaticUpdates(account: TypedBankAccount): Boolean {