Skip to content

Commit 5cdc300

Browse files
authored
Add getStyleExtension to the MapboxCarMapLoader (#6571)
1 parent 5a77f6d commit 5cdc300

4 files changed

Lines changed: 42 additions & 10 deletions

File tree

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+
- Added `MapboxCarMapLoader.getStyleExtension` to get access to the values set. [#6571](https://github.com/mapbox/mapbox-navigation-android/pull/6571)
89

910
## androidauto-v0.16.0 - 04 November, 2022
1011
### Changelog

libnavui-androidauto/api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ package com.mapbox.androidauto.map {
253253

254254
public final class MapboxCarMapLoader implements com.mapbox.maps.extension.androidauto.MapboxCarMapObserver {
255255
ctor public MapboxCarMapLoader();
256+
method public com.mapbox.maps.extension.style.StyleContract.StyleExtension getStyleExtension(boolean isDarkMode);
256257
method public com.mapbox.androidauto.map.MapboxCarMapLoader onCarConfigurationChanged(androidx.car.app.CarContext carContext);
257258
method public com.mapbox.androidauto.map.MapboxCarMapLoader setDarkStyleOverride(com.mapbox.maps.extension.style.StyleContract.StyleExtension? styleContract);
258259
method public com.mapbox.androidauto.map.MapboxCarMapLoader setLightStyleOverride(com.mapbox.maps.extension.style.StyleContract.StyleExtension? styleContract);

libnavui-androidauto/src/main/java/com/mapbox/androidauto/map/MapboxCarMapLoader.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class MapboxCarMapLoader : MapboxCarMapObserver {
4646
with(mapboxCarMapSurface) {
4747
logAndroidAuto("onAttached load style")
4848
mapSurface.getMapboxMap().loadStyle(
49-
mapStyle(carContext.isDarkMode),
49+
getStyleExtension(carContext.isDarkMode),
5050
onStyleLoaded = { style ->
5151
logAndroidAuto("onAttached style loaded")
5252
style.addPersistentStyleCustomLayer(
@@ -65,6 +65,17 @@ class MapboxCarMapLoader : MapboxCarMapObserver {
6565
mapboxMap = null
6666
}
6767

68+
/**
69+
* Returns the current style contract. If an override has not been set the default is returned.
70+
*/
71+
fun getStyleExtension(isDarkMode: Boolean): StyleContract.StyleExtension {
72+
return if (isDarkMode) {
73+
darkStyleOverride ?: DEFAULT_NIGHT_STYLE
74+
} else {
75+
lightStyleOverride ?: DEFAULT_DAY_STYLE
76+
}
77+
}
78+
6879
/**
6980
* Set the map style to apply when [CarContext.isDarkMode] is false. Setting to `null` will use
7081
* a default map style.
@@ -96,7 +107,7 @@ class MapboxCarMapLoader : MapboxCarMapObserver {
96107
*/
97108
fun onCarConfigurationChanged(carContext: CarContext) = apply {
98109
mapboxMap?.loadStyle(
99-
mapStyle(carContext.isDarkMode),
110+
getStyleExtension(carContext.isDarkMode),
100111
onStyleLoaded = { style ->
101112
logAndroidAuto("updateMapStyle styleAvailable ${style.styleURI}")
102113
},
@@ -106,14 +117,6 @@ class MapboxCarMapLoader : MapboxCarMapObserver {
106117
)
107118
}
108119

109-
private fun mapStyle(isDarkMode: Boolean): StyleContract.StyleExtension {
110-
return if (isDarkMode) {
111-
darkStyleOverride ?: DEFAULT_NIGHT_STYLE
112-
} else {
113-
lightStyleOverride ?: DEFAULT_DAY_STYLE
114-
}
115-
}
116-
117120
private companion object {
118121
private val DEFAULT_DAY_STYLE = style(NavigationStyles.NAVIGATION_DAY_STYLE) { }
119122
private val DEFAULT_NIGHT_STYLE = style(NavigationStyles.NAVIGATION_NIGHT_STYLE) { }

libnavui-androidauto/src/test/java/com/mapbox/androidauto/map/MapboxCarMapLoaderTest.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,33 @@ class MapboxCarMapLoaderTest {
8787
assertEquals("test-dark-override", styleExtensionSlot.captured.styleUri)
8888
}
8989

90+
@Test
91+
fun `getStyleExtension will return the default styles`() {
92+
assertEquals(
93+
NavigationStyles.NAVIGATION_DAY_STYLE,
94+
sut.getStyleExtension(false).styleUri
95+
)
96+
assertEquals(
97+
NavigationStyles.NAVIGATION_NIGHT_STYLE,
98+
sut.getStyleExtension(true).styleUri
99+
)
100+
}
101+
102+
@Test
103+
fun `getStyleExtension will return the overridden styles`() {
104+
sut.setLightStyleOverride(mockk { every { styleUri } returns "test-light-override" })
105+
sut.setDarkStyleOverride(mockk { every { styleUri } returns "test-dark-override" })
106+
107+
assertEquals(
108+
"test-light-override",
109+
sut.getStyleExtension(false).styleUri
110+
)
111+
assertEquals(
112+
"test-dark-override",
113+
sut.getStyleExtension(true).styleUri
114+
)
115+
}
116+
90117
private fun mockMapboxCarMapSurface(
91118
styleExtensionSlot: CapturingSlot<StyleContract.StyleExtension>
92119
): MapboxCarMapSurface {

0 commit comments

Comments
 (0)