From babc74179a1ff10c72b65bd97319725598cdcd15 Mon Sep 17 00:00:00 2001 From: dankito Date: Sat, 6 Nov 2021 01:59:15 +0100 Subject: [PATCH] By default transactions don't get sorted anymore. Is not required in all cases --- .../android/dialogs/settings/SettingsDialog.kt | 2 +- .../dialogs/mainwindow/controls/MainMenuBar.kt | 2 +- .../banking/ui/presenter/BankingPresenter.kt | 17 +++++++++++++---- .../net/dankito/banking/util/Extensions.kt | 6 ++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/SettingsDialog.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/SettingsDialog.kt index 743b3b21..2c02c78b 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/SettingsDialog.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/SettingsDialog.kt @@ -139,7 +139,7 @@ open class SettingsDialog : SettingsDialogBase() { val config = FileChooserDialogConfig(initialDirectory = initialDirectory, suggestedFilenameForSaveFileDialog = suggestedFilename) FileChooserDialog().showSaveFileInFullscreenDialog(activity, permissionsService, config) { _, selectedFile -> selectedFile?.let { - val transactions = presenter.allTransactions.map { mapTransaction(it) } + val transactions = presenter.allTransactionsSorted.map { mapTransaction(it) } CsvAccountTransactionsExporter().export(selectedFile, transactions) diff --git a/ui/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/controls/MainMenuBar.kt b/ui/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/controls/MainMenuBar.kt index d617ec16..6141b23c 100644 --- a/ui/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/controls/MainMenuBar.kt +++ b/ui/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/controls/MainMenuBar.kt @@ -133,7 +133,7 @@ open class MainMenuBar(protected val presenter: BankingPresenter) : View() { destinationFile = File(destinationFile.absolutePath + ".csv") } - val transactions = presenter.allTransactions.map { mapTransaction(it) } + val transactions = presenter.allTransactionsSorted.map { mapTransaction(it) } CsvAccountTransactionsExporter().export(destinationFile, transactions) } 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 2f3c6355..955af9e9 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 @@ -48,8 +48,6 @@ import io.ktor.http.cio.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch -import net.dankito.banking.ui.model.issues.CreateTicketRequestDto -import net.dankito.banking.ui.model.issues.IssueDescriptionFormat open class BankingPresenter( @@ -796,11 +794,14 @@ open class BankingPresenter( open fun searchAccountTransactions(query: String, transactions: List): List { val queryLowercase = query.trim().toLowerCase() + // get transactions sorted by date + val transactionsSorted = transactions.toSet().sortedByDate() + if (queryLowercase.isEmpty()) { - return transactions + return transactionsSorted } - return transactions.filter { + return transactionsSorted.filter { it.otherPartyName?.toLowerCase()?.contains(queryLowercase) == true || it.reference.toLowerCase().contains(queryLowercase) || it.bookingText?.toLowerCase()?.contains(queryLowercase) == true @@ -989,6 +990,9 @@ open class BankingPresenter( open val allTransactions: List get() = getTransactionsForAccounts(allAccounts) + open val allTransactionsSorted: List + get() = getTransactionsForAccountsSorted(allAccounts) + open val balanceOfAllAccounts: BigDecimal get() = getBalanceForBanks(allBanks) @@ -1042,6 +1046,11 @@ open class BankingPresenter( protected open fun getTransactionsForAccounts(accounts: Collection): List { return accounts.flatMap { it.bookedTransactions }.sortedByDescending { it.valueDate.millisSinceEpoch } // TODO: someday add unbooked transactions } + + protected open fun getTransactionsForAccountsSorted(accounts: Collection): List { + return getTransactionsForAccounts(accounts).sortedByDate() + } + open fun currencyIsoCodeOfAccounts(accounts: List): String { // TODO: this is of course not right, it assumes that all accounts have the same currency. But we don't support e.g. calculating the balance of accounts with different currencies anyway // at start up list with selectedAccounts is empty 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 420fa1f0..e93694ff 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 @@ -1,5 +1,6 @@ package net.dankito.banking.util +import net.dankito.banking.ui.model.IAccountTransaction import net.dankito.banking.ui.model.OrderedDisplayable @@ -37,4 +38,9 @@ fun List.sortedByDisplayIndex(): List { fun Collection.sortedByDisplayIndex(): Collection { return this.sortedBy { it.displayIndex } +} + + +fun Iterable.sortedByDate(): List { + return this.sortedByDescending { it.valueDate.millisSinceEpoch } } \ No newline at end of file