New filters

This commit is contained in:
Selim Mustafaev 2020-09-26 22:34:14 +03:00
parent 65629cbf90
commit 7e0608b52e
6 changed files with 130 additions and 16 deletions

View File

@ -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 = "<group>"; };
7ADF6C9E251201D200F237B2 /* GlobalEventsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlobalEventsController.swift; sourceTree = "<group>"; };
7ADF6CA02512244400F237B2 /* MapExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapExt.swift; sourceTree = "<group>"; };
7AE24C5E251F1B4E00758E39 /* Buttons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Buttons.swift; sourceTree = "<group>"; };
7AE26A3224EEF9EC00625033 /* UIViewControllerExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewControllerExt.swift; sourceTree = "<group>"; };
7AE26A3424F31B0700625033 /* EventsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventsController.swift; sourceTree = "<group>"; };
7AEFE727240455E200910EB7 /* SettingsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsController.swift; sourceTree = "<group>"; };
@ -354,6 +356,7 @@
7A21112924FC3D7E003BBF6F /* AudioEngine.swift */,
7ADF6C92250B954900F237B2 /* Navigation.swift */,
7ADF6CA02512244400F237B2 /* MapExt.swift */,
7AE24C5E251F1B4E00758E39 /* Buttons.swift */,
);
path = Extensions;
sourceTree = "<group>";
@ -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;

View File

@ -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">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>

View File

@ -7,28 +7,28 @@
<key>AutoCat.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
<key>Eureka (Playground) 1.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>9</integer>
<integer>5</integer>
</dict>
<key>Eureka (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>10</integer>
<integer>6</integer>
</dict>
<key>Eureka (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>2</integer>
<integer>4</integer>
</dict>
<key>GettingStarted (Playground) 1.xcscheme</key>
<dict>
@ -70,42 +70,42 @@
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>5</integer>
<integer>10</integer>
</dict>
<key>Rx (Playground) 1.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>3</integer>
<integer>0</integer>
</dict>
<key>Rx (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>4</integer>
<integer>3</integer>
</dict>
<key>Rx (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>1</integer>
<integer>2</integer>
</dict>
<key>SwiftDate (Playground) 1.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>7</integer>
<integer>8</integer>
</dict>
<key>SwiftDate (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>8</integer>
<integer>9</integer>
</dict>
<key>SwiftDate (Playground) 3.xcscheme</key>
<dict>
@ -133,7 +133,7 @@
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>6</integer>
<integer>7</integer>
</dict>
</dict>
</dict>

View File

@ -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<String>("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<SelectorRow<PushSelectorCell<String>>>) {
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()
}
}

View File

@ -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?()
}
}

View File

@ -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
}