-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor for testability #282
Conversation
81b4c3d
to
2f4df4d
Compare
89973de
to
d5e8261
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good so far.
Examples/Swift/ViewController.swift
Outdated
@@ -52,6 +52,18 @@ class ViewController: UIViewController, MGLMapViewDelegate, NavigationViewContro | |||
getRoute() | |||
} | |||
|
|||
@IBAction func didTapReplay(_ sender: Any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An action is usually named something more active, like replay(_:)
.
} | ||
|
||
if Bundle.main.backgroundModeLocationSupported { | ||
activityType = .automotiveNavigation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the activity type always be automotiveNavigation
, even when the user is getting walking directions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extended RouteOptions
to convert from MBDirectionsProfileIdentifier
to CLActivityType
.
also derive from regular location updates from a `CLLocationManager`. | ||
|
||
- parameter routeController: The route controller that received the new locations. | ||
- parameter locations: The locations that were received from on of the location managers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: /on/one/
public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { | ||
guard let location = locations.last else { | ||
return | ||
} | ||
|
||
delegate?.routeController!(self, didUpdateLocations: [location]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should routeController(_:didUpdateLocations:)
be optional if we require its existence here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be optional
4d6c2ae
to
88b80ec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frederoni this looks awesome, the ReplayLocationManager is going to be especially useful.
Examples/Swift/ViewController.swift
Outdated
navigationViewController.voiceController?.volume = 0.5 | ||
navigationViewController.navigationDelegate = self | ||
|
||
if let locationManager = locationManager { | ||
navigationViewController.routeController.locationManager = locationManager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice if locationManager
was a nullable property and you could set this to nil
for the default location manager.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if Swift have something like Obj-C’s null_resettable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes: CLLocationManager!
with a custom getter or setter that handles nil
.
Examples/Swift/ViewController.swift
Outdated
@@ -143,11 +156,15 @@ class ViewController: UIViewController, MGLMapViewDelegate, NavigationViewContro | |||
// You can get a token here: http://docs.aws.amazon.com/mobile/sdkforios/developerguide/cognito-auth-aws-identity-for-ios.html | |||
//navigationViewController.voiceController?.identityPoolId = "<#Your AWS IdentityPoolId. Remove Argument if you do not want to use AWS Polly#>" | |||
|
|||
navigationViewController.simulatesLocationUpdates = simulatesLocationUpdates | |||
navigationViewController.routeController.snapsUserLocationAnnotationToRoute = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make snapsUserLocationAnnotationToRoute=true
by default
@@ -165,15 +166,6 @@ public class NavigationViewController: NavigationPulleyViewController, RouteMapV | |||
public var routeController: RouteController! | |||
|
|||
/** | |||
`simulate` provides simulated location updates along the given route. | |||
*/ | |||
public var simulatesLocationUpdates: Bool = false { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we keep this bool for simplicity in the Navigation UI and have the didSet function optionally set the SimulatedLocationManager?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't do the same for ReplayLocationManager, so for consistency, I'd prefer not to expose this shortcut.
} | ||
|
||
mapView.locationManager.stopUpdatingLocation() | ||
mapView.locationManager.stopUpdatingHeading() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should move to viewWillAppear
to fix animation issues. More here: #303
8e8463b
to
9eab5b7
Compare
@@ -307,9 +368,6 @@ extension RouteController: CLLocationManagerDelegate { | |||
strongSelf.routeProgress = RouteProgress(route: route) | |||
strongSelf.routeProgress.currentLegProgress.stepIndex = 0 | |||
strongSelf.delegate?.routeController?(strongSelf, didRerouteAlong: route) | |||
NotificationCenter.default.post(name: RouteControllerDidReroute, object: self, userInfo: [ | |||
MBRouteControllerNotificationRouteKey: location |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this to routeProgress didSet and changed RouteKey
to LocationKey
f7fcaa8
to
860d3bf
Compare
|
|
||
self.expectation(forNotification: RouteControllerAlertLevelDidChange.rawValue, object: navigation) { (notification) -> Bool in | ||
XCTAssertEqual(notification.userInfo?.count, 2) | ||
|
||
let routeProgress = notification.userInfo![RouteControllerAlertLevelDidChangeNotificationRouteProgressKey] as? RouteProgress | ||
let userDistance = notification.userInfo![RouteControllerAlertLevelDidChangeNotificationDistanceToEndOfManeuverKey] as! CLLocationDistance | ||
|
||
return routeProgress?.currentLegProgress.alertUserLevel == .low && routeProgress?.currentLegProgress.stepIndex == 2 && round(userDistance) == 1758 | ||
return routeProgress?.currentLegProgress.alertUserLevel == .low && routeProgress?.currentLegProgress.stepIndex == 2 && round(userDistance) == 1786 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. Do you think it could be a race condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting 1786 on master (2c6ec67) 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
860d3bf
to
a0a59c2
Compare
a0a59c2
to
aaddd94
Compare
This PR adds a few location managers that can be set on the
RouteController
NavigationLocationManager
: This is the base location manager that handles permission and background mode. All other location managers inherits from this location manager.DefaultLocationManager
: This location manager resides in the UI part of the framework because it needs access to UIKit to determine battery state and set the desired accuracy accordingly.ReplayLocationManager
: Replays a list of locations.SimulatedLocationManager
: Replaces SimulatedRoute.RouteController
now also supports simple dead reckoning using any of the location managers. However,isDeadReckoningEnabled
defaults tofalse
.NavigationMapView
now receives location updates from the location manager associated with theRouteController
through the newRouteControllerDelegate.routeController(_:didUpdateLocations:)
.Refactor monitorStepProgressWrite tests using ReplayLocationManagerThe gist of how to use these location managers:
SimulatedLocationManager
- Simulates location updates along a routeReplayLocationManager
- Replays a list of locations previously recorded to a file.