Fixing server search
This commit is contained in:
parent
4ef18b88a1
commit
898aea2f91
@ -33,6 +33,7 @@
|
|||||||
7A2DE69B25869ABD00A113FC /* AdsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A2DE69A25869ABD00A113FC /* AdsController.swift */; };
|
7A2DE69B25869ABD00A113FC /* AdsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A2DE69A25869ABD00A113FC /* AdsController.swift */; };
|
||||||
7A2DE69E2589606A00A113FC /* ImageGridRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A2DE69D2589606A00A113FC /* ImageGridRow.swift */; };
|
7A2DE69E2589606A00A113FC /* ImageGridRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A2DE69D2589606A00A113FC /* ImageGridRow.swift */; };
|
||||||
7A33381124990DAE00D878F1 /* FiltersController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A33381024990DAE00D878F1 /* FiltersController.swift */; };
|
7A33381124990DAE00D878F1 /* FiltersController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A33381024990DAE00D878F1 /* FiltersController.swift */; };
|
||||||
|
7A3399AB299063370087DF98 /* SearchControllerExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A3399AA299063370087DF98 /* SearchControllerExt.swift */; };
|
||||||
7A35177B27E23F8800DC538C /* Eureka in Frameworks */ = {isa = PBXBuildFile; productRef = 7A35177A27E23F8800DC538C /* Eureka */; };
|
7A35177B27E23F8800DC538C /* Eureka in Frameworks */ = {isa = PBXBuildFile; productRef = 7A35177A27E23F8800DC538C /* Eureka */; };
|
||||||
7A3F07AB24360DC800E59687 /* Dated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A3F07AA24360DC800E59687 /* Dated.swift */; };
|
7A3F07AB24360DC800E59687 /* Dated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A3F07AA24360DC800E59687 /* Dated.swift */; };
|
||||||
7A3F07AD2436350B00E59687 /* SearchController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A3F07AC2436350B00E59687 /* SearchController.swift */; };
|
7A3F07AD2436350B00E59687 /* SearchController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A3F07AC2436350B00E59687 /* SearchController.swift */; };
|
||||||
@ -205,6 +206,7 @@
|
|||||||
7A2DE69D2589606A00A113FC /* ImageGridRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageGridRow.swift; sourceTree = "<group>"; };
|
7A2DE69D2589606A00A113FC /* ImageGridRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageGridRow.swift; sourceTree = "<group>"; };
|
||||||
7A33381024990DAE00D878F1 /* FiltersController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FiltersController.swift; sourceTree = "<group>"; };
|
7A33381024990DAE00D878F1 /* FiltersController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FiltersController.swift; sourceTree = "<group>"; };
|
||||||
7A333813249A532400D878F1 /* Filter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Filter.swift; sourceTree = "<group>"; };
|
7A333813249A532400D878F1 /* Filter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Filter.swift; sourceTree = "<group>"; };
|
||||||
|
7A3399AA299063370087DF98 /* SearchControllerExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchControllerExt.swift; sourceTree = "<group>"; };
|
||||||
7A3F07AA24360DC800E59687 /* Dated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dated.swift; sourceTree = "<group>"; };
|
7A3F07AA24360DC800E59687 /* Dated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dated.swift; sourceTree = "<group>"; };
|
||||||
7A3F07AC2436350B00E59687 /* SearchController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchController.swift; sourceTree = "<group>"; };
|
7A3F07AC2436350B00E59687 /* SearchController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchController.swift; sourceTree = "<group>"; };
|
||||||
7A43F9F7246C8A6200BA5B49 /* JWT.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JWT.swift; sourceTree = "<group>"; };
|
7A43F9F7246C8A6200BA5B49 /* JWT.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JWT.swift; sourceTree = "<group>"; };
|
||||||
@ -598,6 +600,7 @@
|
|||||||
7AC355572969744100889457 /* Extensions */ = {
|
7AC355572969744100889457 /* Extensions */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
7A3399AA299063370087DF98 /* SearchControllerExt.swift */,
|
||||||
7AC3555129696E3F00889457 /* UIView+layout.swift */,
|
7AC3555129696E3F00889457 /* UIView+layout.swift */,
|
||||||
7AC355582969746600889457 /* UIControl.swift */,
|
7AC355582969746600889457 /* UIControl.swift */,
|
||||||
7AC3555A296995B200889457 /* UIEdgeInsets.swift */,
|
7AC3555A296995B200889457 /* UIEdgeInsets.swift */,
|
||||||
@ -837,6 +840,7 @@
|
|||||||
7A11470123FDE7E500B424AF /* AppDelegate.swift in Sources */,
|
7A11470123FDE7E500B424AF /* AppDelegate.swift in Sources */,
|
||||||
7ADF6C9D250FA96000F237B2 /* SwiftMaskTextfield.swift in Sources */,
|
7ADF6C9D250FA96000F237B2 /* SwiftMaskTextfield.swift in Sources */,
|
||||||
7A813DC9250B5C9700CC93B9 /* LocationRow.swift in Sources */,
|
7A813DC9250B5C9700CC93B9 /* LocationRow.swift in Sources */,
|
||||||
|
7A3399AB299063370087DF98 /* SearchControllerExt.swift in Sources */,
|
||||||
7A2DE69B25869ABD00A113FC /* AdsController.swift in Sources */,
|
7A2DE69B25869ABD00A113FC /* AdsController.swift in Sources */,
|
||||||
7A6DD90824329144009DE740 /* CenterTextLayer.swift in Sources */,
|
7A6DD90824329144009DE740 /* CenterTextLayer.swift in Sources */,
|
||||||
7A99406426E4BFAE002E9CB6 /* VehicleNoteCell.swift in Sources */,
|
7A99406426E4BFAE002E9CB6 /* VehicleNoteCell.swift in Sources */,
|
||||||
@ -1136,7 +1140,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
|
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 107;
|
CURRENT_PROJECT_VERSION = 109;
|
||||||
DEVELOPMENT_TEAM = 46DTTB8X4S;
|
DEVELOPMENT_TEAM = 46DTTB8X4S;
|
||||||
INFOPLIST_FILE = AutoCat/Info.plist;
|
INFOPLIST_FILE = AutoCat/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
||||||
@ -1161,7 +1165,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
|
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 107;
|
CURRENT_PROJECT_VERSION = 109;
|
||||||
DEVELOPMENT_TEAM = 46DTTB8X4S;
|
DEVELOPMENT_TEAM = 46DTTB8X4S;
|
||||||
INFOPLIST_FILE = AutoCat/Info.plist;
|
INFOPLIST_FILE = AutoCat/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
||||||
|
|||||||
40
AutoCat/ACUIKit/Extensions/SearchControllerExt.swift
Normal file
40
AutoCat/ACUIKit/Extensions/SearchControllerExt.swift
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
//
|
||||||
|
// SearchControllerExt.swift
|
||||||
|
// AutoCat
|
||||||
|
//
|
||||||
|
// Created by Selim Mustafaev on 06.02.2023.
|
||||||
|
// Copyright © 2023 Selim Mustafaev. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
extension UISearchController {
|
||||||
|
|
||||||
|
static var `default`: UISearchController {
|
||||||
|
let searchController = UISearchController(searchResultsController: nil)
|
||||||
|
searchController.obscuresBackgroundDuringPresentation = false
|
||||||
|
searchController.hidesNavigationBarDuringPresentation = false
|
||||||
|
searchController.searchBar.keyboardType = .webSearch
|
||||||
|
return searchController
|
||||||
|
}
|
||||||
|
|
||||||
|
func placeholder(_ placeholder: String) -> UISearchController {
|
||||||
|
searchBar.placeholder = placeholder
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
|
func resultsUpdater(_ updater: UISearchResultsUpdating) -> UISearchController {
|
||||||
|
searchResultsUpdater = updater
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeDumb() -> UISearchController {
|
||||||
|
searchBar.autocorrectionType = .no
|
||||||
|
searchBar.spellCheckingType = .no
|
||||||
|
searchBar.autocapitalizationType = .none
|
||||||
|
searchBar.smartDashesType = .no
|
||||||
|
searchBar.smartQuotesType = .no
|
||||||
|
searchBar.smartInsertDeleteType = .no
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -35,17 +35,16 @@ class CheckController: UIViewController, UITableViewDelegate, UISearchResultsUpd
|
|||||||
private var historyDataSource: RealmSectionedDataSource<Vehicle, VehicleCell>!
|
private var historyDataSource: RealmSectionedDataSource<Vehicle, VehicleCell>!
|
||||||
private var historyFilter: HistoryFilter = .all
|
private var historyFilter: HistoryFilter = .all
|
||||||
|
|
||||||
private let searchController = UISearchController(searchResultsController: nil)
|
private lazy var searchController: UISearchController = .default
|
||||||
|
.placeholder(NSLocalizedString("Search plate numbers", comment: ""))
|
||||||
|
.resultsUpdater(self)
|
||||||
|
.makeDumb()
|
||||||
|
|
||||||
// MARK: - Lifecycle
|
// MARK: - Lifecycle
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
searchController.searchResultsUpdater = self
|
|
||||||
searchController.obscuresBackgroundDuringPresentation = false
|
|
||||||
searchController.searchBar.placeholder = NSLocalizedString("Search plate numbers", comment: "")
|
|
||||||
searchController.hidesNavigationBarDuringPresentation = false
|
|
||||||
navigationItem.searchController = searchController
|
navigationItem.searchController = searchController
|
||||||
|
|
||||||
guard let realm = try? Realm() else { return }
|
guard let realm = try? Realm() else { return }
|
||||||
|
|||||||
@ -16,7 +16,12 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
|||||||
private var moreActionsButton: UIBarButtonItem?
|
private var moreActionsButton: UIBarButtonItem?
|
||||||
|
|
||||||
private let bag = DisposeBag()
|
private let bag = DisposeBag()
|
||||||
private let searchController = UISearchController(searchResultsController: nil)
|
|
||||||
|
private lazy var searchController: UISearchController = .default
|
||||||
|
.placeholder(NSLocalizedString("Search plate numbers", comment: ""))
|
||||||
|
.resultsUpdater(self)
|
||||||
|
.makeDumb()
|
||||||
|
|
||||||
private var refreshControl = UIRefreshControl()
|
private var refreshControl = UIRefreshControl()
|
||||||
private var datasource: RxSectionedDataSource<Vehicle,VehicleCell>!
|
private var datasource: RxSectionedDataSource<Vehicle,VehicleCell>!
|
||||||
private var isLoadingPage = false
|
private var isLoadingPage = false
|
||||||
@ -30,10 +35,6 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
|||||||
|
|
||||||
self.showMapButton?.isEnabled = false
|
self.showMapButton?.isEnabled = false
|
||||||
|
|
||||||
searchController.searchResultsUpdater = self
|
|
||||||
searchController.obscuresBackgroundDuringPresentation = false
|
|
||||||
searchController.searchBar.placeholder = NSLocalizedString("Search plate numbers", comment: "")
|
|
||||||
searchController.hidesNavigationBarDuringPresentation = false
|
|
||||||
navigationItem.searchController = searchController
|
navigationItem.searchController = searchController
|
||||||
definesPresentationContext = true
|
definesPresentationContext = true
|
||||||
|
|
||||||
@ -64,7 +65,14 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
|||||||
.do(onNext: { _ in
|
.do(onNext: { _ in
|
||||||
self.showProgress()
|
self.showProgress()
|
||||||
})
|
})
|
||||||
.flatMapLatest { Api.getVehicles(with: $0, pageToken: self.datasource.pageToken).do(onError: { print($0) }).catchErrorJustReturn(PagedResponse<Vehicle>()) }
|
.flatMapLatest { filter in
|
||||||
|
if filter.needReset {
|
||||||
|
self.datasource.reset()
|
||||||
|
}
|
||||||
|
return Api.getVehicles(with: filter, pageToken: self.datasource.pageToken)
|
||||||
|
.do(onError: { print($0) })
|
||||||
|
.catchErrorJustReturn(PagedResponse<Vehicle>())
|
||||||
|
}
|
||||||
.observeOn(MainScheduler.instance)
|
.observeOn(MainScheduler.instance)
|
||||||
.do(onNext: {
|
.do(onNext: {
|
||||||
if let count = $0.count {
|
if let count = $0.count {
|
||||||
@ -126,7 +134,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
|||||||
guard self.filter.searchString != newQuery else { return }
|
guard self.filter.searchString != newQuery else { return }
|
||||||
|
|
||||||
self.filter.searchString = newQuery
|
self.filter.searchString = newQuery
|
||||||
self.datasource.reset()
|
self.filter.needReset = true
|
||||||
self.filterRelay.accept(self.filter)
|
self.filterRelay.accept(self.filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +170,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
|||||||
|
|
||||||
@objc func refresh(_ sender: AnyObject) {
|
@objc func refresh(_ sender: AnyObject) {
|
||||||
self.showMapButton?.isEnabled = false
|
self.showMapButton?.isEnabled = false
|
||||||
self.datasource.reset()
|
self.filter.needReset = true
|
||||||
self.filterRelay.accept(self.filter)
|
self.filterRelay.accept(self.filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +181,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
|||||||
controller.onDone = {
|
controller.onDone = {
|
||||||
self.filter = controller.filter
|
self.filter = controller.filter
|
||||||
self.datasource.setSortParameter(self.filter.sortBy ?? .updatedDate)
|
self.datasource.setSortParameter(self.filter.sortBy ?? .updatedDate)
|
||||||
self.datasource.reset()
|
self.filter.needReset = true
|
||||||
self.filterRelay.accept(self.filter)
|
self.filterRelay.accept(self.filter)
|
||||||
}
|
}
|
||||||
self.navigationController?.pushViewController(controller, animated: true)
|
self.navigationController?.pushViewController(controller, animated: true)
|
||||||
@ -302,6 +310,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
|||||||
let toBottom = tableView.contentSize.height - (tableView.contentOffset.y + tableView.frame.size.height)
|
let toBottom = tableView.contentSize.height - (tableView.contentOffset.y + tableView.frame.size.height)
|
||||||
if toBottom < 100 && !self.isLoadingPage && self.datasource.needMoreData() {
|
if toBottom < 100 && !self.isLoadingPage && self.datasource.needMoreData() {
|
||||||
self.isLoadingPage = true
|
self.isLoadingPage = true
|
||||||
|
self.filter.needReset = false
|
||||||
self.filterRelay.accept(self.filter)
|
self.filterRelay.accept(self.filter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,6 +54,7 @@ public struct Filter {
|
|||||||
public var toDateUpdated: Date?
|
public var toDateUpdated: Date?
|
||||||
public var fromLocationDate: Date?
|
public var fromLocationDate: Date?
|
||||||
public var toLocationDate: Date?
|
public var toLocationDate: Date?
|
||||||
|
public var needReset: Bool = false
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user