Few more location-related fixes. Fix for unknown steering wheel position
This commit is contained in:
parent
6168ac2f0a
commit
de6c6a7ac5
@ -707,7 +707,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 = 24;
|
CURRENT_PROJECT_VERSION = 25;
|
||||||
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;
|
||||||
@ -729,7 +729,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 = 24;
|
CURRENT_PROJECT_VERSION = 25;
|
||||||
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;
|
||||||
|
|||||||
@ -23,7 +23,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||||
|
|
||||||
let config = Realm.Configuration(
|
let config = Realm.Configuration(
|
||||||
schemaVersion: 14,
|
schemaVersion: 15,
|
||||||
migrationBlock: { migration, oldSchemaVersion in
|
migrationBlock: { migration, oldSchemaVersion in
|
||||||
if oldSchemaVersion <= 3 {
|
if oldSchemaVersion <= 3 {
|
||||||
var numbers: [String] = []
|
var numbers: [String] = []
|
||||||
@ -37,6 +37,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if oldSchemaVersion <= 14 {
|
||||||
|
migration.enumerateObjects(ofType: "Vehicle") { old, new in
|
||||||
|
new!["isRightWheel"] = RealmOptional<Bool>(old!["isRightWheel"] as? Bool)
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
Realm.Configuration.defaultConfiguration = config
|
Realm.Configuration.defaultConfiguration = config
|
||||||
|
|||||||
@ -6,6 +6,12 @@ import SwiftDate
|
|||||||
import RxRealm
|
import RxRealm
|
||||||
import RxDataSources
|
import RxDataSources
|
||||||
|
|
||||||
|
enum EventAction {
|
||||||
|
case doNotSend
|
||||||
|
case receiveAndSend
|
||||||
|
case sendSpecific(VehicleEvent)
|
||||||
|
}
|
||||||
|
|
||||||
class CheckController: UIViewController, MaskedTextFieldDelegateListener, UITableViewDelegate {
|
class CheckController: UIViewController, MaskedTextFieldDelegateListener, UITableViewDelegate {
|
||||||
|
|
||||||
@IBOutlet weak var number: UITextField!
|
@IBOutlet weak var number: UITextField!
|
||||||
@ -85,7 +91,11 @@ class CheckController: UIViewController, MaskedTextFieldDelegateListener, UITabl
|
|||||||
break
|
break
|
||||||
case .checkNumber(let number, let event):
|
case .checkNumber(let number, let event):
|
||||||
ad.quickAction = .none
|
ad.quickAction = .none
|
||||||
self.check(number: number, event: event)
|
var action: EventAction = .receiveAndSend
|
||||||
|
if let event = event {
|
||||||
|
action = .sendSpecific(event)
|
||||||
|
}
|
||||||
|
self.check(number: number, action: action)
|
||||||
break
|
break
|
||||||
case .addVoiceRecord:
|
case .addVoiceRecord:
|
||||||
self.tabBarController?.selectedIndex = 1
|
self.tabBarController?.selectedIndex = 1
|
||||||
@ -101,10 +111,10 @@ class CheckController: UIViewController, MaskedTextFieldDelegateListener, UITabl
|
|||||||
guard let number = self.number.text else { return }
|
guard let number = self.number.text else { return }
|
||||||
|
|
||||||
let numberNormalized = number.filter { !$0.isWhitespace }.uppercased()
|
let numberNormalized = number.filter { !$0.isWhitespace }.uppercased()
|
||||||
self.check(number: numberNormalized, event: nil)
|
self.check(number: numberNormalized, action: .receiveAndSend)
|
||||||
}
|
}
|
||||||
|
|
||||||
func check(number: String, event: VehicleEvent?) {
|
func check(number: String, action: EventAction) {
|
||||||
self.number.resignFirstResponder()
|
self.number.resignFirstResponder()
|
||||||
self.number.text = nil
|
self.number.text = nil
|
||||||
self.check.isEnabled = false
|
self.check.isEnabled = false
|
||||||
@ -112,16 +122,20 @@ class CheckController: UIViewController, MaskedTextFieldDelegateListener, UITabl
|
|||||||
Api.checkVehicle(by: number)
|
Api.checkVehicle(by: number)
|
||||||
.observeOn(MainScheduler.instance)
|
.observeOn(MainScheduler.instance)
|
||||||
.subscribe(onSuccess: { vehicle in
|
.subscribe(onSuccess: { vehicle in
|
||||||
self.onReceivedVehicle(vehicle, event: event)
|
self.onReceivedVehicle(vehicle, action: action)
|
||||||
}, onError: { err in
|
}, onError: { err in
|
||||||
if let realm = try? Realm() {
|
if let realm = try? Realm() {
|
||||||
let vehicle = Vehicle(number)
|
let vehicle = Vehicle(number)
|
||||||
try? realm.write {
|
try? realm.write {
|
||||||
realm.add(vehicle, update: .all)
|
realm.add(vehicle, update: .all)
|
||||||
}
|
}
|
||||||
let eventSingle = event == nil ? self.getEvent() : Single.just(event!)
|
|
||||||
|
var eventSingle = self.getEvent()
|
||||||
|
if case .sendSpecific(let event) = action {
|
||||||
|
eventSingle = Single.just(event)
|
||||||
|
}
|
||||||
eventSingle
|
eventSingle
|
||||||
.flatMap { event in event.updateAddress().map{ [event] }.catchErrorJustReturn([event]) }
|
.flatMap { event in event.findAddress().map{ [event] }.catchErrorJustReturn([event]) }
|
||||||
.catchErrorJustReturn([])
|
.catchErrorJustReturn([])
|
||||||
.subscribe(onSuccess: { events in
|
.subscribe(onSuccess: { events in
|
||||||
try? realm.write {
|
try? realm.write {
|
||||||
@ -153,15 +167,22 @@ class CheckController: UIViewController, MaskedTextFieldDelegateListener, UITabl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func onReceivedVehicle(_ vehicle: Vehicle, event: VehicleEvent? = nil) {
|
func onReceivedVehicle(_ vehicle: Vehicle, action: EventAction = .receiveAndSend) {
|
||||||
self.save(vehicle: vehicle)
|
self.save(vehicle: vehicle)
|
||||||
|
|
||||||
let eventSingle = event == nil ? self.getEvent() : Single.just(event!)
|
if case .doNotSend = action {
|
||||||
|
// Just do nothing
|
||||||
|
} else {
|
||||||
|
var eventSingle = self.getEvent()
|
||||||
|
if case .sendSpecific(let event) = action {
|
||||||
|
eventSingle = Single.just(event)
|
||||||
|
}
|
||||||
eventSingle
|
eventSingle
|
||||||
.flatMap { event in event.updateAddress().map{ event }.catchErrorJustReturn(event) }
|
.flatMap { event in event.findAddress().map{ event }.catchErrorJustReturn(event) }
|
||||||
.flatMap { Api.add(event: $0, to: vehicle.number) }
|
.flatMap { Api.add(event: $0, to: vehicle.number) }
|
||||||
.subscribe(onSuccess: self.save(vehicle:), onError: { print("Error adding event: \($0)") })
|
.subscribe(onSuccess: self.save(vehicle:), onError: { print("Error adding event: \($0)") })
|
||||||
.disposed(by: self.bag)
|
.disposed(by: self.bag)
|
||||||
|
}
|
||||||
|
|
||||||
self.updateDetailController(with: vehicle)
|
self.updateDetailController(with: vehicle)
|
||||||
IHProgressHUD.dismiss()
|
IHProgressHUD.dismiss()
|
||||||
@ -213,15 +234,15 @@ class CheckController: UIViewController, MaskedTextFieldDelegateListener, UITabl
|
|||||||
let updateAction = UIContextualAction(style: .normal, title: "Update") { action, view, completion in
|
let updateAction = UIContextualAction(style: .normal, title: "Update") { action, view, completion in
|
||||||
IHProgressHUD.show()
|
IHProgressHUD.show()
|
||||||
|
|
||||||
var event: VehicleEvent? = nil
|
var eventAction: EventAction = .doNotSend
|
||||||
if vehicle.unrecognized, let savedEvent = vehicle.events.first {
|
if vehicle.unrecognized, let savedEvent = vehicle.events.first {
|
||||||
event = savedEvent
|
eventAction = .sendSpecific(savedEvent.freeze())
|
||||||
}
|
}
|
||||||
|
|
||||||
Api.checkVehicle(by: vehicle.number, force: true)
|
Api.checkVehicle(by: vehicle.number, force: true)
|
||||||
.observeOn(MainScheduler.instance)
|
.observeOn(MainScheduler.instance)
|
||||||
.subscribe(onSuccess: { vehicle in
|
.subscribe(onSuccess: { vehicle in
|
||||||
self.onReceivedVehicle(vehicle, event: event)
|
self.onReceivedVehicle(vehicle, action: eventAction)
|
||||||
}, onError: { err in
|
}, onError: { err in
|
||||||
IHProgressHUD.showError(withStatus: err.localizedDescription)
|
IHProgressHUD.showError(withStatus: err.localizedDescription)
|
||||||
print(err.localizedDescription)
|
print(err.localizedDescription)
|
||||||
|
|||||||
@ -180,7 +180,11 @@ class ReportController: UIViewController, UICollectionViewDataSource, UICollecti
|
|||||||
cell?.configure(param: generalSection.description, value: vehicle.category ?? "<unknown>")
|
cell?.configure(param: generalSection.description, value: vehicle.category ?? "<unknown>")
|
||||||
break
|
break
|
||||||
case .wheelPosition:
|
case .wheelPosition:
|
||||||
cell?.configure(param: generalSection.description, value: vehicle.isRightWheel ? "Right" : "Left")
|
var position = "Unknown"
|
||||||
|
if let rightWheel = vehicle.isRightWheel.value {
|
||||||
|
position = rightWheel ? "Right" : "Left"
|
||||||
|
}
|
||||||
|
cell?.configure(param: generalSection.description, value: position)
|
||||||
break
|
break
|
||||||
case .japanese:
|
case .japanese:
|
||||||
cell?.configure(param: generalSection.description, value: vehicle.isJapanese ? "Yes" : "No")
|
cell?.configure(param: generalSection.description, value: vehicle.isJapanese ? "Yes" : "No")
|
||||||
|
|||||||
@ -80,7 +80,11 @@ extension Vehicle {
|
|||||||
y += cellHeight
|
y += cellHeight
|
||||||
self.drawCell(y: y, width: w, height: cellHeight, title: "Category", value: self.category ?? "<unknown>", context: ctx)
|
self.drawCell(y: y, width: w, height: cellHeight, title: "Category", value: self.category ?? "<unknown>", context: ctx)
|
||||||
y += cellHeight
|
y += cellHeight
|
||||||
self.drawCell(y: y, width: w, height: cellHeight, title: "Steering wheel position", value: self.isRightWheel ? "Right" : "Left", context: ctx)
|
var position = "Unknown"
|
||||||
|
if let rightWheel = self.isRightWheel.value {
|
||||||
|
position = rightWheel ? "Right" : "Left"
|
||||||
|
}
|
||||||
|
self.drawCell(y: y, width: w, height: cellHeight, title: "Steering wheel position", value: position, context: ctx)
|
||||||
y += cellHeight
|
y += cellHeight
|
||||||
self.drawCell(y: y, width: w, height: cellHeight, title: "Japanese", value: self.isJapanese ? "Yes" : "No", lineMargin: 0, context: ctx)
|
self.drawCell(y: y, width: w, height: cellHeight, title: "Japanese", value: self.isJapanese ? "Yes" : "No", lineMargin: 0, context: ctx)
|
||||||
y += cellHeight + 32
|
y += cellHeight + 32
|
||||||
@ -182,7 +186,11 @@ extension Vehicle {
|
|||||||
text += "Year: \(self.year)\n"
|
text += "Year: \(self.year)\n"
|
||||||
if let color = self.color { text += "Color: \(color)\n" }
|
if let color = self.color { text += "Color: \(color)\n" }
|
||||||
if let category = self.category { text += "Category: \(category)\n" }
|
if let category = self.category { text += "Category: \(category)\n" }
|
||||||
text += "Steering wheel position: \(self.isRightWheel ? "right" : "left")\n"
|
var position = "Unknown"
|
||||||
|
if let rightWheel = self.isRightWheel.value {
|
||||||
|
position = rightWheel ? "Right" : "Left"
|
||||||
|
}
|
||||||
|
text += "Steering wheel position: \(position)\n"
|
||||||
text += "Japanese: \(self.isJapanese ? "yes" : "no")\n"
|
text += "Japanese: \(self.isJapanese ? "yes" : "no")\n"
|
||||||
text += "Plate number: \(self.number)\n"
|
text += "Plate number: \(self.number)\n"
|
||||||
if let vin = self.vin1 { text += "VIN: \(vin)\n" }
|
if let vin = self.vin1 { text += "VIN: \(vin)\n" }
|
||||||
|
|||||||
@ -45,6 +45,20 @@ enum OwnerType: String {
|
|||||||
case individual
|
case individual
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum SteeringWheelPosition: CustomStringConvertible {
|
||||||
|
case left
|
||||||
|
case right
|
||||||
|
case unknown
|
||||||
|
|
||||||
|
var description: String {
|
||||||
|
switch self {
|
||||||
|
case .left: return "Left"
|
||||||
|
case .right: return "Right"
|
||||||
|
case .unknown: return "Unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class VehicleOwnershipPeriod: Object, Decodable {
|
class VehicleOwnershipPeriod: Object, Decodable {
|
||||||
@objc dynamic var lastOperation: String
|
@objc dynamic var lastOperation: String
|
||||||
@objc dynamic var ownerType: String
|
@objc dynamic var ownerType: String
|
||||||
@ -64,7 +78,7 @@ class Vehicle: Object, Decodable, IdentifiableType {
|
|||||||
@objc dynamic var vin2: String?
|
@objc dynamic var vin2: String?
|
||||||
@objc dynamic var sts: String?
|
@objc dynamic var sts: String?
|
||||||
@objc dynamic var pts: String?
|
@objc dynamic var pts: String?
|
||||||
@objc dynamic var isRightWheel: Bool = false
|
var isRightWheel = RealmOptional<Bool>()
|
||||||
@objc dynamic var isJapanese: Bool = false
|
@objc dynamic var isJapanese: Bool = false
|
||||||
@objc dynamic var addedDate: TimeInterval = 0
|
@objc dynamic var addedDate: TimeInterval = 0
|
||||||
@objc dynamic var addedBy: String = ""
|
@objc dynamic var addedBy: String = ""
|
||||||
@ -108,7 +122,7 @@ class Vehicle: Object, Decodable, IdentifiableType {
|
|||||||
self.vin2 = try container.decodeIfPresent(String.self, forKey: .vin2)
|
self.vin2 = try container.decodeIfPresent(String.self, forKey: .vin2)
|
||||||
self.sts = try container.decodeIfPresent(String.self, forKey: .sts)
|
self.sts = try container.decodeIfPresent(String.self, forKey: .sts)
|
||||||
self.pts = try container.decodeIfPresent(String.self, forKey: .pts)
|
self.pts = try container.decodeIfPresent(String.self, forKey: .pts)
|
||||||
self.isRightWheel = try container.decode(Bool.self, forKey: .isRightWheel)
|
self.isRightWheel = try container.decode(RealmOptional<Bool>.self, forKey: .isRightWheel)
|
||||||
self.isJapanese = try container.decode(Bool.self, forKey: .isJapanese)
|
self.isJapanese = try container.decode(Bool.self, forKey: .isJapanese)
|
||||||
self.addedDate = try container.decode(TimeInterval.self, forKey: .addedDate)
|
self.addedDate = try container.decode(TimeInterval.self, forKey: .addedDate)
|
||||||
self.addedBy = try container.decode(String.self, forKey: .addedBy)
|
self.addedBy = try container.decode(String.self, forKey: .addedBy)
|
||||||
|
|||||||
@ -21,9 +21,13 @@ class VehicleEvent: Object, Codable {
|
|||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateAddress() -> Single<Void> {
|
func findAddress() -> Single<Void> {
|
||||||
|
if address != nil {
|
||||||
|
return Single.just(())
|
||||||
|
} else {
|
||||||
return LocationManager
|
return LocationManager
|
||||||
.getAddressForLocation(latitude: self.latitude, longitude: self.longitude)
|
.getAddressForLocation(latitude: self.latitude, longitude: self.longitude)
|
||||||
.map { self.address = $0 }
|
.map { self.address = $0 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -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