Skip to content
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

Navigation Service, Part 1 #1602

Merged
merged 41 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
57ed105
WIP: Building out scaffolding for `MapboxNavigationService`
Aug 9, 2018
ef09aac
WIP: It compiles! (Completed building out scaffolding around Navigati…
Aug 13, 2018
23818fc
WIP: It's Aliiiiive! (Hooking NavigationService up to consumer, movin…
Aug 13, 2018
a9611d1
WIP: PR Comments
Aug 13, 2018
8f47670
Update all the tests!
Aug 14, 2018
099ddc4
Cleaning up after myself
Aug 15, 2018
b24c8bf
Merge branch 'master' into jerrad/146-navigation-service
Aug 15, 2018
518a89e
Decoupling EventsManager from RouteController
Aug 16, 2018
8e44849
Merge branch 'master' into jerrad/146-navigation-service
Aug 16, 2018
d169b06
WIP: Temporarily disabling TunnelIntersectionTests for refactor
Aug 21, 2018
3a80e14
Decoupling the TunnelIntersectionManager (now TunnelAuthority) from t…
Aug 21, 2018
cedabcb
Gah, forgot about the OBJ-C interface!
Aug 21, 2018
230351f
Prevent yo-yoing by only passing synthetic location updates onto the …
Aug 21, 2018
8c04240
Fix naming conventions and coding style
frederoni Aug 21, 2018
7f5aa7f
Simplified TunnelAuthority and refactor accompanying tests
frederoni Aug 21, 2018
089a39a
Completely decoupling tunnel detection from route simulation. This si…
Aug 22, 2018
9c5b70d
Fixing issue where countdown timer payload was being executed on back…
Aug 22, 2018
950cd68
Fixing issue where we were using timer.cancel() (which is permanent) …
Aug 22, 2018
d49ebdc
Fixing Tests. Gah.
Aug 22, 2018
3e8edde
PR Comments, and preliminary polish.
Aug 22, 2018
d6f8498
Merge branch 'master' into jerrad/146-navigation-service
Aug 24, 2018
8a8fc79
Adding new `NavigationServiceDelegate` type and plumbing everything t…
Aug 27, 2018
7b8ed23
Merge branch 'master' into jerrad/146-navigation-service
Aug 27, 2018
e454202
Hooking up example
Aug 27, 2018
45795e4
cleanup, random comment fix
Aug 27, 2018
a139f89
Merge branch 'master' into jerrad/146-navigation-service
Aug 29, 2018
4fc2e2a
Fixing tests.
Aug 29, 2018
297f7b4
Consolidating directions reference into a single-point-of-truth.
Aug 29, 2018
ee3cd30
Merge branch 'master' into jerrad/146-navigation-service
Sep 7, 2018
cec16b6
Fixing merge clobber
Sep 7, 2018
b5c0c03
Merge branch 'epic/nav-native' into jerrad/146-navigation-service
Sep 21, 2018
fdcb350
WIP: Trying to fix test failures
Sep 24, 2018
9c7c9f9
WIP: Fixed crash, now working on the actual failures, which is "we di…
Sep 24, 2018
2049a30
Fixed issue where wrong type of location manager was used for core na…
Sep 24, 2018
41265b1
Fixing remaining tests
Sep 26, 2018
89c73cf
Final polish -- fixing issue where speed multiplier changes weren't b…
Sep 26, 2018
2e161df
Fixing test cruft where testing type is no longer extant on stubbed e…
Sep 26, 2018
6bccfd6
Reverting removal of ostensibly redundant XCTest availability macros
Sep 26, 2018
edbb56d
Merge branch 'epic/nav-native' into jerrad/146-navigation-service
Sep 26, 2018
0994b2b
Forgot this one
Sep 26, 2018
e9a7781
Fixing some post-merge testing issues
Sep 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions Examples/Objective-C/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ @interface ViewController () <AVSpeechSynthesizerDelegate>
@property (nonatomic, assign) CLLocationCoordinate2D destination;
@property (nonatomic) MBDirections *directions;
@property (nonatomic) MBRoute *route;
@property (nonatomic) MBRouteController *navigation;
@property (nonatomic) MBNavigationService *navigation;
JThramer marked this conversation as resolved.
Show resolved Hide resolved
@property (nonatomic) NSLengthFormatter *lengthFormatter;
@property (nonatomic) AVSpeechSynthesizer *speechSynth;
@end
Expand All @@ -37,7 +37,7 @@ - (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];

[self suspendNotifications];
[self.navigation suspendLocationUpdates];
[self.navigation stop];
}

- (IBAction)didLongPress:(UILongPressGestureRecognizer *)sender {
Expand Down Expand Up @@ -121,10 +121,15 @@ -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"StartNavigation"]) {
MBNavigationViewController *controller = (MBNavigationViewController *)[segue destinationViewController];

MBSimulatedLocationManager *locationManager = [[MBSimulatedLocationManager alloc] initWithRoute:self.route];

MBEventsManager *events = [[MBEventsManager alloc] initWithAccessToken:self.route.accessToken];

controller.directions = [MBDirections sharedDirections];
controller.route = self.route;
controller.navigationService = [[MBNavigationService alloc] initWithRoute:self.route directions:controller.directions locationSource:locationManager eventsManager:events];

controller.routeController.locationManager = [[MBSimulatedLocationManager alloc] initWithRoute:self.route];

}
}

Expand Down
2 changes: 1 addition & 1 deletion MapboxCoreNavigation/RouteController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ extension RouteController: CLLocationManagerDelegate {
}
}

func reroute(from location: CLLocation, along progress: RouteProgress) {
public func reroute(from location: CLLocation, along progress: RouteProgress) {
if let lastRerouteLocation = lastRerouteLocation {
guard location.distance(from: lastRerouteLocation) >= RouteControllerMaximumDistanceBeforeRecalculating else {
return
Expand Down
2 changes: 2 additions & 0 deletions MapboxCoreNavigation/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public typealias RouterDelegate = RouteControllerDelegate
var route: Route { get set }
func endNavigation(feedback: EndOfRouteFeedback?)

@objc func userIsOnRoute(_ location: CLLocation) -> Bool
@objc func reroute(from: CLLocation, along: RouteProgress)
@objc var location: CLLocation? { get }
}
49 changes: 26 additions & 23 deletions MapboxCoreNavigationTests/MapboxCoreNavigationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ let waitForInterval: TimeInterval = 5

class MapboxCoreNavigationTests: XCTestCase {

var navigation: RouteController!
var navigation: MapboxNavigationService!

func testDepart() {
route.accessToken = "foo"
navigation = RouteController(along: route, directions: directions)
navigation = MapboxNavigationService(route: route, directions: directions)
let depart = CLLocation(coordinate: CLLocationCoordinate2D(latitude: 37.795042, longitude: -122.413165), altitude: 1, horizontalAccuracy: 1, verticalAccuracy: 1, course: 0, speed: 10, timestamp: Date())

expectation(forNotification: .routeControllerDidPassSpokenInstructionPoint, object: navigation) { (notification) -> Bool in
expectation(forNotification: .routeControllerDidPassSpokenInstructionPoint, object: navigation.router) { (notification) -> Bool in
XCTAssertEqual(notification.userInfo?.count, 1)

let routeProgress = notification.userInfo![RouteControllerNotificationUserInfoKey.routeProgressKey] as? RouteProgress

return routeProgress != nil && routeProgress?.currentLegProgress.userHasArrivedAtWaypoint == false
}

navigation.resume()
navigation.locationManager(navigation.locationManager, didUpdateLocations: [depart])
navigation.start()
navigation.locationManager(navigation.locationSource, didUpdateLocations: [depart])

waitForExpectations(timeout: waitForInterval) { (error) in
XCTAssertNil(error)
Expand All @@ -42,17 +42,17 @@ class MapboxCoreNavigationTests: XCTestCase {
route.accessToken = "foo"
let location = CLLocation(coordinate: CLLocationCoordinate2D(latitude: 37.78895, longitude: -122.42543), altitude: 1, horizontalAccuracy: 1, verticalAccuracy: 1, course: 171, speed: 10, timestamp: Date())
let locationManager = ReplayLocationManager(locations: [location, location])
navigation = RouteController(along: route, directions: directions, locationManager: locationManager)
navigation = MapboxNavigationService(route: route, directions: directions, locationSource: locationManager)

expectation(forNotification: .routeControllerDidPassSpokenInstructionPoint, object: navigation) { (notification) -> Bool in
expectation(forNotification: .routeControllerDidPassSpokenInstructionPoint, object: navigation.router) { (notification) -> Bool in
XCTAssertEqual(notification.userInfo?.count, 1)

let routeProgress = notification.userInfo![RouteControllerNotificationUserInfoKey.routeProgressKey] as? RouteProgress

return routeProgress?.currentLegProgress.stepIndex == 2
}

navigation.resume()
navigation.start()

waitForExpectations(timeout: waitForInterval) { (error) in
XCTAssertNil(error)
Expand All @@ -64,17 +64,17 @@ class MapboxCoreNavigationTests: XCTestCase {
let location = CLLocation(coordinate: CLLocationCoordinate2D(latitude: 37.77386, longitude: -122.43085), altitude: 1, horizontalAccuracy: 1, verticalAccuracy: 1, course: 171, speed: 10, timestamp: Date())

let locationManager = ReplayLocationManager(locations: [location, location])
navigation = RouteController(along: route, directions: directions, locationManager: locationManager)
navigation = MapboxNavigationService(route: route, directions: directions, locationSource: locationManager)

expectation(forNotification: .routeControllerDidPassSpokenInstructionPoint, object: navigation) { (notification) -> Bool in
expectation(forNotification: .routeControllerDidPassSpokenInstructionPoint, object: navigation.router) { (notification) -> Bool in
XCTAssertEqual(notification.userInfo?.count, 1)

let routeProgress = notification.userInfo![RouteControllerNotificationUserInfoKey.routeProgressKey] as? RouteProgress

return routeProgress?.currentLegProgress.stepIndex == 6
}

navigation.resume()
navigation.start()

waitForExpectations(timeout: waitForInterval) { (error) in
XCTAssertNil(error)
Expand All @@ -92,16 +92,16 @@ class MapboxCoreNavigationTests: XCTestCase {
timestamp: Date(timeIntervalSinceNow: 1))

let locationManager = ReplayLocationManager(locations: [firstLocation, secondLocation])
navigation = RouteController(along: route, directions: directions, locationManager: locationManager)
navigation = MapboxNavigationService(route: route, directions: directions, locationSource: locationManager)

expectation(forNotification: .routeControllerWillReroute, object: navigation) { (notification) -> Bool in
expectation(forNotification: .routeControllerWillReroute, object: navigation.router) { (notification) -> Bool in
XCTAssertEqual(notification.userInfo?.count, 1)

let location = notification.userInfo![RouteControllerNotificationUserInfoKey.locationKey] as? CLLocation
return location?.coordinate == secondLocation.coordinate
}

navigation.resume()
navigation.start()

waitForExpectations(timeout: waitForInterval) { (error) in
XCTAssertNil(error)
Expand All @@ -114,14 +114,14 @@ class MapboxCoreNavigationTests: XCTestCase {
let locationManager = ReplayLocationManager(locations: locations)
locationManager.speedMultiplier = 20

navigation = RouteController(along: route, directions: directions, locationManager: locationManager)
navigation = MapboxNavigationService(route: route, directions: directions, locationSource: locationManager)

expectation(forNotification: .routeControllerProgressDidChange, object: navigation) { (notification) -> Bool in
expectation(forNotification: .routeControllerProgressDidChange, object: navigation.router) { (notification) -> Bool in
let routeProgress = notification.userInfo![RouteControllerNotificationUserInfoKey.routeProgressKey] as? RouteProgress
return routeProgress != nil
}

navigation.resume()
navigation.start()

let timeout = locations.last!.timestamp.timeIntervalSince(locations.first!.timestamp) / locationManager.speedMultiplier
waitForExpectations(timeout: timeout + 2) { (error) in
Expand All @@ -130,20 +130,23 @@ class MapboxCoreNavigationTests: XCTestCase {
}

func testFailToReroute() {
enum TestError: Error {
case test
}
route.accessToken = "foo"
let directionsClientSpy = DirectionsSpy(accessToken: "garbage", host: nil)
navigation = RouteController(along: route, directions: directionsClientSpy)
navigation = MapboxNavigationService(route: route, directions: directionsClientSpy)

expectation(forNotification: .routeControllerWillReroute, object: navigation) { (notification) -> Bool in
expectation(forNotification: .routeControllerWillReroute, object: navigation.router) { (notification) -> Bool in
return true
}

expectation(forNotification: .routeControllerDidFailToReroute, object: navigation) { (notification) -> Bool in
expectation(forNotification: .routeControllerDidFailToReroute, object: navigation.router) { (notification) -> Bool in
return true
}

navigation.reroute(from: CLLocation(latitude: 0, longitude: 0), along: navigation.routeProgress)
directionsClientSpy.fireLastCalculateCompletion(with: nil, routes: nil, error: NSError())
let routeController = navigation.router as! RouteController
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If reroute(from:along) stays public, this forced-cast is unnecessary.

routeController.reroute(from: CLLocation(latitude: 0, longitude: 0), along: navigation.router.routeProgress)
directionsClientSpy.fireLastCalculateCompletion(with: nil, routes: nil, error: TestError.test as NSError)

waitForExpectations(timeout: 2) { (error) in
XCTAssertNil(error)
Expand Down