Skip to content

Commit 3769e18

Browse files
committed
NAVAND-1001: use immediate dispatcher to guarantee that language will change before voice instructions
1 parent f3043af commit 3769e18

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Mapbox welcomes participation and contributions from everyone.
2525
```
2626
- Added guarantees that route progress with `RouteProgress#currentState == OFF_ROUTE` arrives earlier than `NavigationRerouteController#reroute` is called. [#6764](https://github.com/mapbox/mapbox-navigation-android/pull/6764)
2727
- Fixed a rare `java.lang.NullPointerException: Attempt to read from field 'SpeechAnnouncement PlayCallback.announcement' on a null object reference` crash in `PlayCallback.getAnnouncement`. [#6760](https://github.com/mapbox/mapbox-navigation-android/pull/6760)
28+
- Fixed an issue where the first voice instruction might have been played twice. [#6766](https://github.com/mapbox/mapbox-navigation-android/pull/6766)
2829

2930
## Mapbox Navigation SDK 2.10.0-rc.1 - 16 December, 2022
3031
### Changelog

libnavui-voice/src/main/java/com/mapbox/navigation/ui/voice/api/MapboxAudioGuidance.kt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import kotlinx.coroutines.CoroutineDispatcher
1414
import kotlinx.coroutines.CoroutineScope
1515
import kotlinx.coroutines.Dispatchers
1616
import kotlinx.coroutines.ExperimentalCoroutinesApi
17-
import kotlinx.coroutines.FlowPreview
1817
import kotlinx.coroutines.Job
1918
import kotlinx.coroutines.SupervisorJob
2019
import kotlinx.coroutines.flow.Flow
@@ -25,9 +24,7 @@ import kotlinx.coroutines.flow.combine
2524
import kotlinx.coroutines.flow.distinctUntilChanged
2625
import kotlinx.coroutines.flow.filter
2726
import kotlinx.coroutines.flow.first
28-
import kotlinx.coroutines.flow.flatMapConcat
2927
import kotlinx.coroutines.flow.flatMapLatest
30-
import kotlinx.coroutines.flow.flowOf
3128
import kotlinx.coroutines.flow.map
3229
import kotlinx.coroutines.flow.updateAndGet
3330
import kotlinx.coroutines.launch
@@ -123,7 +120,7 @@ internal constructor(
123120
/**
124121
* Top level flow that will switch based on the language and muted state.
125122
*/
126-
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
123+
@OptIn(ExperimentalCoroutinesApi::class)
127124
private fun audioGuidanceFlow(
128125
mapboxNavigation: MapboxNavigation
129126
): Flow<MapboxAudioGuidanceState> {
@@ -146,18 +143,15 @@ internal constructor(
146143
} else {
147144
voiceInstructions
148145
.filter { it.voiceInstructions != lastPlayedInstructions }
149-
.flatMapConcat {
146+
.map {
150147
lastPlayedInstructions = it.voiceInstructions
151148
val announcement = audioGuidance.speak(it.voiceInstructions)
152-
flowOf(announcement)
153-
}
154-
.map { speechAnnouncement ->
155-
internalStateFlow.updateAndGet {
149+
internalStateFlow.updateAndGet { state ->
156150
MapboxAudioGuidanceState(
157-
isPlayable = it.isPlayable,
158-
isMuted = it.isMuted,
159-
voiceInstructions = it.voiceInstructions,
160-
speechAnnouncement = speechAnnouncement
151+
isPlayable = state.isPlayable,
152+
isMuted = state.isMuted,
153+
voiceInstructions = state.voiceInstructions,
154+
speechAnnouncement = announcement
161155
)
162156
}
163157
}
@@ -195,7 +189,10 @@ internal constructor(
195189
* Construct an instance without registering to [MapboxNavigationApp].
196190
*/
197191
@JvmStatic
198-
fun create() = MapboxAudioGuidance(MapboxAudioGuidanceServices(), Dispatchers.Main)
192+
fun create() = MapboxAudioGuidance(
193+
MapboxAudioGuidanceServices(),
194+
Dispatchers.Main.immediate
195+
)
199196

200197
/**
201198
* Get the registered instance or create one and register it to [MapboxNavigationApp].

0 commit comments

Comments
 (0)