Additional search scopes - vin and notes
This commit is contained in:
parent
4c2811246d
commit
69fdd322b0
@ -1150,7 +1150,7 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 114;
|
||||
CURRENT_PROJECT_VERSION = 116;
|
||||
DEVELOPMENT_TEAM = 46DTTB8X4S;
|
||||
INFOPLIST_FILE = AutoCat/Info.plist;
|
||||
INFOPLIST_KEY_CFBundleDisplayName = AutoCat;
|
||||
@ -1178,7 +1178,7 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 114;
|
||||
CURRENT_PROJECT_VERSION = 116;
|
||||
DEVELOPMENT_TEAM = 46DTTB8X4S;
|
||||
INFOPLIST_FILE = AutoCat/Info.plist;
|
||||
INFOPLIST_KEY_CFBundleDisplayName = AutoCat;
|
||||
|
||||
@ -15,6 +15,13 @@ extension UISearchController {
|
||||
searchController.obscuresBackgroundDuringPresentation = false
|
||||
searchController.hidesNavigationBarDuringPresentation = false
|
||||
searchController.searchBar.keyboardType = .webSearch
|
||||
|
||||
if #available(iOS 16, *) {
|
||||
searchController.scopeBarActivation = .onTextEntry
|
||||
} else {
|
||||
searchController.automaticallyShowsScopeBar = true
|
||||
}
|
||||
|
||||
return searchController
|
||||
}
|
||||
|
||||
@ -37,4 +44,14 @@ extension UISearchController {
|
||||
searchBar.smartInsertDeleteType = .no
|
||||
return self
|
||||
}
|
||||
|
||||
func scopeButtons(_ buttons: [String]) -> UISearchController {
|
||||
searchBar.scopeButtonTitles = buttons
|
||||
return self
|
||||
}
|
||||
|
||||
func searchBarDelegate(_ delegate: UISearchBarDelegate) -> UISearchController {
|
||||
searchBar.delegate = delegate
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,12 +47,41 @@ class NewNumberController: UIViewController {
|
||||
}()
|
||||
|
||||
private lazy var mainStackView: UIStackView = {
|
||||
let stack = UIStackView(arrangedSubviews: [titleLabel, stackView, keyboardView])
|
||||
let stack = UIStackView(arrangedSubviews: [titleLabel, stackView, settingsStackView, keyboardView])
|
||||
stack.axis = .vertical
|
||||
stack.spacing = 16
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
return stack
|
||||
}()
|
||||
|
||||
private lazy var locationSwitcherView: UISegmentedControl = {
|
||||
let view = UISegmentedControl()
|
||||
view.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.insertSegment(with: UIImage(systemName: "location.fill"), at: 0, animated: false)
|
||||
view.insertSegment(with: UIImage(systemName: "location"), at: 1, animated: false)
|
||||
view.insertSegment(with: UIImage(systemName: "location.slash"), at: 2, animated: false)
|
||||
return view
|
||||
}()
|
||||
|
||||
private lazy var numTypeSwitcherView: UISegmentedControl = {
|
||||
let view = UISegmentedControl()
|
||||
view.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.insertSegment(withTitle: "ГРЗ", at: 0, animated: false)
|
||||
view.insertSegment(withTitle: "VIN", at: 1, animated: false)
|
||||
view.selectedSegmentIndex = 0
|
||||
view.isEnabled = false
|
||||
return view
|
||||
}()
|
||||
|
||||
private lazy var settingsStackView: UIStackView = {
|
||||
let stack = UIStackView(arrangedSubviews: [numTypeSwitcherView, locationSwitcherView])
|
||||
stack.axis = .horizontal
|
||||
stack.spacing = 16
|
||||
stack.distribution = .fillProportionally
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
stack.isHidden = true
|
||||
return stack
|
||||
}()
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
@ -6,7 +6,7 @@ import PKHUD
|
||||
import ExceptionCatcher
|
||||
import AutoCatCore
|
||||
|
||||
class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDelegate, UIScrollViewDelegate {
|
||||
class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDelegate, UIScrollViewDelegate, UISearchBarDelegate {
|
||||
|
||||
@IBOutlet weak var tableView: UITableView!
|
||||
@IBOutlet weak var showMapButton: UIBarButtonItem?
|
||||
@ -20,7 +20,9 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
||||
private lazy var searchController: UISearchController = .default
|
||||
.placeholder(NSLocalizedString("Search plate numbers", comment: ""))
|
||||
.resultsUpdater(self)
|
||||
.searchBarDelegate(self)
|
||||
.makeDumb()
|
||||
.scopeButtons(SearchScope.allCases.map(\.title))
|
||||
|
||||
private var refreshControl = UIRefreshControl()
|
||||
private var datasource: RxSectionedDataSource<Vehicle,VehicleCell>!
|
||||
@ -136,9 +138,20 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
||||
|
||||
self.filter.searchString = newQuery
|
||||
self.filter.needReset = true
|
||||
self.filter.scope = SearchScope(rawValue: searchController.searchBar.selectedScopeButtonIndex) ?? .plateNumber
|
||||
|
||||
self.filterRelay.accept(self.filter)
|
||||
}
|
||||
|
||||
func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) {
|
||||
guard let scope = SearchScope(rawValue: selectedScope) else {
|
||||
return
|
||||
}
|
||||
|
||||
filter.scope = scope
|
||||
filterRelay.accept(filter)
|
||||
}
|
||||
|
||||
// MARK: NavigationBar actions
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
@ -183,6 +196,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
||||
self.filter = controller.filter
|
||||
self.datasource.setSortParameter(self.filter.sortBy ?? .updatedDate)
|
||||
self.filter.needReset = true
|
||||
self.filter.scope = SearchScope(rawValue: self.searchController.searchBar.selectedScopeButtonIndex) ?? .plateNumber
|
||||
self.filterRelay.accept(self.filter)
|
||||
}
|
||||
self.navigationController?.pushViewController(controller, animated: true)
|
||||
|
||||
@ -38,6 +38,29 @@ public enum SortOrder: String, CustomStringConvertible, CaseIterable {
|
||||
}
|
||||
}
|
||||
|
||||
public enum SearchScope: Int, CaseIterable {
|
||||
|
||||
case plateNumber = 0
|
||||
case vin = 1
|
||||
case notes = 2
|
||||
|
||||
public var title: String {
|
||||
switch self {
|
||||
case .plateNumber: return NSLocalizedString("Plate number", comment: "")
|
||||
case .vin: return NSLocalizedString("VIN", comment: "")
|
||||
case .notes: return NSLocalizedString("Notes", comment: "")
|
||||
}
|
||||
}
|
||||
|
||||
public var stringValue: String {
|
||||
switch self {
|
||||
case .plateNumber: return "plateNumber"
|
||||
case .vin: return "vin"
|
||||
case .notes: return "notes"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct Filter {
|
||||
public var searchString = ""
|
||||
public var brand: String?
|
||||
@ -55,6 +78,7 @@ public struct Filter {
|
||||
public var fromLocationDate: Date?
|
||||
public var toLocationDate: Date?
|
||||
public var needReset: Bool = false
|
||||
public var scope: SearchScope = .plateNumber
|
||||
|
||||
public init() {
|
||||
}
|
||||
@ -74,6 +98,7 @@ public struct Filter {
|
||||
self.toDateUpdated = nil
|
||||
self.fromLocationDate = nil
|
||||
self.toLocationDate = nil
|
||||
self.scope = .plateNumber
|
||||
}
|
||||
|
||||
public func queryDictionary() -> [String: String] {
|
||||
@ -122,6 +147,8 @@ public struct Filter {
|
||||
dict["toLocationDate"] = String(toLocationDate.timeIntervalSince1970)
|
||||
}
|
||||
|
||||
dict["scope"] = scope.stringValue
|
||||
|
||||
return dict
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user