Update vehicles from search results
This commit is contained in:
parent
cb71fd16bb
commit
c48fa0b041
@ -779,7 +779,7 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 42;
|
||||
CURRENT_PROJECT_VERSION = 43;
|
||||
DEVELOPMENT_TEAM = 46DTTB8X4S;
|
||||
INFOPLIST_FILE = AutoCat/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
||||
@ -801,7 +801,7 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 42;
|
||||
CURRENT_PROJECT_VERSION = 43;
|
||||
DEVELOPMENT_TEAM = 46DTTB8X4S;
|
||||
INFOPLIST_FILE = AutoCat/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
||||
|
||||
@ -2,6 +2,7 @@ import UIKit
|
||||
import RxDataSources
|
||||
import RxSwift
|
||||
import RxCocoa
|
||||
import RealmSwift
|
||||
|
||||
class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDelegate {
|
||||
|
||||
@ -11,6 +12,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
||||
let bag = DisposeBag()
|
||||
let searchController = UISearchController(searchResultsController: nil)
|
||||
var refreshControl = UIRefreshControl()
|
||||
var datasource: RxTableViewSectionedAnimatedDataSource<DateSection<Vehicle>>!
|
||||
|
||||
var filterRelay = BehaviorRelay<Filter>(value: Filter())
|
||||
var filter = Filter()
|
||||
@ -30,7 +32,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
||||
self.refreshControl.addTarget(self, action: #selector(self.refresh(_:)), for: .valueChanged)
|
||||
self.tableView.addSubview(self.refreshControl)
|
||||
|
||||
let ds = RxTableViewSectionedAnimatedDataSource<DateSection<Vehicle>>(configureCell: { dataSource, tableView, indexPath, item in
|
||||
self.datasource = RxTableViewSectionedAnimatedDataSource<DateSection<Vehicle>>(configureCell: { dataSource, tableView, indexPath, item in
|
||||
if let cell = tableView.dequeueReusableCell(withIdentifier: "VehicleCell", for: indexPath) as? VehicleCell {
|
||||
cell.configure(with: item)
|
||||
return cell
|
||||
@ -38,8 +40,9 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
||||
return UITableViewCell()
|
||||
}
|
||||
})
|
||||
self.datasource.canEditRowAtIndexPath = { _, _ in true }
|
||||
|
||||
ds.titleForHeaderInSection = { dataSourse, index in
|
||||
self.datasource.titleForHeaderInSection = { dataSourse, index in
|
||||
return dataSourse.sectionModels[index].header
|
||||
}
|
||||
|
||||
@ -59,7 +62,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
||||
self.refreshControl.endRefreshing()
|
||||
})
|
||||
.map { $0.groupedByDate() }
|
||||
.bind(to: self.tableView.rx.items(dataSource: ds))
|
||||
.bind(to: self.tableView.rx.items(dataSource: self.datasource))
|
||||
.disposed(by: self.bag)
|
||||
}
|
||||
|
||||
@ -130,19 +133,47 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
||||
|
||||
// MARK: - UITableViewDelegate
|
||||
|
||||
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
||||
let vehicle = self.datasource[indexPath]
|
||||
let updateAction = UIContextualAction(style: .normal, title: "Update") { action, view, completion in
|
||||
self.update(vehicle: vehicle, at: indexPath)
|
||||
completion(true)
|
||||
}
|
||||
updateAction.image = UIImage(systemName: "arrow.2.circlepath")
|
||||
updateAction.backgroundColor = .systemBlue
|
||||
|
||||
let configuration = UISwipeActionsConfiguration(actions: [updateAction])
|
||||
configuration.performsFirstActionWithFullSwipe = false
|
||||
return configuration
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
|
||||
//guard let vehicle = try? self.tableView.rx.model(at: indexPath) else { return }
|
||||
let vehicle = self.datasource[indexPath]
|
||||
|
||||
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { _ in
|
||||
let update = UIAction(title: "Update", image: UIImage(systemName: "arrow.2.circlepath")) { action in
|
||||
self.update(vehicle: vehicle, at: indexPath)
|
||||
}
|
||||
|
||||
// return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { _ in
|
||||
// let update = UIAction(title: "Update", image: UIImage(systemName: "arrow.2.circlepath")) { action in
|
||||
// //self.update(vehicle: vehicle)
|
||||
// }
|
||||
// let remove = UIAction(title: "Remove", image: UIImage(systemName: "trash"), attributes: [.destructive]) { action in
|
||||
// //self.remove(vehicle: vehicle)
|
||||
// }
|
||||
//
|
||||
// return UIMenu(title: "Actions", children: [update, remove])
|
||||
// }
|
||||
return UIMenu(title: "Actions", children: [update])
|
||||
}
|
||||
}
|
||||
|
||||
func update(vehicle: Vehicle, at indexPath: IndexPath) {
|
||||
IHProgressHUD.show()
|
||||
Api.checkVehicle(by: vehicle.getNumber(), force: true).observeOn(MainScheduler.instance).subscribe { newVehicle in
|
||||
IHProgressHUD.dismiss()
|
||||
if let realm = try? Realm() {
|
||||
if realm.object(ofType: Vehicle.self, forPrimaryKey: vehicle.getNumber()) != nil {
|
||||
try? realm.write {
|
||||
realm.add(newVehicle, update: .all)
|
||||
}
|
||||
}
|
||||
}
|
||||
self.datasource[indexPath] = newVehicle
|
||||
self.updateDetailController(with: newVehicle)
|
||||
} onError: { err in
|
||||
IHProgressHUD.show(error: err)
|
||||
}.disposed(by: self.bag)
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,9 +3,9 @@ import Foundation
|
||||
enum Constants {
|
||||
static var baseUrl: String {
|
||||
#if DEBUG
|
||||
//return "http://127.0.0.1:3000/"
|
||||
return "http://127.0.0.1:3000/"
|
||||
//return "http://192.168.1.67:3000/"
|
||||
return "https://vps.aliencat.pro:8443/"
|
||||
//return "https://vps.aliencat.pro:8443/"
|
||||
#else
|
||||
return "https://vps.aliencat.pro:8443/"
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user