diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index 45ae04e..85cb185 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -97,7 +97,7 @@ 7AA7BC3825A5DFB80053A5D5 /* Eureka in Frameworks */ = {isa = PBXBuildFile; productRef = 7AEF47A3253DC4D2001D6238 /* Eureka */; }; 7AABDE26253350C30041AFC6 /* RxSectionedDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AABDE25253350C30041AFC6 /* RxSectionedDataSource.swift */; }; 7AAE6AD324CDDF950023860B /* VehicleEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AAE6AD224CDDF950023860B /* VehicleEvent.swift */; }; - 7AB562BA249C9E9B00473D53 /* Region.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB562B9249C9E9B00473D53 /* Region.swift */; }; + 7AB562BA249C9E9B00473D53 /* VehicleRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB562B9249C9E9B00473D53 /* VehicleRegion.swift */; }; 7AB67E8C2435C38700258F61 /* CustomTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB67E8B2435C38700258F61 /* CustomTextField.swift */; }; 7AB67E8E2435D1A000258F61 /* CustomButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB67E8D2435D1A000258F61 /* CustomButton.swift */; }; 7ADF6C93250B954900F237B2 /* Navigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7ADF6C92250B954900F237B2 /* Navigation.swift */; }; @@ -205,7 +205,7 @@ 7A9FEEC72529AB23001CA50E /* RxRealmDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RxRealmDataSource.swift; sourceTree = ""; }; 7AABDE25253350C30041AFC6 /* RxSectionedDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RxSectionedDataSource.swift; sourceTree = ""; }; 7AAE6AD224CDDF950023860B /* VehicleEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehicleEvent.swift; sourceTree = ""; }; - 7AB562B9249C9E9B00473D53 /* Region.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Region.swift; sourceTree = ""; }; + 7AB562B9249C9E9B00473D53 /* VehicleRegion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehicleRegion.swift; sourceTree = ""; }; 7AB67E8B2435C38700258F61 /* CustomTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTextField.swift; sourceTree = ""; }; 7AB67E8D2435D1A000258F61 /* CustomButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomButton.swift; sourceTree = ""; }; 7ADF6C92250B954900F237B2 /* Navigation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Navigation.swift; sourceTree = ""; }; @@ -380,7 +380,7 @@ 7A0516192414FF0900FC55AC /* DateSection.swift */, 7A6DD90D24337930009DE740 /* PlateNumber.swift */, 7A333813249A532400D878F1 /* Filter.swift */, - 7AB562B9249C9E9B00473D53 /* Region.swift */, + 7AB562B9249C9E9B00473D53 /* VehicleRegion.swift */, 7A659B5824A2B1BA0043A0F2 /* AudioRecord.swift */, 7AAE6AD224CDDF950023860B /* VehicleEvent.swift */, 7A0420A925619AEC00034941 /* Osago.swift */, @@ -601,7 +601,7 @@ 7A813DC32508EE4F00CC93B9 /* EventCell.swift in Sources */, 7A3F07AD2436350B00E59687 /* SearchController.swift in Sources */, 7AABDE26253350C30041AFC6 /* RxSectionedDataSource.swift in Sources */, - 7AB562BA249C9E9B00473D53 /* Region.swift in Sources */, + 7AB562BA249C9E9B00473D53 /* VehicleRegion.swift in Sources */, 7A0B96A0257D6D4B000B39AD /* MultilineLabelRow.swift in Sources */, 7A659B5924A2B1BA0043A0F2 /* AudioRecord.swift in Sources */, 7A6DD90C24335A6D009DE740 /* FlagLayer.swift in Sources */, @@ -847,7 +847,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 68; + CURRENT_PROJECT_VERSION = 69; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; @@ -871,7 +871,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 68; + CURRENT_PROJECT_VERSION = 69; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; diff --git a/AutoCat.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/AutoCat.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 4a8dc44..099e37a 100644 --- a/AutoCat.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/AutoCat.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -33,8 +33,8 @@ "repositoryURL": "https://github.com/onevcat/Kingfisher", "state": { "branch": null, - "revision": "2a6d1135af3915547c4b08c3b154a05e6f1075a3", - "version": "5.15.5" + "revision": "2a10bf41da75599a9f8e872dbd44fe0155a2e00c", + "version": "5.15.8" } }, { @@ -51,8 +51,8 @@ "repositoryURL": "https://github.com/realm/realm-cocoa", "state": { "branch": null, - "revision": "2dc2d259095051b997b76a07e859822661105303", - "version": "5.4.7" + "revision": "7ec5df0a700ef76ad930dcedb9c63c1b354979e1", + "version": "5.5.1" } }, { @@ -60,8 +60,8 @@ "repositoryURL": "https://github.com/realm/realm-core", "state": { "branch": null, - "revision": "2df510904ad04287926b287b4e89b786de2808c8", - "version": "6.1.3" + "revision": "66d79b3c5213fb14d491c1b22193077b488d49a6", + "version": "6.2.4" } }, { @@ -78,8 +78,8 @@ "repositoryURL": "https://github.com/ReactiveX/RxSwift.git", "state": { "branch": null, - "revision": "002d325b0bdee94e7882e1114af5ff4fe1e96afa", - "version": "5.1.1" + "revision": "254617dd7fae0c45319ba5fbea435bf4d0e15b5d", + "version": "5.1.2" } }, { @@ -87,8 +87,8 @@ "repositoryURL": "https://github.com/malcommac/SwiftDate.git", "state": { "branch": null, - "revision": "a25913b19833860b61fac161a706e44834f03c47", - "version": "6.2.0" + "revision": "6190d0cefff3013e77ed567e6b074f324e5c5bf5", + "version": "6.3.1" } } ] diff --git a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 618c809..f74ca62 100644 --- a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -63,5 +63,149 @@ landmarkType = "7"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist index 1351ee9..00da5da 100644 --- a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist @@ -12,170 +12,191 @@ DifferenceKit (Playground) 1.xcscheme isShown - + orderHint - 6 + 5 DifferenceKit (Playground) 2.xcscheme isShown - + orderHint - 7 + 6 DifferenceKit (Playground).xcscheme isShown - + orderHint - 3 + 4 Eureka (Playground) 1.xcscheme isShown - + orderHint - 2 + 8 Eureka (Playground) 2.xcscheme isShown - + orderHint - 4 + 9 Eureka (Playground) 3.xcscheme isShown - + orderHint 19 Eureka (Playground) 4.xcscheme isShown - + orderHint 21 Eureka (Playground) 5.xcscheme isShown - + orderHint 23 Eureka (Playground).xcscheme isShown - + orderHint - 1 + 7 GettingStarted (Playground) 1.xcscheme isShown - + orderHint - 15 + 14 GettingStarted (Playground) 2.xcscheme isShown - + orderHint - 17 + 15 GettingStarted (Playground) 3.xcscheme isShown - + orderHint 13 GettingStarted (Playground) 4.xcscheme isShown - + orderHint 16 GettingStarted (Playground) 5.xcscheme isShown - + orderHint 18 GettingStarted (Playground).xcscheme isShown - + orderHint - 12 + 13 Rx (Playground) 1.xcscheme isShown - + orderHint - 8 + 2 Rx (Playground) 2.xcscheme isShown - + orderHint - 9 + 3 + + Rx (Playground) 3.xcscheme + + isShown + + orderHint + 16 + + Rx (Playground) 4.xcscheme + + isShown + + orderHint + 17 + + Rx (Playground) 5.xcscheme + + isShown + + orderHint + 18 Rx (Playground).xcscheme isShown - + orderHint - 5 + 1 SwiftDate (Playground) 1.xcscheme isShown - + orderHint - 11 + 12 SwiftDate (Playground) 2.xcscheme isShown - + orderHint - 14 + 10 SwiftDate (Playground) 3.xcscheme isShown - + orderHint 20 SwiftDate (Playground) 4.xcscheme isShown - + orderHint 22 SwiftDate (Playground) 5.xcscheme isShown - + orderHint 24 SwiftDate (Playground).xcscheme isShown - + orderHint - 10 + 11 SuppressBuildableAutocreation @@ -183,7 +204,7 @@ 7A1146FC23FDE7E500B424AF primary - + diff --git a/AutoCat/Controllers/FiltersController.swift b/AutoCat/Controllers/FiltersController.swift index 0632296..5ed0600 100644 --- a/AutoCat/Controllers/FiltersController.swift +++ b/AutoCat/Controllers/FiltersController.swift @@ -16,12 +16,36 @@ enum AddedBy: String, CustomStringConvertible, CaseIterable { } } +enum SortParameter: String, CustomStringConvertible, CaseIterable { + case addedDate + case updatedDate + + var description: String { + switch self { + case .addedDate: return NSLocalizedString("added time", comment: "sort by added time") + case .updatedDate: return NSLocalizedString("updated time", comment: "sort by updated time") + } + } +} + +enum SortOrder: String, CustomStringConvertible, CaseIterable { + case ascending + case descending + + var description: String { + switch self { + case .ascending: return NSLocalizedString("ascending", comment: "sort order") + case .descending: return NSLocalizedString("descending", comment: "sort order") + } + } +} + class FiltersController: FormViewController { var done = false var filter: Filter! var onDone: (() -> Void)? - var regions: [Region] = [] + var regions: [VehicleRegion] = [] let bag = DisposeBag() @@ -77,6 +101,20 @@ class FiltersController: FormViewController { .onChange { self.filter.color = $0.value == "Any" ? nil : $0.value } .cellUpdate { $1.value = self.filter.color ?? "Any" } + <<< PushRow("Year") { row in + row.title = NSLocalizedString("Year", comment: "Manufacturing year") + row.value = self.filter.year ?? "Any" + row.optionsProvider = .lazy({ form, completion in + Api.getYears().observeOn(MainScheduler.instance).subscribe { years in + completion(["Any"] + years.map(String.init)) + } onError: { error in + print("Get years error: \(error)") + }.disposed(by: self.bag) + }) + } + .onChange { self.filter.year = $0.value == "Any" ? nil : $0.value } + .cellUpdate { $1.value = self.filter.year ?? "Any" } + form +++ Section() { $0.tag = "Regions" } <<< LabelRow("RegionsRow") { row in row.title = NSLocalizedString("Regions", comment: "") @@ -115,7 +153,23 @@ class FiltersController: FormViewController { row.value = self.filter.addedBy?.description ?? AddedBy.anyone.description } - form +++ Section(NSLocalizedString("Time range", comment: "")) + form +++ Section(NSLocalizedString("Update time", comment: "")) + <<< DateInlineRow("FromDateUpdated") { row in + row.title = NSLocalizedString("From", comment: "") + row.noValueDisplayText = NSLocalizedString("Beginning", comment: "") + row.value = self.filter.fromDateUpdated + } + .onChange { self.filter.fromDateUpdated = $0.value } + .cellUpdate(self.update(cell:row:)) + <<< DateInlineRow("ToDateUpdated") { row in + row.title = NSLocalizedString("To", comment: "") + row.noValueDisplayText = NSLocalizedString("Now", comment: "") + row.value = self.filter.toDateUpdated + } + .onChange { self.filter.toDateUpdated = $0.value } + .cellUpdate(self.update(cell:row:)) + + form +++ Section(NSLocalizedString("Added time", comment: "")) <<< DateInlineRow("FromDate") { row in row.title = NSLocalizedString("From", comment: "") row.noValueDisplayText = NSLocalizedString("Beginning", comment: "") @@ -131,6 +185,22 @@ class FiltersController: FormViewController { .onChange { self.filter.toDate = $0.value } .cellUpdate(self.update(cell:row:)) + form +++ Section(NSLocalizedString("Sort", comment: "Header section. Noun.")) + <<< PickerInlineRow("SortBy") { row in + row.title = NSLocalizedString("Sort by", comment: "") + row.value = self.filter.sortBy + row.options = SortParameter.allCases + } + .onChange { self.filter.sortBy = $0.value } + .cellUpdate { $1.value = self.filter.sortBy } + <<< SegmentedRow("SortOrder") { row in + row.title = NSLocalizedString("Order", comment: "sort order") + row.value = self.filter.sortOrder + row.options = SortOrder.allCases + } + .onChange { self.filter.sortOrder = $0.value } + .cellUpdate { $1.value = self.filter.sortOrder } + form +++ Section() <<< ButtonRow("ClearAll") { $0.title = NSLocalizedString("Clear all filters", comment: "") }.onCellSelection { cell, row in self.filter.clear() @@ -164,7 +234,9 @@ class FiltersController: FormViewController { } func update(cell: DateInlineRow.Cell, row: DateInlineRow) { - let date = row.tag == "FromDate" ? self.filter.fromDate : self.filter.toDate + guard let tag = row.tag else { return } + + let date = self.date(from: tag) if date != nil { let button = UIButton(type: .close) button.accessibilityLabel = row.tag @@ -177,6 +249,16 @@ class FiltersController: FormViewController { row.value = date } + func date(from tag: String) -> Date? { + switch tag { + case "FromDate": return self.filter.fromDate + case "ToDate": return self.filter.toDate + case "FromDateUpdated": return self.filter.fromDateUpdated + case "ToDateUpdated": return self.filter.toDateUpdated + default: return nil + } + } + @objc func clearDate(_ sender: UIButton) { guard let tag = sender.accessibilityLabel else { return } guard let row = self.form.rowBy(tag: tag) as? DateInlineRow else { return } diff --git a/AutoCat/Controllers/RegionsController.swift b/AutoCat/Controllers/RegionsController.swift index 32db8de..28386cc 100644 --- a/AutoCat/Controllers/RegionsController.swift +++ b/AutoCat/Controllers/RegionsController.swift @@ -1,7 +1,7 @@ import UIKit import RxSwift -class RegionsDataSourse: UITableViewDiffableDataSource { +class RegionsDataSourse: UITableViewDiffableDataSource { override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return snapshot().sectionIdentifiers[section].name } @@ -11,8 +11,8 @@ class RegionsController: UIViewController, UISearchResultsUpdating, UITableViewD @IBOutlet weak var tableView: UITableView! - var regions: [Region] = [] - var regionsFiltered: [Region] = [] + var regions: [VehicleRegion] = [] + var regionsFiltered: [VehicleRegion] = [] var done = false var onDone: (([Int]?) -> Void)? var regionCodes: [Int] = [] @@ -69,7 +69,7 @@ class RegionsController: UIViewController, UISearchResultsUpdating, UITableViewD } func updateTableView() { - var snapshot = NSDiffableDataSourceSnapshot() + var snapshot = NSDiffableDataSourceSnapshot() snapshot.appendSections(self.regionsFiltered) for region in self.regionsFiltered { snapshot.appendItems(region.codes, toSection: region) diff --git a/AutoCat/Controllers/SearchController.swift b/AutoCat/Controllers/SearchController.swift index c53aa91..d42cc56 100644 --- a/AutoCat/Controllers/SearchController.swift +++ b/AutoCat/Controllers/SearchController.swift @@ -101,6 +101,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe controller.filter = self.filter controller.onDone = { self.filter = controller.filter + self.datasource.setSortParameter(self.filter.sortBy ?? .updatedDate) self.datasource.reset() self.filterRelay.accept(self.filter) } diff --git a/AutoCat/Extensions/Dated.swift b/AutoCat/Extensions/Dated.swift index 0658d0c..56f7d75 100644 --- a/AutoCat/Extensions/Dated.swift +++ b/AutoCat/Extensions/Dated.swift @@ -3,45 +3,60 @@ import SwiftDate import DifferenceKit protocol Dated { - var date: Date { get } + var added: Date { get } + var updated: Date { get } } extension Vehicle: Dated { - var date: Date { - return Date(timeIntervalSince1970: self.updatedDate) + var updated: Date { + Date(timeIntervalSince1970: self.updatedDate) + } + + var added: Date { + Date(timeIntervalSince1970: self.addedDate) } } extension AudioRecord: Dated { - var date: Date { + var updated: Date { + Date(timeIntervalSince1970: self.getAddedDate()) + } + + var added: Date { Date(timeIntervalSince1970: self.getAddedDate()) } } extension RandomAccessCollection where Element: Dated & Hashable & Differentiable { - func groupedByDate() -> [DateSection] { + func groupedByDate(type: SortParameter = .updatedDate) -> [DateSection] { let now = Date() let monthStart = now.dateAtStartOf(.month) - var sections: [TimeInterval: [Element]] = [:] + var sectionsIndices: [TimeInterval: Int] = [:] + var sectionsArray: [DateSection] = [] for vehicle in self { - let date = vehicle.date - var key = date.dateAtStartOf(.day).timeIntervalSince1970 + let date = self.date(of: type, for: vehicle) + let dateInRegion = DateInRegion(date, region: Region.current) + + var key = dateInRegion.dateAtStartOf(.day).timeIntervalSince1970 if date.isBeforeDate(monthStart, orEqual: false, granularity: .day) { - key = date.dateAtStartOf(.month).timeIntervalSince1970 + key = dateInRegion.dateAtStartOf(.month).timeIntervalSince1970 } - if sections[key] == nil { - sections[key] = [vehicle] + if let index = sectionsIndices[key] { + sectionsArray[index].append(vehicle) } else { - sections[key]?.append(vehicle) + sectionsArray.append(DateSection(timestamp: key, items: [vehicle])) + sectionsIndices[key] = sectionsArray.count - 1 } } - var sectionsArray: [DateSection] = [] - for (timestamp, vehicles) in sections { - sectionsArray.append(DateSection(timestamp: timestamp, items: vehicles)) + return sectionsArray + } + + func date(of type: SortParameter, for object: Dated) -> Date { + switch type { + case .addedDate: return object.added + case .updatedDate: return object.updated } - - return sectionsArray.sorted { $0.timestamp > $1.timestamp } } } diff --git a/AutoCat/Models/DateSection.swift b/AutoCat/Models/DateSection.swift index 792f60b..8432e69 100644 --- a/AutoCat/Models/DateSection.swift +++ b/AutoCat/Models/DateSection.swift @@ -42,7 +42,7 @@ struct DateSection: Differentiable, DifferentiableSection, Hashable where T: formatter.timeStyle = .none self.header = formatter.string(from: date) } else { - formatter.dateFormat = "MMMM yyyy" + formatter.dateFormat = "LLLL yyyy" self.header = formatter.string(from: date) } @@ -50,6 +50,10 @@ struct DateSection: Differentiable, DifferentiableSection, Hashable where T: self.elements = items } + mutating func append(_ element: T) { + self.elements.append(element) + } + // MARK: - Differentiable var differenceIdentifier: String { @@ -60,7 +64,7 @@ struct DateSection: Differentiable, DifferentiableSection, Hashable where T: return self.differenceIdentifier == source.differenceIdentifier } - // MARK: - Hasable + // MARK: - Hashable static func == (lhs: DateSection, rhs: DateSection) -> Bool { return lhs.timestamp == rhs.timestamp && lhs.elements == rhs.elements diff --git a/AutoCat/Models/Filter.swift b/AutoCat/Models/Filter.swift index d0cc933..63fafd1 100644 --- a/AutoCat/Models/Filter.swift +++ b/AutoCat/Models/Filter.swift @@ -5,19 +5,29 @@ struct Filter { var brand: String? var model: String? var color: String? + var year: String? var regions: [Int]? var addedBy: AddedBy? + var sortBy: SortParameter? = .updatedDate + var sortOrder: SortOrder? = .descending var fromDate: Date? var toDate: Date? + var fromDateUpdated: Date? + var toDateUpdated: Date? mutating func clear() { self.brand = nil self.model = nil self.color = nil + self.year = nil self.regions = nil self.addedBy = nil + self.sortBy = .addedDate + self.sortOrder = .descending self.fromDate = nil self.toDate = nil + self.fromDateUpdated = nil + self.toDateUpdated = nil } func queryDictionary() -> [String: String] { @@ -32,18 +42,33 @@ struct Filter { if let color = self.color { dict["color"] = color } + if let year = self.year { + dict["year"] = year + } if let regions = self.regions { dict["regions"] = regions.map(String.init).joined(separator: ",") } if let addedBy = self.addedBy { dict["addedBy"] = addedBy.rawValue } + if let sortBy = self.sortBy { + dict["sortBy"] = sortBy.rawValue + } + if let sortOrder = self.sortOrder { + dict["sortOrder"] = sortOrder.rawValue + } if let fromDate = self.fromDate { dict["fromDate"] = String(fromDate.timeIntervalSince1970) } if let toDate = self.toDate { dict["toDate"] = String(toDate.timeIntervalSince1970) } + if let fromDateUpdated = self.fromDateUpdated { + dict["fromDateUpdated"] = String(fromDateUpdated.timeIntervalSince1970) + } + if let toDateUpdated = self.toDateUpdated { + dict["toDateUpdated"] = String(toDateUpdated.timeIntervalSince1970) + } return dict } diff --git a/AutoCat/Models/Region.swift b/AutoCat/Models/Region.swift deleted file mode 100644 index 3000ce7..0000000 --- a/AutoCat/Models/Region.swift +++ /dev/null @@ -1,10 +0,0 @@ -import Foundation - -struct Region: Codable, Hashable { - var name: String - var codes: [Int] - - static func == (lhs: Region, rhs: Region) -> Bool { - return lhs.name == rhs.name - } -} diff --git a/AutoCat/Models/VehicleRegion.swift b/AutoCat/Models/VehicleRegion.swift new file mode 100644 index 0000000..a156cbb --- /dev/null +++ b/AutoCat/Models/VehicleRegion.swift @@ -0,0 +1,10 @@ +import Foundation + +struct VehicleRegion: Codable, Hashable { + var name: String + var codes: [Int] + + static func == (lhs: VehicleRegion, rhs: VehicleRegion) -> Bool { + return lhs.name == rhs.name + } +} diff --git a/AutoCat/Utils/Api.swift b/AutoCat/Utils/Api.swift index c6a34f4..12f56e4 100644 --- a/AutoCat/Utils/Api.swift +++ b/AutoCat/Utils/Api.swift @@ -116,7 +116,7 @@ class Api { guard let json = resp as? [String: Any] else { return } if let newToken = json["id_token"] as? String { Settings.shared.user.firebaseIdToken = newToken - print("Token was successfully refresh to: \(newToken)") + //print("Token was successfully refresh to: \(newToken)") } if let newRefreshToken = json["refresh_token"] as? String { Settings.shared.user.firebaseRefreshToken = newRefreshToken @@ -241,10 +241,14 @@ class Api { return self.makeEmptyGetRequest(api: "vehicles/colors") } - public static func getRegions() -> Single<[Region]> { + public static func getRegions() -> Single<[VehicleRegion]> { return self.makeEmptyGetRequest(api: "vehicles/regions") } + public static func getYears() -> Single<[Int]> { + return self.makeEmptyGetRequest(api: "vehicles/years") + } + public static func add(event: VehicleEvent, to number: String) -> Single { let body = ["number": AnyEncodable(number), "event": AnyEncodable(event)] return self.makeBodyRequest(api: "events", body: body).map { (vehicle: Vehicle) -> Vehicle in diff --git a/AutoCat/Utils/RxSectionedDataSource.swift b/AutoCat/Utils/RxSectionedDataSource.swift index af23c5e..dec14a5 100644 --- a/AutoCat/Utils/RxSectionedDataSource.swift +++ b/AutoCat/Utils/RxSectionedDataSource.swift @@ -8,6 +8,7 @@ class RxSectionedDataSource: NSObject, UITableViewDataSource where I private var cellIdentifier: String private var sections: [DateSection] = [] private var items: [Item] = [] + private var sortParam: SortParameter = .updatedDate private(set) var pageToken: String? = nil private(set) var count: Int? = nil @@ -62,7 +63,7 @@ class RxSectionedDataSource: NSObject, UITableViewDataSource where I } self.pageToken = data.pageToken - let newSections = self.items.groupedByDate() + let newSections = self.items.groupedByDate(type: self.sortParam) let changeset = StagedChangeset(source: self.sections, target: newSections) self.tv.reload(using: changeset, with: .automatic) { newSects in self.sections = newSects @@ -80,4 +81,8 @@ class RxSectionedDataSource: NSObject, UITableViewDataSource where I self.count = nil self.items = [] } + + func setSortParameter(_ param: SortParameter) { + self.sortParam = param + } } diff --git a/AutoCat/ru.lproj/Localizable.strings b/AutoCat/ru.lproj/Localizable.strings index e108fc3..3af747e 100644 --- a/AutoCat/ru.lproj/Localizable.strings +++ b/AutoCat/ru.lproj/Localizable.strings @@ -16,6 +16,12 @@ /* No comment provided by engineer. */ "Added by" = "Добавлено"; +/* sort by added time */ +"added time" = "времени добавления"; + +/* No comment provided by engineer. */ +"Added time" = "Время добавления"; + /* No comment provided by engineer. */ "Ads" = "Объявления"; @@ -40,6 +46,9 @@ /* No comment provided by engineer. */ "As text and photos" = "В виде текста и фотографий"; +/* sort order */ +"ascending" = "по возростанию"; + /* No comment provided by engineer. */ "AutoCat Account" = "Аккаунт в АвтоКот"; @@ -112,6 +121,9 @@ /* No comment provided by engineer. */ "Delete" = "Удалить"; +/* sort order */ +"descending" = "по убыванию"; + /* No comment provided by engineer. */ "Description" = "Описание"; @@ -217,6 +229,9 @@ /* No comment provided by engineer. */ "Number" = "Номер"; +/* sort order */ +"Order" = "Порядок"; + /* No comment provided by engineer. */ "OSAGO" = "ОСАГО"; @@ -322,15 +337,18 @@ /* No comment provided by engineer. */ "Sign Out" = "Выйти"; +/* Header section. Noun. */ +"Sort" = "Сортировка"; + +/* No comment provided by engineer. */ +"Sort by" = "Сортировать по"; + /* No comment provided by engineer. */ "Steering wheel position" = "Положение руля"; /* No comment provided by engineer. */ "STS" = "СТС"; -/* No comment provided by engineer. */ -"Time range" = "Временной промежуток"; - /* No comment provided by engineer. */ "To" = "По"; @@ -343,6 +361,12 @@ /* No comment provided by engineer. */ "Update" = "Обновить"; +/* No comment provided by engineer. */ +"Update time" = "Время обновления"; + +/* sort by updated time */ +"updated time" = "времени обновления"; + /* No comment provided by engineer. */ "Vehicle region" = "Регион регистрации ТС";