Skip to content

Commit caabf88

Browse files
authored
Update audio guidance for AA compatibility (#6336)
* Update audio guidance for AA compatibility * Move audio guidance out of shared app * Move constrcutor to private * Add provider functions * fix test * update api
1 parent 148a2d5 commit caabf88

File tree

26 files changed

+312
-643
lines changed

26 files changed

+312
-643
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Mapbox welcomes participation and contributions from everyone.
44

55
## Unreleased
66
#### Features
7+
- Moved `MapboxAudioGuidance` and `MapboxAudioGuidanceState` into public api. [#6336](https://github.com/mapbox/mapbox-navigation-android/pull/6336)
78
#### Bug fixes and improvements
89

910
## Mapbox Navigation SDK 2.9.0-alpha.2 - 16 September, 2022

LICENSE.md

Lines changed: 1 addition & 345 deletions
Large diffs are not rendered by default.

libnavui-androidauto/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Mapbox welcomes participation and contributions from everyone.
55
## Unreleased
66
#### Features
77
#### Bug fixes and improvements
8+
- Use `MapboxAudioGuidance` from public api. [#6336](https://github.com/mapbox/mapbox-navigation-android/pull/6336)
89

910
## androidauto-v0.11.0 - Sep 16, 2022
1011
### Changelog

libnavui-androidauto/api/current.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ package com.mapbox.androidauto {
1717
}
1818

1919
public final class MapboxCarApp {
20-
method public com.mapbox.navigation.ui.voice.internal.MapboxAudioGuidance carAppAudioGuidanceService();
2120
method public com.mapbox.androidauto.navigation.location.CarAppLocation carAppLocationService();
2221
method public kotlinx.coroutines.flow.StateFlow<com.mapbox.androidauto.CarAppState> getCarAppState();
23-
method public void setup(android.app.Application application);
22+
method public void setup();
2423
method public void updateCarAppState(com.mapbox.androidauto.CarAppState carAppState);
2524
property public final kotlinx.coroutines.flow.StateFlow<com.mapbox.androidauto.CarAppState> carAppState;
2625
field public static final com.mapbox.androidauto.MapboxCarApp INSTANCE;

libnavui-androidauto/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ dependencies {
4545
def carSearchVersion = "1.0.0-beta.36"
4646
api("com.mapbox.search:mapbox-search-android:${carSearchVersion}")
4747

48-
debugApi project(":libnavigation-android")
49-
releaseApi("com.mapbox.navigation:android:${carNavVersion}")
50-
debugImplementation project(":libnavui-app")
51-
releaseImplementation("com.mapbox.navigation:ui-app:${carNavVersion}")
48+
// TODO use the carNavVersion when 2.9.0-alpha.2 is available
49+
api(project(":libnavigation-android"))
50+
// api("com.mapbox.navigation:android:${carNavVersion}")
5251

5352
implementation(dependenciesList.androidXAppCompat)
5453
implementation(dependenciesList.coroutinesCore)
Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
package com.mapbox.androidauto
22

3-
import android.app.Application
43
import com.mapbox.androidauto.navigation.location.CarAppLocation
54
import com.mapbox.androidauto.navigation.location.impl.CarAppLocationImpl
65
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
76
import com.mapbox.navigation.core.lifecycle.MapboxNavigationApp
8-
import com.mapbox.navigation.ui.app.internal.SharedApp
9-
import com.mapbox.navigation.ui.voice.internal.MapboxAudioGuidance
107
import kotlinx.coroutines.flow.MutableStateFlow
118
import kotlinx.coroutines.flow.StateFlow
129

1310
/**
1411
* The entry point for your Mapbox Android Auto app.
1512
*/
16-
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
1713
object MapboxCarApp {
1814

1915
private val carAppStateFlow = MutableStateFlow<CarAppState>(FreeDriveState)
@@ -29,12 +25,6 @@ object MapboxCarApp {
2925
fun carAppLocationService(): CarAppLocation =
3026
MapboxNavigationApp.getObserver(CarAppLocation::class)
3127

32-
/**
33-
* Audio guidance service available to the car and app.
34-
*/
35-
fun carAppAudioGuidanceService(): MapboxAudioGuidance =
36-
MapboxNavigationApp.getObserver(MapboxAudioGuidance::class)
37-
3828
/**
3929
* Keep your car and app in sync with CarAppState.
4030
*/
@@ -43,12 +33,12 @@ object MapboxCarApp {
4333
}
4434

4535
/**
46-
* Setup android auto from your [Application.onCreate]
47-
*
48-
* @param application used to detect when activities are foregrounded
36+
* Setup android auto with defaults
4937
*/
50-
fun setup(application: Application) {
51-
SharedApp.setup(application)
52-
MapboxNavigationApp.registerObserver(CarAppLocationImpl())
38+
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
39+
fun setup() {
40+
if (MapboxNavigationApp.getObservers(CarAppLocation::class).isEmpty()) {
41+
MapboxNavigationApp.registerObserver(CarAppLocationImpl())
42+
}
5343
}
5444
}

libnavui-androidauto/src/main/java/com/mapbox/androidauto/navigation/audioguidance/AppAudioGuidanceUi.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import androidx.lifecycle.Lifecycle
77
import androidx.lifecycle.LifecycleOwner
88
import androidx.lifecycle.lifecycleScope
99
import androidx.lifecycle.repeatOnLifecycle
10-
import com.mapbox.androidauto.MapboxCarApp
11-
import com.mapbox.navigation.ui.voice.internal.MapboxAudioGuidance
10+
import com.mapbox.navigation.ui.voice.api.MapboxAudioGuidance
11+
import com.mapbox.navigation.ui.voice.api.MapboxAudioGuidanceState
1212
import com.mapbox.navigation.ui.voice.view.MapboxSoundButton
1313
import kotlinx.coroutines.flow.collect
1414
import kotlinx.coroutines.launch
@@ -17,7 +17,7 @@ fun Fragment.attachAudioGuidance(
1717
mapboxSoundButton: MapboxSoundButton
1818
) {
1919
val lifecycleOwner = viewLifecycleOwner
20-
val flow = MapboxCarApp.carAppAudioGuidanceService().stateFlow()
20+
val flow = MapboxAudioGuidance.getInstance().stateFlow()
2121
lifecycleOwner.lifecycleScope.launch {
2222
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
2323
flow.collect { state ->
@@ -31,7 +31,7 @@ fun Fragment.attachAudioGuidance(
3131
}
3232
}
3333
mapboxSoundButton.setOnClickListener {
34-
MapboxCarApp.carAppAudioGuidanceService().toggle()
34+
MapboxAudioGuidance.getInstance().toggle()
3535
}
3636
}
3737

@@ -40,17 +40,17 @@ fun Fragment.attachAudioGuidance(
4040
*/
4141
fun Lifecycle.muteAudioGuidance() {
4242
addObserver(object : DefaultLifecycleObserver {
43-
lateinit var initialState: MapboxAudioGuidance.State
43+
lateinit var initialState: MapboxAudioGuidanceState
4444
override fun onResume(owner: LifecycleOwner) {
45-
with(MapboxCarApp.carAppAudioGuidanceService()) {
45+
with(MapboxAudioGuidance.getInstance()) {
4646
initialState = stateFlow().value
4747
mute()
4848
}
4949
}
5050

5151
override fun onPause(owner: LifecycleOwner) {
5252
if (!initialState.isMuted) {
53-
MapboxCarApp.carAppAudioGuidanceService().unmute()
53+
MapboxAudioGuidance.getInstance().unMute()
5454
}
5555
}
5656
})

libnavui-androidauto/src/main/java/com/mapbox/androidauto/navigation/audioguidance/CarAudioGuidanceUi.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import androidx.core.graphics.drawable.IconCompat
88
import androidx.lifecycle.Lifecycle
99
import androidx.lifecycle.coroutineScope
1010
import androidx.lifecycle.repeatOnLifecycle
11-
import com.mapbox.androidauto.MapboxCarApp
1211
import com.mapbox.androidauto.R
1312
import com.mapbox.androidauto.car.MainActionStrip
1413
import com.mapbox.androidauto.car.action.MapboxActionProvider
14+
import com.mapbox.navigation.ui.voice.api.MapboxAudioGuidance
1515
import kotlinx.coroutines.flow.collect
1616
import kotlinx.coroutines.flow.distinctUntilChanged
1717
import kotlinx.coroutines.launch
@@ -28,15 +28,15 @@ class CarAudioGuidanceUi : MapboxActionProvider.ScreenActionProvider {
2828
* Attach this to the screen while navigating.
2929
*/
3030
private fun buildSoundButtonAction(screen: Screen): Action {
31-
val audioGuidance = MapboxCarApp.carAppAudioGuidanceService()
31+
val audioGuidance = MapboxAudioGuidance.getInstance()
3232
val state = audioGuidance.stateFlow().value
3333
return if (!state.isMuted) {
3434
buildIconAction(screen, R.drawable.mapbox_car_ic_volume_on) {
3535
audioGuidance.mute()
3636
}
3737
} else {
3838
buildIconAction(screen, R.drawable.mapbox_car_ic_volume_off) {
39-
audioGuidance.unmute()
39+
audioGuidance.unMute()
4040
}
4141
}
4242
}
@@ -45,7 +45,7 @@ class CarAudioGuidanceUi : MapboxActionProvider.ScreenActionProvider {
4545
screen.lifecycle.apply {
4646
coroutineScope.launch {
4747
repeatOnLifecycle(Lifecycle.State.STARTED) {
48-
MapboxCarApp.carAppAudioGuidanceService().stateFlow()
48+
MapboxAudioGuidance.getInstance().stateFlow()
4949
.distinctUntilChanged { old, new ->
5050
old.isMuted == new.isMuted && old.isPlayable == new.isPlayable
5151
}

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.mapbox.navigation.ui.app.internal
22

3-
import android.content.Context
43
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
54
import com.mapbox.navigation.core.internal.extensions.attachCreated
65
import com.mapbox.navigation.core.lifecycle.MapboxNavigationApp
@@ -17,9 +16,6 @@ import com.mapbox.navigation.ui.app.internal.controller.StateResetController
1716
import com.mapbox.navigation.ui.app.internal.controller.TripSessionStarterStateController
1817
import com.mapbox.navigation.ui.maps.internal.ui.RouteAlternativeComponent
1918
import com.mapbox.navigation.ui.maps.internal.ui.RouteAlternativeContract
20-
import com.mapbox.navigation.ui.utils.internal.datastore.NavigationDataStoreOwner
21-
import com.mapbox.navigation.ui.voice.internal.MapboxAudioGuidance
22-
import com.mapbox.navigation.ui.voice.internal.impl.MapboxAudioGuidanceImpl
2319
import java.util.concurrent.atomic.AtomicBoolean
2420

2521
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
@@ -55,8 +51,6 @@ object SharedApp {
5551

5652
@JvmOverloads
5753
fun setup(
58-
context: Context,
59-
audioGuidance: MapboxAudioGuidance? = null,
6054
routeAlternativeContract: RouteAlternativeContract? = null
6155
) {
6256
if (isSetup) return
@@ -69,7 +63,6 @@ object SharedApp {
6963
}
7064
)
7165
MapboxNavigationApp.lifecycleOwner.attachCreated(*navigationObservers)
72-
MapboxNavigationApp.registerObserver(audioGuidance ?: defaultAudioGuidance(context))
7366
}
7467

7568
fun tripSessionTransaction(updateSession: () -> Unit) {
@@ -80,12 +73,4 @@ object SharedApp {
8073
updateSession()
8174
ignoreTripSessionUpdates.set(false)
8275
}
83-
84-
private fun defaultAudioGuidance(context: Context): MapboxAudioGuidance {
85-
return MapboxAudioGuidanceImpl.create(context).also {
86-
it.dataStoreOwner = NavigationDataStoreOwner(context, DEFAULT_DATA_STORE_NAME)
87-
}
88-
}
89-
90-
private const val DEFAULT_DATA_STORE_NAME = "mapbox_navigation_preferences"
9176
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ package com.mapbox.navigation.ui.app.internal.controller
22

33
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
44
import com.mapbox.navigation.core.MapboxNavigation
5-
import com.mapbox.navigation.core.lifecycle.MapboxNavigationApp
65
import com.mapbox.navigation.ui.app.internal.Action
76
import com.mapbox.navigation.ui.app.internal.State
87
import com.mapbox.navigation.ui.app.internal.Store
98
import com.mapbox.navigation.ui.app.internal.audioguidance.AudioAction
109
import com.mapbox.navigation.ui.app.internal.audioguidance.AudioGuidanceState
11-
import com.mapbox.navigation.ui.voice.internal.MapboxAudioGuidance
10+
import com.mapbox.navigation.ui.voice.api.MapboxAudioGuidance
1211

1312
/**
1413
* This class is responsible for playing voice instructions. Use the [AudioAction] to turning the
@@ -47,7 +46,7 @@ class AudioGuidanceStateController(
4746
override fun onAttached(mapboxNavigation: MapboxNavigation) {
4847
super.onAttached(mapboxNavigation)
4948

50-
val audioGuidance = MapboxNavigationApp.getObserver(MapboxAudioGuidance::class)
49+
val audioGuidance = MapboxAudioGuidance.getInstance()
5150
audioGuidance.stateFlow().observe {
5251
if (it.isMuted != store.state.value.audio.isMuted) {
5352
val newState = AudioGuidanceState(it.isMuted)
@@ -59,7 +58,7 @@ class AudioGuidanceStateController(
5958
if (it.isMuted) {
6059
audioGuidance.mute()
6160
} else {
62-
audioGuidance.unmute()
61+
audioGuidance.unMute()
6362
}
6463
}
6564
}

0 commit comments

Comments
 (0)