From 9faa57a4eb41e7cda1ad12a4f43e3ebcc3c48718 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Sat, 12 Sep 2020 16:48:41 +0300 Subject: [PATCH] Show voice record event on map --- AutoCat.xcodeproj/project.pbxproj | 4 +++ .../Location/EventsController.swift | 24 ++++++++--------- .../Location/ShowEventController.swift | 27 +++++++++++++++++++ AutoCat/Controllers/RecordsController.swift | 9 +++++++ AutoCat/Utils/Constants.swift | 4 +-- 5 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 AutoCat/Controllers/Location/ShowEventController.swift diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index c7df5e5..15cb015 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -93,6 +93,7 @@ 7AB67E8C2435C38700258F61 /* CustomTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB67E8B2435C38700258F61 /* CustomTextField.swift */; }; 7AB67E8E2435D1A000258F61 /* CustomButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB67E8D2435D1A000258F61 /* CustomButton.swift */; }; 7ADF6C93250B954900F237B2 /* Navigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7ADF6C92250B954900F237B2 /* Navigation.swift */; }; + 7ADF6C95250D037700F237B2 /* ShowEventController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7ADF6C94250D037700F237B2 /* ShowEventController.swift */; }; 7AE26A3324EEF9EC00625033 /* UIViewControllerExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE26A3224EEF9EC00625033 /* UIViewControllerExt.swift */; }; 7AE26A3524F31B0700625033 /* EventsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE26A3424F31B0700625033 /* EventsController.swift */; }; 7AEFE728240455E200910EB7 /* SettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AEFE727240455E200910EB7 /* SettingsController.swift */; }; @@ -181,6 +182,7 @@ 7AB67E8B2435C38700258F61 /* CustomTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTextField.swift; sourceTree = ""; }; 7AB67E8D2435D1A000258F61 /* CustomButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomButton.swift; sourceTree = ""; }; 7ADF6C92250B954900F237B2 /* Navigation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Navigation.swift; sourceTree = ""; }; + 7ADF6C94250D037700F237B2 /* ShowEventController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShowEventController.swift; sourceTree = ""; }; 7AE26A3224EEF9EC00625033 /* UIViewControllerExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewControllerExt.swift; sourceTree = ""; }; 7AE26A3424F31B0700625033 /* EventsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventsController.swift; sourceTree = ""; }; 7AEFE727240455E200910EB7 /* SettingsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsController.swift; sourceTree = ""; }; @@ -421,6 +423,7 @@ 7AE26A3424F31B0700625033 /* EventsController.swift */, 7A813DC8250B5C9700CC93B9 /* LocationRow.swift */, 7A813DCA250B5DC900CC93B9 /* LocationPickerController.swift */, + 7ADF6C94250D037700F237B2 /* ShowEventController.swift */, ); path = Location; sourceTree = ""; @@ -588,6 +591,7 @@ 7A21112A24FC3D7E003BBF6F /* AudioEngine.swift in Sources */, 7A8A220B248D67B60073DFD9 /* VehicleReportImage.swift in Sources */, 7A488C3E24A74B990054D0B2 /* Reactive+RxRealmDataSources.swift in Sources */, + 7ADF6C95250D037700F237B2 /* ShowEventController.swift in Sources */, 7A27ADC7249D43210035F39E /* RegionsController.swift in Sources */, 7A05161A2414FF0900FC55AC /* DateSection.swift in Sources */, 7A333814249A532400D878F1 /* Filter.swift in Sources */, diff --git a/AutoCat/Controllers/Location/EventsController.swift b/AutoCat/Controllers/Location/EventsController.swift index 23134ff..dabb006 100644 --- a/AutoCat/Controllers/Location/EventsController.swift +++ b/AutoCat/Controllers/Location/EventsController.swift @@ -14,6 +14,17 @@ class EventPin: NSObject, MKAnnotation { self.title = title self.subtitle = subtitle } + + convenience init(event: VehicleEvent) { + let coordinate = CLLocationCoordinate2D(latitude: event.latitude, longitude: event.longitude) + let subtitle = event.address ?? "\(event.latitude), \(event.longitude)" + let date = Date(timeIntervalSince1970: event.date) + let formatter = DateFormatter() + formatter.dateStyle = .medium + formatter.timeStyle = .short + let title = formatter.string(from: date) + self.init(coordinate: coordinate, title: title, subtitle: subtitle) + } } enum EventsMode { @@ -34,18 +45,7 @@ class EventsController: UIViewController, UITableViewDataSource, UITableViewDele public var vehicle: Vehicle? { didSet { if let vehicle = self.vehicle { - self.pins = vehicle.events.map { event in - let coordinate = CLLocationCoordinate2D(latitude: event.latitude, longitude: event.longitude) - let subtitle = event.address ?? "\(event.latitude), \(event.longitude)" - let date = Date(timeIntervalSince1970: event.date) - let formatter = DateFormatter() - formatter.dateStyle = .medium - formatter.timeStyle = .short - let title = formatter.string(from: date) - return EventPin(coordinate: coordinate, title: title, subtitle: subtitle) - } - } else { - + self.pins = vehicle.events.map(EventPin.init(event:)) } if self.isViewLoaded { diff --git a/AutoCat/Controllers/Location/ShowEventController.swift b/AutoCat/Controllers/Location/ShowEventController.swift new file mode 100644 index 0000000..8d2af02 --- /dev/null +++ b/AutoCat/Controllers/Location/ShowEventController.swift @@ -0,0 +1,27 @@ +import UIKit +import MapKit + +class ShowEventController: UIViewController { + + private var map = MKMapView() + var event: VehicleEvent? + + override func viewDidLoad() { + super.viewDidLoad() + + self.map.translatesAutoresizingMaskIntoConstraints = false + self.view.addSubview(self.map) + self.map.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true + self.map.trailingAnchor.constraint(equalTo: self.view.trailingAnchor).isActive = true + self.map.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true + self.map.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true + + if let event = self.event { + self.title = event.address ?? String(format: "%.02f, %.02f", event.latitude, event.longitude) + let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: event.latitude, longitude: event.longitude), latitudinalMeters: 1000, longitudinalMeters: 1000) + self.map.setRegion(region, animated: true) + let pin = EventPin(event: event) + self.map.addAnnotation(pin) + } + } +} diff --git a/AutoCat/Controllers/RecordsController.swift b/AutoCat/Controllers/RecordsController.swift index 34a387e..0cc5b03 100644 --- a/AutoCat/Controllers/RecordsController.swift +++ b/AutoCat/Controllers/RecordsController.swift @@ -300,9 +300,18 @@ class RecordsController: UIViewController, UITableViewDelegate { let editNumber = UIAlertAction(title: "Edit plate number", style: .default) { action in self.edit(record: record) } + let showOnMap = UIAlertAction(title: "Show on map", style: .default) { action in + let controller = ShowEventController() + controller.event = record.event + controller.hidesBottomBarWhenPushed = true + self.navigationController?.pushViewController(controller, animated: true) + } sheet.addAction(editNumber) sheet.addAction(showText) + if record.event != nil { + sheet.addAction(showOnMap) + } sheet.addAction(share) sheet.addAction(cancel) sheet.popoverPresentationController?.sourceView = cell diff --git a/AutoCat/Utils/Constants.swift b/AutoCat/Utils/Constants.swift index 0ce0772..5afbb1c 100644 --- a/AutoCat/Utils/Constants.swift +++ b/AutoCat/Utils/Constants.swift @@ -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