Skip to content

Commit 8e48c2b

Browse files
committed
NAVAND-1001: share lastPlayedInstructions between MapboxAudioGuidanceVoice instances
1 parent 15d044e commit 8e48c2b

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import kotlinx.coroutines.flow.filter
2727
import kotlinx.coroutines.flow.first
2828
import kotlinx.coroutines.flow.flatMapConcat
2929
import kotlinx.coroutines.flow.flatMapLatest
30+
import kotlinx.coroutines.flow.flatMapMerge
3031
import kotlinx.coroutines.flow.flowOf
3132
import kotlinx.coroutines.flow.map
3233
import kotlinx.coroutines.flow.updateAndGet
@@ -123,12 +124,12 @@ internal constructor(
123124
/**
124125
* Top level flow that will switch based on the language and muted state.
125126
*/
126-
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
127+
@OptIn(ExperimentalCoroutinesApi::class)
127128
private fun audioGuidanceFlow(
128129
mapboxNavigation: MapboxNavigation
129130
): Flow<MapboxAudioGuidanceState> {
130-
return mapboxNavigation.audioGuidanceVoice().flatMapLatest { audioGuidance ->
131-
var lastPlayedInstructions: VoiceInstructions? = null
131+
var lastPlayedInstructions: VoiceInstructions? = null
132+
return mapboxNavigation.audioGuidanceVoice().flatMapMerge { audioGuidance ->
132133
mutedStateFlow.flatMapLatest { isMuted ->
133134
val voiceInstructions = mapboxVoiceInstructions.voiceInstructions()
134135
.map { state ->
@@ -146,18 +147,15 @@ internal constructor(
146147
} else {
147148
voiceInstructions
148149
.filter { it.voiceInstructions != lastPlayedInstructions }
149-
.flatMapConcat {
150+
.map {
150151
lastPlayedInstructions = it.voiceInstructions
151152
val announcement = audioGuidance.speak(it.voiceInstructions)
152-
flowOf(announcement)
153-
}
154-
.map { speechAnnouncement ->
155-
internalStateFlow.updateAndGet {
153+
internalStateFlow.updateAndGet { state ->
156154
MapboxAudioGuidanceState(
157-
isPlayable = it.isPlayable,
158-
isMuted = it.isMuted,
159-
voiceInstructions = it.voiceInstructions,
160-
speechAnnouncement = speechAnnouncement
155+
isPlayable = state.isPlayable,
156+
isMuted = state.isMuted,
157+
voiceInstructions = state.voiceInstructions,
158+
speechAnnouncement = announcement
161159
)
162160
}
163161
}

0 commit comments

Comments
 (0)