Update vehicles from search results
This commit is contained in:
parent
cb71fd16bb
commit
c48fa0b041
@ -779,7 +779,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 = 42;
|
CURRENT_PROJECT_VERSION = 43;
|
||||||
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;
|
||||||
@ -801,7 +801,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 = 42;
|
CURRENT_PROJECT_VERSION = 43;
|
||||||
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;
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import UIKit
|
|||||||
import RxDataSources
|
import RxDataSources
|
||||||
import RxSwift
|
import RxSwift
|
||||||
import RxCocoa
|
import RxCocoa
|
||||||
|
import RealmSwift
|
||||||
|
|
||||||
class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDelegate {
|
class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDelegate {
|
||||||
|
|
||||||
@ -11,6 +12,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
|||||||
let bag = DisposeBag()
|
let bag = DisposeBag()
|
||||||
let searchController = UISearchController(searchResultsController: nil)
|
let searchController = UISearchController(searchResultsController: nil)
|
||||||
var refreshControl = UIRefreshControl()
|
var refreshControl = UIRefreshControl()
|
||||||
|
var datasource: RxTableViewSectionedAnimatedDataSource<DateSection<Vehicle>>!
|
||||||
|
|
||||||
var filterRelay = BehaviorRelay<Filter>(value: Filter())
|
var filterRelay = BehaviorRelay<Filter>(value: Filter())
|
||||||
var filter = Filter()
|
var filter = Filter()
|
||||||
@ -30,7 +32,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
|||||||
self.refreshControl.addTarget(self, action: #selector(self.refresh(_:)), for: .valueChanged)
|
self.refreshControl.addTarget(self, action: #selector(self.refresh(_:)), for: .valueChanged)
|
||||||
self.tableView.addSubview(self.refreshControl)
|
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 {
|
if let cell = tableView.dequeueReusableCell(withIdentifier: "VehicleCell", for: indexPath) as? VehicleCell {
|
||||||
cell.configure(with: item)
|
cell.configure(with: item)
|
||||||
return cell
|
return cell
|
||||||
@ -38,8 +40,9 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
|||||||
return UITableViewCell()
|
return UITableViewCell()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
self.datasource.canEditRowAtIndexPath = { _, _ in true }
|
||||||
|
|
||||||
ds.titleForHeaderInSection = { dataSourse, index in
|
self.datasource.titleForHeaderInSection = { dataSourse, index in
|
||||||
return dataSourse.sectionModels[index].header
|
return dataSourse.sectionModels[index].header
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +62,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
|||||||
self.refreshControl.endRefreshing()
|
self.refreshControl.endRefreshing()
|
||||||
})
|
})
|
||||||
.map { $0.groupedByDate() }
|
.map { $0.groupedByDate() }
|
||||||
.bind(to: self.tableView.rx.items(dataSource: ds))
|
.bind(to: self.tableView.rx.items(dataSource: self.datasource))
|
||||||
.disposed(by: self.bag)
|
.disposed(by: self.bag)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,19 +133,47 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
|||||||
|
|
||||||
// MARK: - UITableViewDelegate
|
// 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? {
|
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
|
return UIMenu(title: "Actions", children: [update])
|
||||||
// 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
|
func update(vehicle: Vehicle, at indexPath: IndexPath) {
|
||||||
// //self.remove(vehicle: vehicle)
|
IHProgressHUD.show()
|
||||||
// }
|
Api.checkVehicle(by: vehicle.getNumber(), force: true).observeOn(MainScheduler.instance).subscribe { newVehicle in
|
||||||
//
|
IHProgressHUD.dismiss()
|
||||||
// return UIMenu(title: "Actions", children: [update, remove])
|
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 {
|
enum Constants {
|
||||||
static var baseUrl: String {
|
static var baseUrl: String {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
//return "http://127.0.0.1:3000/"
|
return "http://127.0.0.1:3000/"
|
||||||
//return "http://192.168.1.67:3000/"
|
//return "http://192.168.1.67:3000/"
|
||||||
return "https://vps.aliencat.pro:8443/"
|
//return "https://vps.aliencat.pro:8443/"
|
||||||
#else
|
#else
|
||||||
return "https://vps.aliencat.pro:8443/"
|
return "https://vps.aliencat.pro:8443/"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user