Skip to content

Commit 22804e6

Browse files
committed
NAVAND-1001: use immediate dispatcher to guarantee that language will change before voice instructions
1 parent 915b7d6 commit 22804e6

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
@@ -28,6 +28,7 @@ Mapbox welcomes participation and contributions from everyone.
2828
- Fixed standalone `MapboxManeuverView` appearance when the app also integrates Drop-In UI. [#6774](https://github.com/mapbox/mapbox-navigation-android/pull/6774)
2929
- Introduced `NavigationViewListener.onSpeedInfoClicked` that would be triggered when `MapboxSpeedInfoView` is clicked upon. [#6770](https://github.com/mapbox/mapbox-navigation-android/pull/6770)
3030
- Each newly instantiated MapboxRouteArrowView class will initialize the layers with the provided options on the first render call. Previously this would only be done if the layers hadn't already been initialized. [#6466](https://github.com/mapbox/mapbox-navigation-android/pull/6466)
31+
- Fixed an issue where the first voice instruction might have been played twice. [#6766](https://github.com/mapbox/mapbox-navigation-android/pull/6766)
3132

3233
## Mapbox Navigation SDK 2.10.0-rc.1 - 16 December, 2022
3334
### 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)