Fix for adding events
This commit is contained in:
parent
e63f3ed13d
commit
65629cbf90
@ -767,7 +767,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 = 37;
|
CURRENT_PROJECT_VERSION = 38;
|
||||||
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;
|
||||||
@ -789,7 +789,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 = 37;
|
CURRENT_PROJECT_VERSION = 38;
|
||||||
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;
|
||||||
|
|||||||
@ -37,7 +37,7 @@ enum EventsMode {
|
|||||||
case list
|
case list
|
||||||
}
|
}
|
||||||
|
|
||||||
class EventsController: UIViewController, UITableViewDataSource, UITableViewDelegate {
|
class EventsController: UIViewController, UITableViewDataSource, UITableViewDelegate, MKMapViewDelegate {
|
||||||
|
|
||||||
@IBOutlet weak var map: MKMapView!
|
@IBOutlet weak var map: MKMapView!
|
||||||
@IBOutlet weak var tableView: UITableView!
|
@IBOutlet weak var tableView: UITableView!
|
||||||
@ -49,10 +49,6 @@ class EventsController: UIViewController, UITableViewDataSource, UITableViewDele
|
|||||||
|
|
||||||
public var vehicle: Vehicle? {
|
public var vehicle: Vehicle? {
|
||||||
didSet {
|
didSet {
|
||||||
if let vehicle = self.vehicle {
|
|
||||||
self.pins = vehicle.events.map(EventPin.init(event:))
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.isViewLoaded {
|
if self.isViewLoaded {
|
||||||
self.updateInterface()
|
self.updateInterface()
|
||||||
}
|
}
|
||||||
@ -73,14 +69,24 @@ class EventsController: UIViewController, UITableViewDataSource, UITableViewDele
|
|||||||
self.modeButton = UIBarButtonItem(image: UIImage(systemName: "list.bullet"), style: .plain, target: self, action: #selector(switchMode(_:)))
|
self.modeButton = UIBarButtonItem(image: UIImage(systemName: "list.bullet"), style: .plain, target: self, action: #selector(switchMode(_:)))
|
||||||
self.addButton = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addEvent(_:)))
|
self.addButton = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addEvent(_:)))
|
||||||
self.navigationItem.rightBarButtonItems = [self.modeButton, self.addButton]
|
self.navigationItem.rightBarButtonItems = [self.modeButton, self.addButton]
|
||||||
|
self.map.delegate = self
|
||||||
|
|
||||||
self.updateInterface()
|
self.updateInterface()
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateInterface() {
|
func updateInterface() {
|
||||||
self.map.removeAnnotations(self.map.annotations)
|
if let vehicle = self.vehicle {
|
||||||
self.map.addAnnotations(self.pins)
|
self.pins = vehicle.events.map(EventPin.init(event:))
|
||||||
self.map.centerOnPins()
|
}
|
||||||
|
|
||||||
|
if !self.pins.isEmpty {
|
||||||
|
self.map.removeAnnotations(self.map.annotations)
|
||||||
|
self.map.addAnnotations(self.pins)
|
||||||
|
self.map.centerOnPins()
|
||||||
|
} else {
|
||||||
|
self.map.showsUserLocation = true
|
||||||
|
}
|
||||||
|
|
||||||
self.tableView.reloadData()
|
self.tableView.reloadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,8 +226,11 @@ class EventsController: UIViewController, UITableViewDataSource, UITableViewDele
|
|||||||
try realm.write {
|
try realm.write {
|
||||||
realm.add(vehicle, update: .all)
|
realm.add(vehicle, update: .all)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
self.vehicle?.events.removeAll()
|
||||||
|
self.vehicle?.events.append(objectsIn: vehicle.events)
|
||||||
}
|
}
|
||||||
self.vehicle = vehicle
|
self.updateInterface()
|
||||||
IHProgressHUD.dismiss()
|
IHProgressHUD.dismiss()
|
||||||
return true
|
return true
|
||||||
} catch {
|
} catch {
|
||||||
@ -230,4 +239,12 @@ class EventsController: UIViewController, UITableViewDataSource, UITableViewDele
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - MKMapViewDelegate
|
||||||
|
|
||||||
|
public func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) {
|
||||||
|
let region = MKCoordinateRegion(center: userLocation.coordinate, latitudinalMeters: 1000, longitudinalMeters: 1000)
|
||||||
|
self.map.setRegion(region, animated: true)
|
||||||
|
self.map.showsUserLocation = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -135,6 +135,8 @@ class ReportController: UIViewController, UICollectionViewDataSource, UICollecti
|
|||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.collection.reloadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - UICollectionViewDataSource
|
// MARK: - UICollectionViewDataSource
|
||||||
@ -276,7 +278,7 @@ class ReportController: UIViewController, UICollectionViewDataSource, UICollecti
|
|||||||
controller.owners = self.vehicle?.ownershipPeriods.toArray() ?? []
|
controller.owners = self.vehicle?.ownershipPeriods.toArray() ?? []
|
||||||
self.navigationController?.pushViewController(controller, animated: true)
|
self.navigationController?.pushViewController(controller, animated: true)
|
||||||
}
|
}
|
||||||
else if let events = self.vehicle?.events, indexPath.row == ReportGeneralSection.events.rawValue && events.count > 0 {
|
else if indexPath.row == ReportGeneralSection.events.rawValue {
|
||||||
let controller = sb.instantiateViewController(identifier: "EventsController") as EventsController
|
let controller = sb.instantiateViewController(identifier: "EventsController") as EventsController
|
||||||
controller.vehicle = self.vehicle
|
controller.vehicle = self.vehicle
|
||||||
self.navigationController?.pushViewController(controller, animated: true)
|
self.navigationController?.pushViewController(controller, animated: true)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user