diff --git a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 03df2d6..803f859 100644 --- a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -17,7 +17,7 @@ BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint"> Bool { let config = Realm.Configuration( - schemaVersion: 13, + schemaVersion: 14, migrationBlock: { migration, oldSchemaVersion in if oldSchemaVersion <= 3 { var numbers: [String] = [] diff --git a/AutoCat/Controllers/CheckController.swift b/AutoCat/Controllers/CheckController.swift index bb422a2..993382f 100644 --- a/AutoCat/Controllers/CheckController.swift +++ b/AutoCat/Controllers/CheckController.swift @@ -147,6 +147,7 @@ class CheckController: UIViewController, MaskedTextFieldDelegateListener, UITabl let eventSingle = event == nil ? self.getEvent() : Single.just(event!) eventSingle + .flatMap { event in event.updateAddress().map{ event }.catchErrorJustReturn(event) } .flatMap { Api.add(event: $0, to: vehicle.number) } .subscribe(onSuccess: self.save(vehicle:), onError: { print("Error adding event: \($0)") }) .disposed(by: self.bag) diff --git a/AutoCat/Controllers/ReportController.swift b/AutoCat/Controllers/ReportController.swift index 6df059a..ee91df9 100644 --- a/AutoCat/Controllers/ReportController.swift +++ b/AutoCat/Controllers/ReportController.swift @@ -28,6 +28,7 @@ enum ReportGeneralSection: Int, CaseIterable, CustomStringConvertible { case wheelPosition = 3 case japanese = 4 case owners = 5 + case events = 6 var description: String { switch self { @@ -37,6 +38,7 @@ enum ReportGeneralSection: Int, CaseIterable, CustomStringConvertible { case .wheelPosition: return "Steering wheel position" case .japanese: return "Japanese" case .owners: return "Owners (from PTS)" + case .events: return "Events" } } } @@ -172,6 +174,8 @@ class ReportController: UIViewController, UICollectionViewDataSource, UICollecti case .owners: cell?.configure(param: generalSection.description, value: String(vehicle.ownershipPeriods.count)) break + case .events: + cell?.configure(param: generalSection.description, value: String(vehicle.events.count)) } } return cell ?? UICollectionViewCell() diff --git a/AutoCat/Models/VehicleEvent.swift b/AutoCat/Models/VehicleEvent.swift index dc9f0da..473690d 100644 --- a/AutoCat/Models/VehicleEvent.swift +++ b/AutoCat/Models/VehicleEvent.swift @@ -1,5 +1,6 @@ import Foundation import RealmSwift +import RxSwift class VehicleEvent: Object, Codable { @objc dynamic var date: TimeInterval = Date().timeIntervalSince1970 @@ -20,7 +21,9 @@ class VehicleEvent: Object, Codable { super.init() } - override class func ignoredProperties() -> [String] { - return ["address"] + func updateAddress() -> Single { + return LocationManager + .getAddressForLocation(latitude: self.latitude, longitude: self.longitude) + .map { self.address = $0 } } } diff --git a/AutoCat/Utils/Constants.swift b/AutoCat/Utils/Constants.swift index a87f1d4..9bfd07e 100644 --- a/AutoCat/Utils/Constants.swift +++ b/AutoCat/Utils/Constants.swift @@ -3,8 +3,8 @@ import Foundation enum Constants { static var baseUrl: String { #if DEBUG - //return "http://192.168.1.67:3000/" - return "https://vps.aliencat.pro:8443/" + return "http://192.168.1.67:3000/" + //return "https://vps.aliencat.pro:8443/" #else return "https://vps.aliencat.pro:8443/" #endif diff --git a/AutoCat/Utils/Location.swift b/AutoCat/Utils/Location.swift index 7a81046..2dedd0c 100644 --- a/AutoCat/Utils/Location.swift +++ b/AutoCat/Utils/Location.swift @@ -19,17 +19,6 @@ class RxLocationManagerDelegateProxy: DelegateProxy Observable { -// self.authSubject = PublishSubject() -// return self.authSubject -// } -// -// func generateLocationObservable() -> Observable { -// print("generateLocationObservable") -// self.locationSubject = PublishSubject() -// return self.locationSubject -// } - // MARK: - DelegateProxyType static func registerKnownImplementations() { @@ -126,4 +115,24 @@ class LocationManager { self.manager.stopUpdatingLocation() }) } + + static func getAddressForLocation(latitude: Double, longitude: Double) -> Single { + return Single.create { observer in + let geocoder = CLGeocoder() + let location = CLLocation(latitude: latitude, longitude: longitude) + geocoder.reverseGeocodeLocation(location) { placemarks, error in + if let error = error { + observer(.error(error)) + } else if let placemark = placemarks?.first, let name = placemark.name { + observer(.success(name)) + } else { + observer(.error(NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Reverse geolocation error"]))) + } + } + + return Disposables.create { + geocoder.cancelGeocode() + } + } + } }