diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index b761009..425a893 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -86,6 +86,7 @@ 7AB67E8C2435C38700258F61 /* CustomTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB67E8B2435C38700258F61 /* CustomTextField.swift */; }; 7AB67E8E2435D1A000258F61 /* CustomButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AB67E8D2435D1A000258F61 /* CustomButton.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 */; }; 7AF58D2F24029C5200CE01A0 /* MagazineLayout in Frameworks */ = {isa = PBXBuildFile; productRef = 7AF58D2E24029C5200CE01A0 /* MagazineLayout */; }; 7AF58D3124029E1000CE01A0 /* VehicleHeaderCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AF58D3024029E1000CE01A0 /* VehicleHeaderCell.swift */; }; @@ -166,6 +167,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 = ""; }; 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 = ""; }; 7AF58D3024029E1000CE01A0 /* VehicleHeaderCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehicleHeaderCell.swift; sourceTree = ""; }; 7AF58D57240309CA00CE01A0 /* VehicleTextParamCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehicleTextParamCell.swift; sourceTree = ""; }; @@ -250,6 +252,7 @@ 7A33381024990DAE00D878F1 /* FiltersController.swift */, 7A27ADC6249D43210035F39E /* RegionsController.swift */, 7A27ADF2249F8B650035F39E /* RecordsController.swift */, + 7AE26A3424F31B0700625033 /* EventsController.swift */, ); path = Controllers; sourceTree = ""; @@ -504,6 +507,7 @@ 7A659B5924A2B1BA0043A0F2 /* AudioRecord.swift in Sources */, 7A488C3C24A74B990054D0B2 /* RxTableViewRealmDataSource.swift in Sources */, 7A6DD90C24335A6D009DE740 /* FlagLayer.swift in Sources */, + 7AE26A3524F31B0700625033 /* EventsController.swift in Sources */, 7AB67E8C2435C38700258F61 /* CustomTextField.swift in Sources */, 7A27ADF5249FD2F90035F39E /* FileManagerExt.swift in Sources */, 7AE26A3324EEF9EC00625033 /* UIViewControllerExt.swift in Sources */, diff --git a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 803f859..f6d5466 100644 --- a/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/AutoCat.xcodeproj/xcuserdata/selim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -63,5 +63,21 @@ landmarkType = "7"> + + + + diff --git a/AutoCat/Base.lproj/Main.storyboard b/AutoCat/Base.lproj/Main.storyboard index b175c7d..a3b725b 100644 --- a/AutoCat/Base.lproj/Main.storyboard +++ b/AutoCat/Base.lproj/Main.storyboard @@ -219,6 +219,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -232,14 +261,14 @@ - + - + - + diff --git a/AutoCat/Controllers/EventsController.swift b/AutoCat/Controllers/EventsController.swift new file mode 100644 index 0000000..784bcfc --- /dev/null +++ b/AutoCat/Controllers/EventsController.swift @@ -0,0 +1,61 @@ +import UIKit +import MapKit + +class EventPin: NSObject, MKAnnotation { + var coordinate: CLLocationCoordinate2D + var title: String? + var subtitle: String? + + init(coordinate: CLLocationCoordinate2D, title: String?, subtitle: String) { + self.coordinate = coordinate + self.title = title + self.subtitle = subtitle + } +} + +class EventsController: UIViewController { + + @IBOutlet weak var map: MKMapView! + + public var events: [VehicleEvent] = [] { + didSet { + self.pins = self.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) + } + } + } + + private var pins: [EventPin] = [] + + override func viewDidLoad() { + super.viewDidLoad() + + self.map.addAnnotations(self.pins) + self.centerMap() + } + + func centerMap() { + var minLat = 0.0, maxLat = 0.0, minLon = 0.0, maxLon = 0.0 + for event in self.events { + if event.latitude < minLat || minLat == 0 { minLat = event.latitude } + if event.latitude > maxLat || maxLat == 0 { maxLat = event.latitude } + if event.longitude < minLon || minLon == 0 { minLon = event.longitude } + if event.longitude > maxLon || maxLon == 0 { maxLon = event.longitude } + } + + let center = CLLocationCoordinate2D(latitude: (minLat + maxLat)/2, longitude: (minLon + maxLon)/2) + let leftTop = CLLocation(latitude: minLat, longitude: minLon) + let rightBottom = CLLocation(latitude: maxLat, longitude: maxLon) + let diagonal = leftTop.distance(from: rightBottom) + + let region = MKCoordinateRegion(center: center, latitudinalMeters: diagonal, longitudinalMeters: diagonal) + self.map.setRegion(region, animated: true) + } +} diff --git a/AutoCat/Controllers/ReportController.swift b/AutoCat/Controllers/ReportController.swift index ee91df9..2524521 100644 --- a/AutoCat/Controllers/ReportController.swift +++ b/AutoCat/Controllers/ReportController.swift @@ -248,12 +248,17 @@ class ReportController: UIViewController, UICollectionViewDataSource, UICollecti } if indexPath.section == ReportSection.general.rawValue { + let sb = UIStoryboard(name: "Main", bundle: nil) if indexPath.row == ReportGeneralSection.owners.rawValue { - let sb = UIStoryboard(name: "Main", bundle: nil) let controller = sb.instantiateViewController(identifier: "OwnersController") as OwnersController controller.owners = self.vehicle?.ownershipPeriods.toArray() ?? [] self.navigationController?.pushViewController(controller, animated: true) } + else if let events = self.vehicle?.events, indexPath.row == ReportGeneralSection.events.rawValue && events.count > 0 { + let controller = sb.instantiateViewController(identifier: "EventsController") as EventsController + controller.events = Array(events) + self.navigationController?.pushViewController(controller, animated: true) + } } } diff --git a/AutoCat/Utils/Constants.swift b/AutoCat/Utils/Constants.swift index 9bfd07e..800d54b 100644 --- a/AutoCat/Utils/Constants.swift +++ b/AutoCat/Utils/Constants.swift @@ -3,8 +3,9 @@ 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://127.0.0.1:3000/" + //return "http://192.168.1.67:3000/" + return "https://vps.aliencat.pro:8443/" #else return "https://vps.aliencat.pro:8443/" #endif