From 4ffb68eba452c58f4a8ec1174b15b3a4a9b96eb3 Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 27 Jul 2020 00:05:55 +0200 Subject: [PATCH] Implemented filtering account transactions --- .../banking/ui/presenter/BankingPresenter.kt | 8 +++- .../BankingiOSApp.xcodeproj/project.pbxproj | 12 ++++-- .../ui/views/AccountTransactionsDialog.swift | 43 +++++++++++++++++-- 3 files changed, 53 insertions(+), 10 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 1390df48..c8424833 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 @@ -456,13 +456,17 @@ open class BankingPresenter( open fun searchSelectedAccountTransactions(query: String): List { + return searchAccountTransactions(query, selectedBankAccountsAccountTransactions) + } + + open fun searchAccountTransactions(query: String, transactions: List): List { val queryLowercase = query.trim().toLowerCase() if (queryLowercase.isEmpty()) { - return selectedBankAccountsAccountTransactions + return transactions } - return selectedBankAccountsAccountTransactions.filter { + return transactions.filter { it.otherPartyName?.toLowerCase()?.contains(queryLowercase) == true || it.usage.toLowerCase().contains(queryLowercase) || it.bookingText?.toLowerCase()?.contains(queryLowercase) == true diff --git a/ui/BankingiOSApp/BankingiOSApp.xcodeproj/project.pbxproj b/ui/BankingiOSApp/BankingiOSApp.xcodeproj/project.pbxproj index 6d111989..40fa6307 100644 --- a/ui/BankingiOSApp/BankingiOSApp.xcodeproj/project.pbxproj +++ b/ui/BankingiOSApp/BankingiOSApp.xcodeproj/project.pbxproj @@ -12,7 +12,6 @@ 366FA4DC24C479120094F009 /* BankInfoListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 366FA4DB24C479120094F009 /* BankInfoListItem.swift */; }; 366FA4E024C4924A0094F009 /* RemitteeListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 366FA4DF24C4924A0094F009 /* RemitteeListItem.swift */; }; 366FA4E224C4ED6C0094F009 /* EnterTanDialog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 366FA4E124C4ED6C0094F009 /* EnterTanDialog.swift */; }; - 366FA4E424C4F2C70094F009 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 366FA4E324C4F2C70094F009 /* AppState.swift */; }; 366FA4E624C6EBF40094F009 /* EnterTanState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 366FA4E524C6EBF40094F009 /* EnterTanState.swift */; }; 36BCF85424BA0C54005BEC29 /* BankList.json in Resources */ = {isa = PBXBuildFile; fileRef = 36BCF85324BA0C54005BEC29 /* BankList.json */; }; 36BCF85824BA4274005BEC29 /* BankingUiCommon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36BCF85524BA41EE005BEC29 /* BankingUiCommon.framework */; }; @@ -44,6 +43,8 @@ 36BE065924CA3CAB00CBBB68 /* UIKitSearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BE065824CA3CAB00CBBB68 /* UIKitSearchBar.swift */; }; 36BE065B24CA4B3500CBBB68 /* SelectBankDialog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BE065A24CA4B3500CBBB68 /* SelectBankDialog.swift */; }; 36BE065D24CB08FC00CBBB68 /* LazyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BE065C24CB08FB00CBBB68 /* LazyView.swift */; }; + 36BE066524CDE62800CBBB68 /* AccountTransactionListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BE066424CDE62800CBBB68 /* AccountTransactionListItem.swift */; }; + 36BE068924CE288800CBBB68 /* CollapsibleText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BE068824CE288800CBBB68 /* CollapsibleText.swift */; }; 36E7BA1424B3D05C00757859 /* ViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36E7BA1324B3D05C00757859 /* ViewExtensions.swift */; }; 36FC929C24B39A05002B12E9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36FC929B24B39A05002B12E9 /* AppDelegate.swift */; }; 36FC929E24B39A05002B12E9 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36FC929D24B39A05002B12E9 /* SceneDelegate.swift */; }; @@ -104,7 +105,6 @@ 366FA4DB24C479120094F009 /* BankInfoListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankInfoListItem.swift; sourceTree = ""; }; 366FA4DF24C4924A0094F009 /* RemitteeListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemitteeListItem.swift; sourceTree = ""; }; 366FA4E124C4ED6C0094F009 /* EnterTanDialog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnterTanDialog.swift; sourceTree = ""; }; - 366FA4E324C4F2C70094F009 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = ""; }; 366FA4E524C6EBF40094F009 /* EnterTanState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnterTanState.swift; sourceTree = ""; }; 36BCF85324BA0C54005BEC29 /* BankList.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = BankList.json; path = ../../../tools/BankFinder/src/commonMain/resources/BankList.json; sourceTree = ""; }; 36BCF85524BA41EE005BEC29 /* BankingUiCommon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = BankingUiCommon.framework; path = "../BankingUiCommon/build/xcode-frameworks/BankingUiCommon.framework"; sourceTree = ""; }; @@ -131,6 +131,8 @@ 36BE065824CA3CAB00CBBB68 /* UIKitSearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitSearchBar.swift; sourceTree = ""; }; 36BE065A24CA4B3500CBBB68 /* SelectBankDialog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectBankDialog.swift; sourceTree = ""; }; 36BE065C24CB08FB00CBBB68 /* LazyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazyView.swift; sourceTree = ""; }; + 36BE066424CDE62800CBBB68 /* AccountTransactionListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountTransactionListItem.swift; sourceTree = ""; }; + 36BE068824CE288800CBBB68 /* CollapsibleText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollapsibleText.swift; sourceTree = ""; }; 36E7BA1324B3D05C00757859 /* ViewExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewExtensions.swift; sourceTree = ""; }; 36E7BA1824B9E70C00757859 /* xcode-frameworks */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "xcode-frameworks"; path = "../../tools/BankFinder/build/xcode-frameworks"; sourceTree = ""; }; 36FC929824B39A05002B12E9 /* BankingiOSApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BankingiOSApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -193,7 +195,6 @@ 36BCF89024C25971005BEC29 /* CoreDataBankingPersistence.swift */, 36BCF89224C25BC3005BEC29 /* Mapper.swift */, 36BCF89424C31F02005BEC29 /* AppData.swift */, - 366FA4E324C4F2C70094F009 /* AppState.swift */, 366FA4D924C472A90094F009 /* Extensions.swift */, 366FA4E524C6EBF40094F009 /* EnterTanState.swift */, ); @@ -302,6 +303,7 @@ 36BCF88824C0A7D7005BEC29 /* Message.swift */, 36BCF88E24C1DFF7005BEC29 /* SheetPresenter.swift */, 366FA4D724C46B160094F009 /* AutoCompleteList.swift */, + 36BE068824CE288800CBBB68 /* CollapsibleText.swift */, ); path = ui; sourceTree = ""; @@ -314,6 +316,7 @@ 36BCF88224C098BB005BEC29 /* BankListItem.swift */, 36BCF88424C098C8005BEC29 /* BankAccountListItem.swift */, 36BCF88A24C0BD2D005BEC29 /* AccountTransactionsDialog.swift */, + 36BE066424CDE62800CBBB68 /* AccountTransactionListItem.swift */, 36BCF88C24C1C1EA005BEC29 /* TransferMoneyDialog.swift */, 366FA4DB24C479120094F009 /* BankInfoListItem.swift */, 366FA4DF24C4924A0094F009 /* RemitteeListItem.swift */, @@ -494,6 +497,7 @@ 36FC92D724B3A3BA002B12E9 /* NSUrlWebClient.swift in Sources */, 36BCF89524C31F02005BEC29 /* AppData.swift in Sources */, 36BE065B24CA4B3500CBBB68 /* SelectBankDialog.swift in Sources */, + 36BE068924CE288800CBBB68 /* CollapsibleText.swift in Sources */, 36BCF88324C098BB005BEC29 /* BankListItem.swift in Sources */, 36BCF88D24C1C1EA005BEC29 /* TransferMoneyDialog.swift in Sources */, 36E7BA1424B3D05C00757859 /* ViewExtensions.swift in Sources */, @@ -513,10 +517,10 @@ 366FA4DA24C472A90094F009 /* Extensions.swift in Sources */, 366FA4D824C46B160094F009 /* AutoCompleteList.swift in Sources */, 366FA4DC24C479120094F009 /* BankInfoListItem.swift in Sources */, - 366FA4E424C4F2C70094F009 /* AppState.swift in Sources */, 36FC929E24B39A05002B12E9 /* SceneDelegate.swift in Sources */, 36BCF88524C098C8005BEC29 /* BankAccountListItem.swift in Sources */, 36FC92EF24B3BB81002B12E9 /* AddAccountDialog.swift in Sources */, + 36BE066524CDE62800CBBB68 /* AccountTransactionListItem.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift index 3dc615c4..6e623c92 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift @@ -4,21 +4,56 @@ import BankingUiSwift struct AccountTransactionsDialog: View { - var title: String + private var title: String - var transactions: [AccountTransaction] + private var allTransactions: [AccountTransaction] + + + @State private var filteredTransactions: [AccountTransaction] + + @State private var searchText = "" + + private var searchTextBinding: Binding { + Binding( + get: { self.searchText }, + set: { + self.searchText = $0 + self.filterTransactions($0) + }) + } @Inject private var presenter: BankingPresenterSwift + init(title: String, transactions: [AccountTransaction]) { + self.title = title + + self.allTransactions = transactions + self._filteredTransactions = State(initialValue: transactions) + } + + var body: some View { - List(transactions.sorted(by: { $0.valueDate.date > $1.valueDate.date } ), id: \.technicalId) { transaction in - AccountTransactionListItem(transaction) + Form { + Section { + UIKitSearchBar(text: searchTextBinding) + } + + Section { + List(filteredTransactions.sorted(by: { $0.valueDate.date > $1.valueDate.date } ), id: \.technicalId) { transaction in + AccountTransactionListItem(transaction) + } + } } .showNavigationBarTitle(LocalizedStringKey(title)) .navigationBarHidden(false) } + + + private func filterTransactions(_ query: String) { + self.filteredTransactions = presenter.searchAccountTransactions(query: query, transactions: allTransactions) + } }