Skip to content

Commit 9d8a6cf

Browse files
committed
Move audio guidance out of shared app
1 parent ddbd4e7 commit 9d8a6cf

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

libnavui-app/src/main/java/com/mapbox/navigation/ui/app/internal/SharedApp.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import com.mapbox.navigation.ui.app.internal.controller.StateResetController
1616
import com.mapbox.navigation.ui.app.internal.controller.TripSessionStarterStateController
1717
import com.mapbox.navigation.ui.maps.internal.ui.RouteAlternativeComponent
1818
import com.mapbox.navigation.ui.maps.internal.ui.RouteAlternativeContract
19-
import com.mapbox.navigation.ui.voice.api.MapboxAudioGuidance
2019
import java.util.concurrent.atomic.AtomicBoolean
2120

2221
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
@@ -64,12 +63,6 @@ object SharedApp {
6463
}
6564
)
6665
MapboxNavigationApp.lifecycleOwner.attachCreated(*navigationObservers)
67-
68-
// TODO Remove this from SharedApp. The components that use `MapboxAudioGuidance`
69-
// will "ensureAudioGuidanceRegistered". See the `ComponentInstaller.audioGuidanceButton`
70-
if (MapboxNavigationApp.getObservers(MapboxAudioGuidance::class).isEmpty()) {
71-
MapboxNavigationApp.registerObserver(MapboxAudioGuidance())
72-
}
7366
}
7467

7568
fun tripSessionTransaction(updateSession: () -> Unit) {

libnavui-voice/src/main/java/com/mapbox/navigation/ui/voice/internal/ui/AudioGuidanceButtonComponent.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ class AudioGuidanceButtonComponent(
5353

5454
init {
5555
this.contractProvider = contractProvider ?: Provider {
56-
val audioGuidance = MapboxNavigationApp.getObserver(MapboxAudioGuidance::class)
56+
val audioGuidance = MapboxNavigationApp
57+
.getObservers(MapboxAudioGuidance::class).firstOrNull()
58+
?: MapboxAudioGuidance().also { MapboxNavigationApp.registerObserver(it) }
5759
MapboxAudioComponentContract(coroutineScope, audioGuidance)
5860
}
5961
}

libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/internal/ui/AudioGuidanceButtonComponentTest.kt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.mapbox.navigation.ui.voice.view.MapboxAudioGuidanceButton
1313
import io.mockk.every
1414
import io.mockk.mockk
1515
import io.mockk.mockkObject
16+
import io.mockk.slot
1617
import io.mockk.spyk
1718
import io.mockk.unmockkAll
1819
import io.mockk.verify
@@ -21,6 +22,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
2122
import kotlinx.coroutines.flow.MutableStateFlow
2223
import org.junit.After
2324
import org.junit.Assert.assertFalse
25+
import org.junit.Assert.assertTrue
2426
import org.junit.Before
2527
import org.junit.Rule
2628
import org.junit.Test
@@ -112,8 +114,8 @@ class AudioGuidanceButtonComponentTest {
112114
every { toggle() } returns Unit
113115
}
114116
every {
115-
MapboxNavigationApp.getObserver(MapboxAudioGuidance::class)
116-
} returns mockAudioGuidance
117+
MapboxNavigationApp.getObservers(MapboxAudioGuidance::class)
118+
} returns listOf(mockAudioGuidance)
117119

118120
val sut = AudioGuidanceButtonComponent(button)
119121
sut.onAttached(mapboxNavigation)
@@ -122,6 +124,23 @@ class AudioGuidanceButtonComponentTest {
122124
verify { mockAudioGuidance.mute() }
123125
}
124126

127+
@Test
128+
fun `onAttach - create MapboxAudioGuidance if none exists`() {
129+
val slotAudioGuidance = slot<MapboxAudioGuidance>()
130+
every {
131+
MapboxNavigationApp.getObservers(MapboxAudioGuidance::class)
132+
} returns emptyList()
133+
every {
134+
MapboxNavigationApp.registerObserver(capture(slotAudioGuidance))
135+
} returns MapboxNavigationApp
136+
137+
val sut = AudioGuidanceButtonComponent(button)
138+
sut.onAttached(mapboxNavigation)
139+
button.performClick()
140+
141+
assertTrue(slotAudioGuidance.isCaptured)
142+
}
143+
125144
@Test
126145
fun `onDetached - should not handle button on click events`() {
127146
sut.onAttached(mapboxNavigation)

0 commit comments

Comments
 (0)