diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index 60979b9..10e53cf 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -99,6 +99,7 @@ 7ADF6C9D250FA96000F237B2 /* SwiftMaskTextfield.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7ADF6C9C250FA96000F237B2 /* SwiftMaskTextfield.swift */; }; 7ADF6C9F251201D200F237B2 /* GlobalEventsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7ADF6C9E251201D200F237B2 /* GlobalEventsController.swift */; }; 7ADF6CA12512244400F237B2 /* MapExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7ADF6CA02512244400F237B2 /* MapExt.swift */; }; + 7AE24C5F251F1B4E00758E39 /* Buttons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE24C5E251F1B4E00758E39 /* Buttons.swift */; }; 7AE26A3324EEF9EC00625033 /* UIViewControllerExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE26A3224EEF9EC00625033 /* UIViewControllerExt.swift */; }; 7AE26A3524F31B0700625033 /* EventsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE26A3424F31B0700625033 /* EventsController.swift */; }; 7AEFE728240455E200910EB7 /* SettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AEFE727240455E200910EB7 /* SettingsController.swift */; }; @@ -194,6 +195,7 @@ 7ADF6C9C250FA96000F237B2 /* SwiftMaskTextfield.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftMaskTextfield.swift; sourceTree = ""; }; 7ADF6C9E251201D200F237B2 /* GlobalEventsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlobalEventsController.swift; sourceTree = ""; }; 7ADF6CA02512244400F237B2 /* MapExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapExt.swift; sourceTree = ""; }; + 7AE24C5E251F1B4E00758E39 /* Buttons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Buttons.swift; sourceTree = ""; }; 7AE26A3224EEF9EC00625033 /* UIViewControllerExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewControllerExt.swift; sourceTree = ""; }; 7AE26A3424F31B0700625033 /* EventsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventsController.swift; sourceTree = ""; }; 7AEFE727240455E200910EB7 /* SettingsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsController.swift; sourceTree = ""; }; @@ -354,6 +356,7 @@ 7A21112924FC3D7E003BBF6F /* AudioEngine.swift */, 7ADF6C92250B954900F237B2 /* Navigation.swift */, 7ADF6CA02512244400F237B2 /* MapExt.swift */, + 7AE24C5E251F1B4E00758E39 /* Buttons.swift */, ); path = Extensions; sourceTree = ""; @@ -582,6 +585,7 @@ 7A11471823FDEBFA00B424AF /* ReportController.swift in Sources */, 7A64AE7E2469E16100ABE48E /* RadialGradientLayer.swift in Sources */, 7A64AE7F2469E16100ABE48E /* IndefiniteAnimatedView.swift in Sources */, + 7AE24C5F251F1B4E00758E39 /* Buttons.swift in Sources */, 7A11471A23FE839000B424AF /* AuthController.swift in Sources */, 7A530B7A24001D3300CBFE6E /* CheckController.swift in Sources */, 7A6E03282485951700DB22ED /* OwnersController.swift in Sources */, @@ -767,7 +771,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 38; + CURRENT_PROJECT_VERSION = 39; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; @@ -789,7 +793,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 38; + CURRENT_PROJECT_VERSION = 39; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; diff --git a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 7615455..4628ac5 100644 --- a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -73,10 +73,10 @@ filePath = "AutoCat/Utils/Api.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "232" - endingLineNumber = "232" + startingLineNumber = "237" + endingLineNumber = "237" landmarkName = "add(event:to:)" - landmarkType = "9"> + landmarkType = "7"> diff --git a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist index 74a5455..88fbda5 100644 --- a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,28 +7,28 @@ AutoCat.xcscheme_^#shared#^_ orderHint - 0 + 1 Eureka (Playground) 1.xcscheme isShown orderHint - 9 + 5 Eureka (Playground) 2.xcscheme isShown orderHint - 10 + 6 Eureka (Playground).xcscheme isShown orderHint - 2 + 4 GettingStarted (Playground) 1.xcscheme @@ -70,42 +70,42 @@ isShown orderHint - 5 + 10 Rx (Playground) 1.xcscheme isShown orderHint - 3 + 0 Rx (Playground) 2.xcscheme isShown orderHint - 4 + 3 Rx (Playground).xcscheme isShown orderHint - 1 + 2 SwiftDate (Playground) 1.xcscheme isShown orderHint - 7 + 8 SwiftDate (Playground) 2.xcscheme isShown orderHint - 8 + 9 SwiftDate (Playground) 3.xcscheme @@ -133,7 +133,7 @@ isShown orderHint - 6 + 7 diff --git a/AutoCat/Controllers/FiltersController.swift b/AutoCat/Controllers/FiltersController.swift index 84b1287..898b5ce 100644 --- a/AutoCat/Controllers/FiltersController.swift +++ b/AutoCat/Controllers/FiltersController.swift @@ -2,6 +2,20 @@ import UIKit import Eureka import RxSwift +enum AddedBy: String, CustomStringConvertible, CaseIterable { + case anyone + case me + case anyoneButMe + + var description: String { + switch self { + case .anyone: return "Anyone" + case .me: return "Me" + case .anyoneButMe: return "Anyone but me" + } + } +} + class FiltersController: FormViewController { var done = false @@ -83,6 +97,40 @@ class FiltersController: FormViewController { self.navigationController?.pushViewController(vc, animated: true) } + form +++ Section() { $0.tag = "AddedByMe" } + <<< ActionSheetRow("AddedByMeRow") { row in + row.title = "Added by" + row.selectorTitle = "Added by" + row.options = AddedBy.allCases.map { $0.description } + row.value = self.filter.addedBy?.description ?? AddedBy.anyone.description + } + .onChange { row in + if let index = row.options?.firstIndex(of: row.value ?? "") { + self.filter.addedBy = AddedBy.allCases[index] + } else { + self.filter.addedBy = .anyone + } + } + .cellUpdate { cell, row in + row.value = self.filter.addedBy?.description ?? AddedBy.anyone.description + } + + form +++ Section("Time range") + <<< DateInlineRow("FromDate") { row in + row.title = "From" + row.noValueDisplayText = "Beginning" + row.value = self.filter.fromDate + } + .onChange { self.filter.fromDate = $0.value } + .cellUpdate(self.update(cell:row:)) + <<< DateInlineRow("ToDate") { row in + row.title = "To" + row.noValueDisplayText = "Now" + row.value = self.filter.toDate + } + .onChange { self.filter.toDate = $0.value } + .cellUpdate(self.update(cell:row:)) + form +++ Section() <<< ButtonRow("ClearAll") { $0.title = "Clear all filters" }.onCellSelection { cell, row in self.filter.clear() @@ -114,4 +162,33 @@ class FiltersController: FormViewController { func removeSectionName(from: FormViewController, to: SelectorViewController>>) { to.sectionKeyForValue = { _ in "" } } + + func update(cell: DateInlineRow.Cell, row: DateInlineRow) { + let date = row.tag == "FromDate" ? self.filter.fromDate : self.filter.toDate + if date != nil { + let button = UIButton(type: .close) + button.accessibilityLabel = row.tag + button.addTarget(self, action: #selector(self.clearDate(_:)), for: .touchUpInside) + button.sizeToFit() + cell.accessoryView = button + } else { + cell.accessoryView = nil + } + row.value = date + } + + @objc func clearDate(_ sender: UIButton) { + guard let tag = sender.accessibilityLabel else { return } + guard let row = self.form.rowBy(tag: tag) as? DateInlineRow else { return } + + if tag == "FromDate" { + self.filter.fromDate = nil + } else { + self.filter.toDate = nil + } + + row.value = nil + row.baseCell.accessoryView = nil + row.baseCell.update() + } } diff --git a/AutoCat/Extensions/Buttons.swift b/AutoCat/Extensions/Buttons.swift new file mode 100644 index 0000000..a14adc2 --- /dev/null +++ b/AutoCat/Extensions/Buttons.swift @@ -0,0 +1,18 @@ +import UIKit + +class ActionButton: UIButton { + var actionHandler: (() -> Void)? { + didSet { + self.removeTarget(self, action: #selector(self.actionImpl), for: .touchUpInside) + self.addTarget(self, action: #selector(self.actionImpl), for: .touchUpInside) + } + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + @objc private func actionImpl() -> Void { + self.actionHandler?() + } +} diff --git a/AutoCat/Models/Filter.swift b/AutoCat/Models/Filter.swift index 2fefe84..d0cc933 100644 --- a/AutoCat/Models/Filter.swift +++ b/AutoCat/Models/Filter.swift @@ -6,12 +6,18 @@ struct Filter { var model: String? var color: String? var regions: [Int]? + var addedBy: AddedBy? + var fromDate: Date? + var toDate: Date? mutating func clear() { self.brand = nil self.model = nil self.color = nil self.regions = nil + self.addedBy = nil + self.fromDate = nil + self.toDate = nil } func queryDictionary() -> [String: String] { @@ -29,6 +35,15 @@ struct Filter { if let regions = self.regions { dict["regions"] = regions.map(String.init).joined(separator: ",") } + if let addedBy = self.addedBy { + dict["addedBy"] = addedBy.rawValue + } + if let fromDate = self.fromDate { + dict["fromDate"] = String(fromDate.timeIntervalSince1970) + } + if let toDate = self.toDate { + dict["toDate"] = String(toDate.timeIntervalSince1970) + } return dict }