From f3a0ed2051279a4c9c11f3339e03674f104755b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 15 Mar 2018 18:25:36 -0700 Subject: [PATCH] Reroute proactively, not opportunistically --- CHANGELOG.md | 5 ++++- MapboxCoreNavigation/Constants.swift | 2 +- MapboxCoreNavigation/MBRouteController.h | 6 +++--- MapboxCoreNavigation/MBRouteController.m | 2 +- MapboxCoreNavigation/RouteController.swift | 16 ++++++++-------- MapboxNavigation/RouteMapViewController.swift | 2 +- MapboxNavigation/RouteVoiceController.swift | 2 +- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f901bd97d..37c7be6117 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,13 @@ ## Master -#### User Interface +#### User interface * Added support for abbreviated top banner instructions. [#1169](https://github.com/mapbox/mapbox-navigation-ios/pull/1169) * Reveal the steps list by swiping down on the top banner. [#1150](https://github.com/mapbox/mapbox-navigation-ios/pull/1150) +#### Core Navigation +* Renamed the `RouteController.reroutesOpportunistically` property to `RouteController.reroutesProactively`, `RouteControllerOpportunisticReroutingInterval` global variable to `RouteControllerProactiveReroutingInterval`, and the `RouteControllerNotificationUserInfoKey.isOpportunisticKey` value to `RouteControllerNotificationUserInfoKey.isProactiveKey`. ([#1230](https://github.com/mapbox/mapbox-navigation-ios/pull/1230)) + ## v0.15.0 (March 13, 2018) #### Breaking changes diff --git a/MapboxCoreNavigation/Constants.swift b/MapboxCoreNavigation/Constants.swift index 7dfcc54482..fc4ae30264 100644 --- a/MapboxCoreNavigation/Constants.swift +++ b/MapboxCoreNavigation/Constants.swift @@ -78,7 +78,7 @@ public var RouteControllerNumberOfSecondsForRerouteFeedback: TimeInterval = 10 /** The number of seconds between attempts to automatically calculate a more optimal route while traveling. */ -public var RouteControllerOpportunisticReroutingInterval: TimeInterval = 120 +public var RouteControllerProactiveReroutingInterval: TimeInterval = 120 let FasterRouteFoundEvent = "navigation.fasterRoute" diff --git a/MapboxCoreNavigation/MBRouteController.h b/MapboxCoreNavigation/MBRouteController.h index c17a533448..157107f825 100644 --- a/MapboxCoreNavigation/MBRouteController.h +++ b/MapboxCoreNavigation/MBRouteController.h @@ -21,7 +21,7 @@ extern const NSNotificationName MBRouteControllerWillRerouteNotification; /** Posted when `MBRouteController` obtains a new route in response to the user diverging from a previous route. - The user info dictionary contains the keys `MBRouteControllerLocationKey` and `MBRouteControllerIsOpportunisticKey`. + The user info dictionary contains the keys `MBRouteControllerLocationKey` and `MBRouteControllerIsProactiveKey`. :nodoc: */ @@ -73,6 +73,6 @@ extern const MBRouteControllerNotificationUserInfoKey MBRouteControllerRawLocati extern const MBRouteControllerNotificationUserInfoKey MBRouteControllerRoutingErrorKey; /** - A key in the user info dictionary of a `Notification.Name.RouteControllerDidReroute` notification. The corresponding value is an `NSNumber` instance containing a Boolean value indicating whether `RouteController` opportunistically rerouted the user onto a faster route. + A key in the user info dictionary of a `Notification.Name.RouteControllerDidReroute` notification. The corresponding value is an `NSNumber` instance containing a Boolean value indicating whether `RouteController` proactively rerouted the user onto a faster route. */ -extern const MBRouteControllerNotificationUserInfoKey MBRouteControllerIsOpportunisticKey; +extern const MBRouteControllerNotificationUserInfoKey MBRouteControllerIsProactiveKey; diff --git a/MapboxCoreNavigation/MBRouteController.m b/MapboxCoreNavigation/MBRouteController.m index f298c56bb4..5b2658c78c 100644 --- a/MapboxCoreNavigation/MBRouteController.m +++ b/MapboxCoreNavigation/MBRouteController.m @@ -10,6 +10,6 @@ const MBRouteControllerNotificationUserInfoKey MBRouteControllerLocationKey = @"location"; const MBRouteControllerNotificationUserInfoKey MBRouteControllerRawLocationKey = @"rawLocation"; const MBRouteControllerNotificationUserInfoKey MBRouteControllerRoutingErrorKey = @"error"; -const MBRouteControllerNotificationUserInfoKey MBRouteControllerIsOpportunisticKey = @"RouteControllerDidFindFasterRoute"; +const MBRouteControllerNotificationUserInfoKey MBRouteControllerIsProactiveKey = @"RouteControllerDidFindFasterRoute"; NSString *const MBErrorDomain = @"ErrorDomain"; diff --git a/MapboxCoreNavigation/RouteController.swift b/MapboxCoreNavigation/RouteController.swift index 505d5ceceb..318be4f18f 100644 --- a/MapboxCoreNavigation/RouteController.swift +++ b/MapboxCoreNavigation/RouteController.swift @@ -29,7 +29,7 @@ extension Notification.Name { /** Posted when `RouteController` obtains a new route in response to the user diverging from a previous route. - The user info dictionary contains the keys `RouteControllerNotificationUserInfoKey.locationKey` and `RouteControllerNotificationUserInfoKey.isOpportunisticKey`. + The user info dictionary contains the keys `RouteControllerNotificationUserInfoKey.locationKey` and `RouteControllerNotificationUserInfoKey.isProactiveKey`. */ public static let routeControllerDidReroute = MBRouteControllerDidReroute @@ -172,9 +172,9 @@ open class RouteController: NSObject { @objc public var isDeadReckoningEnabled = false /** - If true, the `RouteController` attempts to calculate a more optimal route for the user on an interval defined by `RouteControllerOpportunisticReroutingInterval`. + If true, the `RouteController` attempts to calculate a more optimal route for the user on an interval defined by `RouteControllerProactiveReroutingInterval`. */ - @objc public var reroutesOpportunistically = false + @objc public var reroutesProactively = false var didFindFasterRoute = false @@ -198,7 +198,7 @@ open class RouteController: NSObject { if let location = locationManager.location { userInfo[.locationKey] = location } - userInfo[.isOpportunisticKey] = didFindFasterRoute + userInfo[.isProactiveKey] = didFindFasterRoute NotificationCenter.default.post(name: .routeControllerDidReroute, object: self, userInfo: userInfo) } } @@ -465,7 +465,7 @@ extension RouteController { } @objc func didReroute(notification: NSNotification) { - if let didFindFasterRoute = notification.userInfo?[RouteControllerNotificationUserInfoKey.isOpportunisticKey] as? Bool, didFindFasterRoute { + if let didFindFasterRoute = notification.userInfo?[RouteControllerNotificationUserInfoKey.isProactiveKey] as? Bool, didFindFasterRoute { _ = enqueueFoundFasterRouteEvent() } @@ -575,7 +575,7 @@ extension RouteController: CLLocationManagerDelegate { updateSpokenInstructionProgress(for: location) // Check for faster route given users current location - guard reroutesOpportunistically else { return } + guard reroutesProactively else { return } // Only check for faster alternatives if the user has plenty of time left on the route. guard routeProgress.durationRemaining > 600 else { return } // If the user is approaching a maneuver, don't check for a faster alternatives @@ -663,7 +663,7 @@ extension RouteController: CLLocationManagerDelegate { } // Only check every so often for a faster route. - guard location.timestamp.timeIntervalSince(lastLocationDate) >= RouteControllerOpportunisticReroutingInterval else { return } + guard location.timestamp.timeIntervalSince(lastLocationDate) >= RouteControllerProactiveReroutingInterval else { return } let durationRemaining = routeProgress.durationRemaining getDirections(from: location) { [weak self] (route, error) in @@ -680,7 +680,7 @@ extension RouteController: CLLocationManagerDelegate { strongSelf.routeProgress = RouteProgress(route: route, legIndex: 0, spokenInstructionIndex: strongSelf.routeProgress.currentLegProgress.currentStepProgress.spokenInstructionIndex) strongSelf.delegate?.routeController?(strongSelf, didRerouteAlong: route) strongSelf.didReroute(notification: NSNotification(name: .routeControllerDidReroute, object: nil, userInfo: [ - RouteControllerNotificationUserInfoKey.isOpportunisticKey: true + RouteControllerNotificationUserInfoKey.isProactiveKey: true ])) strongSelf.didFindFasterRoute = false } diff --git a/MapboxNavigation/RouteMapViewController.swift b/MapboxNavigation/RouteMapViewController.swift index 7b9d7a1341..e184d0f71c 100644 --- a/MapboxNavigation/RouteMapViewController.swift +++ b/MapboxNavigation/RouteMapViewController.swift @@ -324,7 +324,7 @@ class RouteMapViewController: UIViewController { } } - if notification.userInfo![RouteControllerNotificationUserInfoKey.isOpportunisticKey] as! Bool { + if notification.userInfo![RouteControllerNotificationUserInfoKey.isProactiveKey] as! Bool { let title = NSLocalizedString("FASTER_ROUTE_FOUND", bundle: .mapboxNavigation, value: "Faster Route Found", comment: "Indicates a faster route was found") showStatus(title: title, withSpinner: true, for: 3) } diff --git a/MapboxNavigation/RouteVoiceController.swift b/MapboxNavigation/RouteVoiceController.swift index f58c6ea9be..fd1715db8b 100644 --- a/MapboxNavigation/RouteVoiceController.swift +++ b/MapboxNavigation/RouteVoiceController.swift @@ -151,7 +151,7 @@ open class RouteVoiceController: NSObject, AVSpeechSynthesizerDelegate, AVAudioP @objc func didReroute(notification: NSNotification) { // Play reroute sound when a faster route is found - if notification.userInfo?[RouteControllerNotificationUserInfoKey.isOpportunisticKey] as! Bool { + if notification.userInfo?[RouteControllerNotificationUserInfoKey.isProactiveKey] as! Bool { pauseSpeechAndPlayReroutingDing(notification: notification) } }