@@ -72,10 +72,34 @@ public class SpokenInstructionFormatter: NSObject {
7272 // We only want to announce this special depature announcement once.
7373 // Once it has been announced, all subsequnt announcements will not have an alert level of low
7474 // since the user will be approaching the maneuver location.
75- let isDeparture = routeProgress. currentLegProgress. currentStep. maneuverType == . depart && alertLevel == . depart
76- let didCompleteManeuver = routeProgress. currentLegProgress. currentStep. distance > 2_000 && routeProgress. currentLegProgress. alertUserLevel == . low
77- if isDeparture || didCompleteManeuver {
78- if isDeparture && upcomingStepDuration < linkedInstructionMultiplier {
75+ let isStartingDeparture = routeProgress. currentLegProgress. currentStep. maneuverType == . depart && ( alertLevel == . depart || alertLevel == . low)
76+ if let currentInstruction = currentInstruction, isStartingDeparture {
77+ if routeProgress. currentLegProgress. currentStep. distance > RouteControllerMinDistanceForContinueInstruction {
78+ text = currentInstruction
79+ } else if upcomingStepDuration > linkedInstructionMultiplier {
80+ // If the upcoming step is an .exitRoundabout or .exitRotary, don't link the instruction
81+ if let followOnStep = routeProgress. currentLegProgress. followOnStep, followOnStep. maneuverType == . exitRoundabout || followOnStep. maneuverType == . exitRotary {
82+ text = upComingInstruction
83+ } else {
84+ let phrase = escapeIfNecessary ( routeStepFormatter. instructions. phrase ( named: . twoInstructionsWithDistance) )
85+ text = phrase. replacingTokens { ( tokenType) -> String in
86+ switch tokenType {
87+ case . firstInstruction:
88+ return currentInstruction
89+ case . secondInstruction:
90+ return upComingInstruction
91+ case . distance:
92+ return maneuverVoiceDistanceFormatter. string ( from: userDistance)
93+ default :
94+ fatalError ( " Unexpected token \( tokenType) " )
95+ }
96+ }
97+ }
98+ } else {
99+ text = upComingInstruction
100+ }
101+ } else if routeProgress. currentLegProgress. currentStep. distance > RouteControllerMinDistanceForContinueInstruction && routeProgress. currentLegProgress. alertUserLevel == . low {
102+ if isStartingDeparture && upcomingStepDuration < linkedInstructionMultiplier {
79103 let phrase = escapeIfNecessary ( routeStepFormatter. instructions. phrase ( named: . twoInstructionsWithDistance) )
80104 text = phrase. replacingTokens { ( tokenType) -> String in
81105 switch tokenType {
0 commit comments