From 04fba18316ee7541884a6768d2d620ece349cf9f Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 27 Jul 2020 13:40:25 +0200 Subject: [PATCH] Implemented updating selected accounts --- .../banking/ui/android/home/HomeFragment.kt | 2 +- .../controls/AccountTransactionsControlView.kt | 1 + .../banking/ui/presenter/BankingPresenter.kt | 12 ++++++++++++ .../ui/views/AccountTransactionsDialog.swift | 16 +++++++++++++++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt index e6f7aed4..debfe603 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/home/HomeFragment.kt @@ -151,7 +151,7 @@ class HomeFragment : Fragment() { } private fun updateAccountsTransactions() { - presenter.updateAccountsTransactionsAsync { } + presenter.updateSelectedBankAccountTransactionsAsync { } } private fun handleGetTransactionsResponse(response: GetTransactionsResponse) { diff --git a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsControlView.kt b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsControlView.kt index 4fa17891..8339e4ed 100644 --- a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsControlView.kt +++ b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsControlView.kt @@ -136,6 +136,7 @@ open class AccountTransactionsControlView( } protected open fun updateAccountTransactions(processingIndicatorButton: ProcessingIndicatorButton) { + // TODO: or only update transactions of selected accounts? presenter.updateAccountsTransactionsAsync { transactions -> runLater { processingIndicatorButton.resetIsProcessing() 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 c8424833..c940375d 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 @@ -292,6 +292,10 @@ open class BankingPresenter( updateAccountsTransactionsAsync(true) { } } + open fun updateSelectedBankAccountTransactionsAsync(callback: (GetTransactionsResponse) -> Unit) { + updateBanksAccountsTransactionsAsync(selectedBankAccounts, false, callback) + } + protected open fun updateAccountsTransactionsAsync(abortIfTanIsRequired: Boolean = false, callback: (GetTransactionsResponse) -> Unit) { bankingClientsForAccounts.keys.forEach { account -> account.accounts.forEach { bankAccount -> @@ -302,6 +306,14 @@ open class BankingPresenter( } } + protected open fun updateBanksAccountsTransactionsAsync(accounts: List, abortIfTanIsRequired: Boolean = false, callback: (GetTransactionsResponse) -> Unit) { + accounts.forEach { bankAccount -> + if (bankAccount.supportsRetrievingAccountTransactions) { + updateBankAccountTransactionsAsync(bankAccount, abortIfTanIsRequired, callback) + } + } + } + protected open fun updateBankAccountTransactionsAsync(bankAccount: BankAccount, abortIfTanIsRequired: Boolean, callback: (GetTransactionsResponse) -> Unit) { val fromDate = bankAccount.lastRetrievedTransactionsTimestamp?.let { Date(it.millisSinceEpoch - OneDayMillis) } // one day before last received transactions diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift index f3d20a7c..5d43078d 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift @@ -79,10 +79,24 @@ struct AccountTransactionsDialog: View { } } .showNavigationBarTitle(LocalizedStringKey(title)) - .navigationBarHidden(false) + .navigationBarItems(trailing: Button( + action: { self.retrieveTransactions() }, + label: { Image(systemName: "arrow.2.circlepath") } + )) } + private func retrieveTransactions() { + presenter.updateSelectedBankAccountTransactionsAsync { response in + if response.isSuccessful { + self.filterTransactions(self.searchText) + } + else if response.userCancelledAction == false { + // TODO: show updating transactions failed message + } + } + } + private func filterTransactions(_ query: String) { self.filteredTransactions = presenter.searchSelectedAccountTransactions(query: query)