Implemented updating selected accounts

This commit is contained in:
dankito 2020-07-27 13:40:25 +02:00
parent 17fd1b0474
commit 04fba18316
4 changed files with 29 additions and 2 deletions

View File

@ -151,7 +151,7 @@ class HomeFragment : Fragment() {
} }
private fun updateAccountsTransactions() { private fun updateAccountsTransactions() {
presenter.updateAccountsTransactionsAsync { } presenter.updateSelectedBankAccountTransactionsAsync { }
} }
private fun handleGetTransactionsResponse(response: GetTransactionsResponse) { private fun handleGetTransactionsResponse(response: GetTransactionsResponse) {

View File

@ -136,6 +136,7 @@ open class AccountTransactionsControlView(
} }
protected open fun updateAccountTransactions(processingIndicatorButton: ProcessingIndicatorButton) { protected open fun updateAccountTransactions(processingIndicatorButton: ProcessingIndicatorButton) {
// TODO: or only update transactions of selected accounts?
presenter.updateAccountsTransactionsAsync { transactions -> presenter.updateAccountsTransactionsAsync { transactions ->
runLater { runLater {
processingIndicatorButton.resetIsProcessing() processingIndicatorButton.resetIsProcessing()

View File

@ -292,6 +292,10 @@ open class BankingPresenter(
updateAccountsTransactionsAsync(true) { } updateAccountsTransactionsAsync(true) { }
} }
open fun updateSelectedBankAccountTransactionsAsync(callback: (GetTransactionsResponse) -> Unit) {
updateBanksAccountsTransactionsAsync(selectedBankAccounts, false, callback)
}
protected open fun updateAccountsTransactionsAsync(abortIfTanIsRequired: Boolean = false, callback: (GetTransactionsResponse) -> Unit) { protected open fun updateAccountsTransactionsAsync(abortIfTanIsRequired: Boolean = false, callback: (GetTransactionsResponse) -> Unit) {
bankingClientsForAccounts.keys.forEach { account -> bankingClientsForAccounts.keys.forEach { account ->
account.accounts.forEach { bankAccount -> account.accounts.forEach { bankAccount ->
@ -302,6 +306,14 @@ open class BankingPresenter(
} }
} }
protected open fun updateBanksAccountsTransactionsAsync(accounts: List<BankAccount>, 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) { 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 val fromDate = bankAccount.lastRetrievedTransactionsTimestamp?.let { Date(it.millisSinceEpoch - OneDayMillis) } // one day before last received transactions

View File

@ -79,10 +79,24 @@ struct AccountTransactionsDialog: View {
} }
} }
.showNavigationBarTitle(LocalizedStringKey(title)) .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) { private func filterTransactions(_ query: String) {
self.filteredTransactions = presenter.searchSelectedAccountTransactions(query: query) self.filteredTransactions = presenter.searchSelectedAccountTransactions(query: query)