Skip to content

Commit

Permalink
remove alert
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobby Sudekum committed Oct 18, 2017
1 parent 2bcb0a9 commit 5b51716
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 65 deletions.
4 changes: 2 additions & 2 deletions Examples/Swift/CustomViewController.swift
Expand Up @@ -74,9 +74,9 @@ class CustomViewController: UIViewController, MGLMapViewDelegate, AVSpeechSynthe
addRouteToMap()
}

// When the alert level changes, this signals the user is ready for a voice announcement
// When an instruction should be given
func shouldSpeak(_ notification: NSNotification) {
let routeProgress = notification.userInfo![RouteControllerAlertLevelDidChangeNotificationRouteProgressKey] as! RouteProgress
let routeProgress = notification.userInfo![MBRouteControllerDidPassSpokenInstructionPointRouteProgressKey] as! RouteProgress

guard let text = routeProgress.currentLegProgress.currentStepProgress.currentSpokenInstruction?.text else { return }

Expand Down
21 changes: 8 additions & 13 deletions MapboxCoreNavigation/Constants.swift
Expand Up @@ -17,11 +17,6 @@ public let RouteControllerProgressDidChangeNotificationLocationKey = MBRouteCont
*/
public let RouteControllerProgressDidChangeNotificationSecondsRemainingOnStepKey = MBRouteControllerProgressDidChangeNotificationSecondsRemainingOnStepKey

/**
Key used for accessing the `RouteProgress` object from a `RouteControllerAlertLevelDidChange` notification's `userInfo` dictionary.
*/
public let RouteControllerAlertLevelDidChangeNotificationRouteProgressKey = MBRouteControllerAlertLevelDidChangeNotificationRouteProgressKey

/**
Key used for accessing the user's current `CLLocation` from a `RouteControllerWillReroute` notification's `userInfo` dictionary.
*/
Expand All @@ -48,10 +43,15 @@ public let RouteControllerDidFindFasterRouteKey = MBRouteControllerDidFindFaster
public let RouteControllerProgressDidChange = Notification.Name(MBRouteControllerNotificationProgressDidChange)

/**
Emitted when the alert level changes. This indicates the user should be notified about the upcoming maneuver.
Emitted when the user passing an instruction location location.
*/
public let RouteControllerDidPassSpokenInstructionPoint = Notification.Name(MBRouteControllerDidPassSpokenInstructionPoint)

/**
Key for accessing the `RouteProgress` key emitted when `RouteControllerDidPassSpokenInstructionPoint` is fired.
*/
public let RouteControllerDidPassSpokenInstructionPointRouteProgressKey = MBRouteControllerDidPassSpokenInstructionPointRouteProgressKey

/**
Emitted when the user has gone off-route and the `RouteController` is about to reroute.
*/
Expand Down Expand Up @@ -100,14 +100,9 @@ public var RouteControllerHighAlertInterval: TimeInterval = 15
public var RouteControllerManeuverZoneRadius: CLLocationDistance = 40

/**
Remaing distance on a motorway at which the `AlertLevel.high` `AlertLevel` will be given. This overrides `RouteControllerHighAlertInterval` only when the current step is a motorway. Default value is a half mile.
*/
public var RouteControllerMotorwayHighAlertDistance: CLLocationDistance = 0.25 * milesToMeters

/**
Remaing distance on a motorway at which the `AlertLevel.medium` `AlertLevel` will be given. This overrides `RouteControllerMediumAlertInterval` only when the current step is a motorway. Defauly value is 2 miles.
Maximum number of seconds the user can travel away from the start of the route before rerouting occurs
*/
public var RouteControllerMotorwayMediumAlertDistance: CLLocationDistance = 2 * milesToMeters
public var MaxSecondsSpentTravelingAwayFromStartOfRoute: TimeInterval = 3

/**
When calculating whether or not the user is on the route, we look where the user will be given their speed and this variable.
Expand Down
5 changes: 2 additions & 3 deletions MapboxCoreNavigation/MBRouteController.h
Expand Up @@ -5,15 +5,14 @@ extern NSString *const MBRouteControllerProgressDidChangeNotificationProgressKey
extern NSString *const MBRouteControllerProgressDidChangeNotificationLocationKey;
extern NSString *const MBRouteControllerProgressDidChangeNotificationSecondsRemainingOnStepKey;

extern NSString *const MBRouteControllerAlertLevelDidChangeNotificationRouteProgressKey;
extern NSString *const MBRouteControllerAlertLevelDidChangeNotificationDistanceToEndOfManeuverKey;
extern NSString *const MBRouteControllerDidPassSpokenInstructionPointRouteProgressKey;
extern NSString *const MBRouteControllerDidPassSpokenInstructionPoint;

extern NSString *const MBRouteControllerNotificationLocationKey;
extern NSString *const MBRouteControllerNotificationRouteKey;
extern NSString *const MBRouteControllerNotificationErrorKey;

extern NSString *const MBRouteControllerNotificationProgressDidChange;
extern NSString *const MBRouteControllerDidPassSpokenInstructionPoint;
extern NSString *const MBRouteControllerWillReroute;
extern NSString *const MBRouteControllerDidReroute;
extern NSString *const MBRouteControllerDidFailToReroute;
Expand Down
3 changes: 1 addition & 2 deletions MapboxCoreNavigation/MBRouteController.m
Expand Up @@ -5,8 +5,7 @@
NSString *const MBRouteControllerProgressDidChangeNotificationLocationKey = @"location";
NSString *const MBRouteControllerProgressDidChangeNotificationSecondsRemainingOnStepKey = @"seconds";

NSString *const MBRouteControllerAlertLevelDidChangeNotificationRouteProgressKey = @"progress";
NSString *const MBRouteControllerAlertLevelDidChangeNotificationDistanceToEndOfManeuverKey = @"distance";
NSString *const MBRouteControllerDidPassSpokenInstructionPointRouteProgressKey = @"progress";

NSString *const MBRouteControllerNotificationLocationKey = @"location";
NSString *const MBRouteControllerNotificationRouteKey = @"route";
Expand Down
6 changes: 3 additions & 3 deletions MapboxCoreNavigation/RouteController.swift
Expand Up @@ -235,7 +235,7 @@ open class RouteController: NSObject {

func resumeNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(notification:)), name: RouteControllerProgressDidChange, object: self)
NotificationCenter.default.addObserver(self, selector: #selector(alertLevelDidChange(notification:)), name: RouteControllerDidPassSpokenInstructionPoint, object: self)
NotificationCenter.default.addObserver(self, selector: #selector(didPassSpokenInstructionPoint(notification:)), name: RouteControllerDidPassSpokenInstructionPoint, object: self)
NotificationCenter.default.addObserver(self, selector: #selector(willReroute(notification:)), name: RouteControllerWillReroute, object: self)
NotificationCenter.default.addObserver(self, selector: #selector(didReroute(notification:)), name: RouteControllerDidReroute, object: self)
}
Expand Down Expand Up @@ -391,7 +391,7 @@ extension RouteController {
checkAndSendOutstandingFeedbackEvents(forceAll: false)
}

func alertLevelDidChange(notification: NSNotification) {
func didPassSpokenInstructionPoint(notification: NSNotification) {
if routeProgress.currentLegProgress.userHasArrivedAtWaypoint && sessionState.arrivalTimestamp == nil {
sessionState.arrivalTimestamp = Date()
sendArriveEvent()
Expand Down Expand Up @@ -736,7 +736,7 @@ extension RouteController: CLLocationManagerDelegate {
if userSnapToStepDistanceFromManeuver <= voiceInstruction.distanceAlongStep && voiceInstructionIndex >= routeProgress.currentLegProgress.currentStepProgress.voiceInstructionIndex {

NotificationCenter.default.post(name: RouteControllerDidPassSpokenInstructionPoint, object: self, userInfo: [
RouteControllerAlertLevelDidChangeNotificationRouteProgressKey: routeProgress
MBRouteControllerDidPassSpokenInstructionPointRouteProgressKey: routeProgress
])

routeProgress.currentLegProgress.currentStepProgress.voiceInstructionIndex += 1
Expand Down
2 changes: 0 additions & 2 deletions MapboxCoreNavigation/RouteProgress.swift
Expand Up @@ -96,7 +96,6 @@ open class RouteProgress: NSObject {
- parameter route: The route to follow.
- parameter legIndex: Zero-based index indicating the current leg the user is on.
- parameter alertLevel: Optional `AlertLevel` to start the `RouteProgress` at.
*/
public init(route: Route, legIndex: Int = 0) {
self.route = route
Expand Down Expand Up @@ -281,7 +280,6 @@ open class RouteLegProgress: NSObject {
- parameter leg: Leg on a `Route`.
- parameter stepIndex: Current step the user is on.
- parameter alertLevel: Optional `AlertLevel` to start the `RouteProgress` at.
*/
public init(leg: RouteLeg, stepIndex: Int = 0) {
self.leg = leg
Expand Down
2 changes: 1 addition & 1 deletion MapboxCoreNavigation/SimulatedLocationManager.swift
Expand Up @@ -78,7 +78,7 @@ public class SimulatedLocationManager: NavigationLocationManager {
}

@objc private func progressDidChange(_ notification: Notification) {
routeProgress = notification.userInfo![RouteControllerAlertLevelDidChangeNotificationRouteProgressKey] as? RouteProgress
routeProgress = notification.userInfo![MBRouteControllerDidPassSpokenInstructionPointRouteProgressKey] as? RouteProgress
}

@objc private func didReroute(_ notification: Notification) {
Expand Down
22 changes: 8 additions & 14 deletions MapboxCoreNavigationTests/MapboxCoreNavigationTests.swift
Expand Up @@ -21,13 +21,12 @@ class MapboxCoreNavigationTests: XCTestCase {
navigation.resume()
let depart = CLLocation(coordinate: CLLocationCoordinate2D(latitude: 37.795042, longitude: -122.413165), altitude: 1, horizontalAccuracy: 1, verticalAccuracy: 1, course: 0, speed: 10, timestamp: Date())

self.expectation(forNotification: RouteControllerAlertLevelDidChange.rawValue, object: navigation) { (notification) -> Bool in
self.expectation(forNotification: RouteControllerDidPassSpokenInstructionPoint.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
let routeProgress = notification.userInfo![RouteControllerDidPassSpokenInstructionPointRouteProgressKey] as? RouteProgress

return routeProgress != nil && routeProgress?.currentLegProgress.alertUserLevel == .depart && round(userDistance) == 384
return routeProgress != nil
}

navigation.locationManager(navigation.locationManager, didUpdateLocations: [depart])
Expand All @@ -44,13 +43,12 @@ class MapboxCoreNavigationTests: XCTestCase {
let locationManager = ReplayLocationManager(locations: locations)
let navigation = RouteController(along: route, directions: directions, locationManager: locationManager)

self.expectation(forNotification: RouteControllerAlertLevelDidChange.rawValue, object: navigation) { (notification) -> Bool in
self.expectation(forNotification: RouteControllerDidPassSpokenInstructionPoint.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
let routeProgress = notification.userInfo![RouteControllerDidPassSpokenInstructionPointRouteProgressKey] as? RouteProgress

return routeProgress?.currentLegProgress.alertUserLevel == .low && routeProgress?.currentLegProgress.stepIndex == 2 && round(userDistance) == 1786
return routeProgress?.currentLegProgress.stepIndex == 2
}

navigation.resume()
Expand Down Expand Up @@ -102,12 +100,8 @@ class MapboxCoreNavigationTests: XCTestCase {
let navigation = RouteController(along: route, directions: directions, locationManager: locationManager)

self.expectation(forNotification: RouteControllerProgressDidChange.rawValue, object: navigation) { (notification) -> Bool in
let routeProgress = notification.userInfo![RouteControllerAlertLevelDidChangeNotificationRouteProgressKey] as? RouteProgress
guard let alertLevel = routeProgress?.currentLegProgress.alertUserLevel else {
return false
}

return alertLevel == .arrive
let routeProgress = notification.userInfo![RouteControllerDidPassSpokenInstructionPointRouteProgressKey] as? RouteProgress
return routeProgress != nil
}

navigation.resume()
Expand Down
10 changes: 0 additions & 10 deletions MapboxCoreNavigationTests/RouteProgressTests.swift
Expand Up @@ -4,15 +4,6 @@ import MapboxDirections
@testable import MapboxCoreNavigation

class RouteProgressTests: XCTestCase {
func testAlertLevels() {
XCTAssertNotNil(AlertLevel.none)
XCTAssertNotNil(AlertLevel.depart)
XCTAssertNotNil(AlertLevel.low)
XCTAssertNotNil(AlertLevel.medium)
XCTAssertNotNil(AlertLevel.high)
XCTAssertNotNil(AlertLevel.arrive)
}

func testRouteProgress() {
let routeProgress = RouteProgress(route: route)
XCTAssertEqual(routeProgress.fractionTraveled, 0)
Expand All @@ -24,7 +15,6 @@ class RouteProgressTests: XCTestCase {
func testRouteLegProgress() {
let routeProgress = RouteProgress(route: route)
XCTAssertEqual(routeProgress.currentLeg.description, "California Street, Webster Street")
XCTAssertEqual(routeProgress.currentLegProgress.alertUserLevel, .none)
XCTAssertEqual(routeProgress.currentLegProgress.distanceTraveled, 0)
XCTAssertEqual(round(routeProgress.currentLegProgress.durationRemaining), 790)
XCTAssertEqual(routeProgress.currentLegProgress.fractionTraveled, 0)
Expand Down
12 changes: 6 additions & 6 deletions MapboxNavigation/NavigationViewController.swift
Expand Up @@ -418,7 +418,7 @@ public class NavigationViewController: NavigationPulleyViewController, RouteMapV

func resumeNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(notification:)), name: RouteControllerProgressDidChange, object: routeController)
NotificationCenter.default.addObserver(self, selector: #selector(alertLevelDidChange(notification:)), name: RouteControllerDidPassSpokenInstructionPoint, object: routeController)
NotificationCenter.default.addObserver(self, selector: #selector(didPassInstructionPoint(notification:)), name: RouteControllerDidPassSpokenInstructionPoint, object: routeController)
}

func suspendNotifications() {
Expand All @@ -429,7 +429,7 @@ public class NavigationViewController: NavigationPulleyViewController, RouteMapV
func progressDidChange(notification: NSNotification) {
resetETATimer()

let routeProgress = notification.userInfo![RouteControllerAlertLevelDidChangeNotificationRouteProgressKey] as! RouteProgress
let routeProgress = notification.userInfo![MBRouteControllerDidPassSpokenInstructionPointRouteProgressKey] as! RouteProgress
let location = notification.userInfo![RouteControllerProgressDidChangeNotificationLocationKey] as! CLLocation
let secondsRemaining = notification.userInfo![RouteControllerProgressDidChangeNotificationSecondsRemainingOnStepKey] as! TimeInterval

Expand All @@ -438,11 +438,11 @@ public class NavigationViewController: NavigationPulleyViewController, RouteMapV
progressBar.progress = routeProgress.currentLegProgress.userHasArrivedAtWaypoint ? 1 : CGFloat(routeProgress.fractionTraveled)
}

func alertLevelDidChange(notification: NSNotification) {
let routeProgress = notification.userInfo![RouteControllerAlertLevelDidChangeNotificationRouteProgressKey] as! RouteProgress
func didPassInstructionPoint(notification: NSNotification) {
let routeProgress = notification.userInfo![MBRouteControllerDidPassSpokenInstructionPointRouteProgressKey] as! RouteProgress

mapViewController?.notifyAlertLevelDidChange(routeProgress: routeProgress)
tableViewController?.notifyAlertLevelDidChange()
mapViewController?.shouldGiveVoiceInstruction(routeProgress: routeProgress)
tableViewController?.shouldGiveVoiceInstruction()

// Any time the alert level changes, clear out previous notifications.
// When we give a high alert notification, we want to clear out this notification when completing that step.
Expand Down
4 changes: 2 additions & 2 deletions MapboxNavigation/PollyVoiceController.swift
Expand Up @@ -49,10 +49,10 @@ public class PollyVoiceController: RouteVoiceController {
super.init()
}

public override func alertLevelDidChange(notification: NSNotification) {
public override func didPassSpokenInstructionPoint(notification: NSNotification) {
guard shouldSpeak(for: notification) == true else { return }

let routeProgresss = notification.userInfo![RouteControllerAlertLevelDidChangeNotificationRouteProgressKey] as! RouteProgress
let routeProgresss = notification.userInfo![MBRouteControllerDidPassSpokenInstructionPointRouteProgressKey] as! RouteProgress
guard let instruction = routeProgresss.currentLegProgress.currentStepProgress.currentSpokenInstruction?.ssmlText else { return }

pollyTask?.cancel()
Expand Down
2 changes: 1 addition & 1 deletion MapboxNavigation/RouteMapViewController.swift
Expand Up @@ -252,7 +252,7 @@ class RouteMapViewController: UIViewController {
}
}

func notifyAlertLevelDidChange(routeProgress: RouteProgress) {
func shouldGiveVoiceInstruction(routeProgress: RouteProgress) {
if routeProgress.currentLegProgress.followOnStep != nil {
mapView.addArrow(route: routeController.routeProgress.route, legIndex: routeController.routeProgress.legIndex, stepIndex: routeController.routeProgress.currentLegProgress.stepIndex + 1)
} else {
Expand Down
2 changes: 1 addition & 1 deletion MapboxNavigation/RouteTableViewController.swift
Expand Up @@ -85,7 +85,7 @@ class RouteTableViewController: UIViewController {
}
}

func notifyAlertLevelDidChange() {
func shouldGiveVoiceInstruction() {
if let visibleIndexPaths = tableView.indexPathsForVisibleRows {
tableView.reloadRows(at: visibleIndexPaths, with: .fade)
}
Expand Down
6 changes: 3 additions & 3 deletions MapboxNavigation/RouteVoiceController.swift
Expand Up @@ -80,7 +80,7 @@ open class RouteVoiceController: NSObject, AVSpeechSynthesizerDelegate, AVAudioP
}

func resumeNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(alertLevelDidChange(notification:)), name: RouteControllerDidPassSpokenInstructionPoint, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didPassSpokenInstructionPoint(notification:)), name: RouteControllerDidPassSpokenInstructionPoint, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(pauseSpeechAndPlayReroutingDing(notification:)), name: RouteControllerWillReroute, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didReroute(notification:)), name: RouteControllerDidReroute, object: nil)
}
Expand Down Expand Up @@ -154,7 +154,7 @@ open class RouteVoiceController: NSObject, AVSpeechSynthesizerDelegate, AVAudioP
recentlyAnnouncedRouteStep = nil
}

open func alertLevelDidChange(notification: NSNotification) {
open func didPassSpokenInstructionPoint(notification: NSNotification) {
guard shouldSpeak(for: notification) == true else { return }

speak(fallbackText, error: nil)
Expand All @@ -164,7 +164,7 @@ open class RouteVoiceController: NSObject, AVSpeechSynthesizerDelegate, AVAudioP
func shouldSpeak(for notification: NSNotification) -> Bool {
guard isEnabled, volume > 0, !NavigationSettings.shared.muted else { return false }

let routeProgress = notification.userInfo![RouteControllerAlertLevelDidChangeNotificationRouteProgressKey] as! RouteProgress
let routeProgress = notification.userInfo![RouteControllerDidPassSpokenInstructionPointRouteProgressKey] as! RouteProgress

// We're guarding against two things here:
// 1. `recentlyAnnouncedRouteStep` being nil.
Expand Down
2 changes: 1 addition & 1 deletion MapboxNavigationTests/LaneTests.swift
Expand Up @@ -25,7 +25,7 @@ class LaneTests: FBSnapshotTestCase {
let controller = storyboard().instantiateViewController(withIdentifier: "RouteMapViewController") as! RouteMapViewController
XCTAssert(controller.view != nil)

controller.updateLaneViews(step: step, alertLevel: .high)
controller.updateLaneViews(step: step, durationRemaining: 20)
controller.showLaneViews(animated: false)

FBSnapshotVerifyView(controller.laneViewsContainerView)
Expand Down

0 comments on commit 5b51716

Please sign in to comment.