Skip to content

Commit cd816d0

Browse files
committed
Fix data store crash
1 parent 420d326 commit cd816d0

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone.
66
#### Features
77
#### Bug fixes and improvements
88
- Marked `ReplayProgressObserver`, `MapboxReplayer`, `ReplayLocationEngine`, `RerouteController#RoutesCallback`, `NavigationRerouteController#RoutesCallback`, `LocationObserver`, `NavigationSessionStateObserver`, `OffRouteObserver`, `RouteProgressObserver`, `TripSessionStateObserver`, `VoiceInstructionsObserver` methods with `@UiThread` annotation. [#6266](https://github.com/mapbox/mapbox-navigation-android/pull/6266)
9+
- Fix crash due to multiple DataStores active. [#6392](https://github.com/mapbox/mapbox-navigation-android/pull/6392)
910

1011
## Mapbox Navigation SDK 2.9.0-alpha.3 - 23 September, 2022
1112
### Changelog

libnavui-util/src/main/java/com/mapbox/navigation/ui/utils/internal/datastore/NavigationDataStoreOwner.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import kotlinx.coroutines.flow.map
1111
/**
1212
* Implementation for preferences that exist beyond app and car sessions.
1313
*/
14-
class NavigationDataStoreOwner(context: Context, storeName: String) {
14+
class NavigationDataStoreOwner(context: Context) {
1515

16-
private val Context.dataStore by preferencesDataStore(storeName)
17-
private var dataStore: DataStore<Preferences> = context.dataStore
16+
private val dataStore: DataStore<Preferences> = context.dataStore
1817

1918
fun <T> read(key: NavigationDataStoreKey<T>): Flow<T> {
2019
return dataStore.data.map { preferences ->
@@ -27,4 +26,9 @@ class NavigationDataStoreOwner(context: Context, storeName: String) {
2726
preferences[key.preferenceKey] = value ?: key.defaultValue
2827
}
2928
}
29+
30+
private companion object {
31+
private const val NAVIGATION_DATA_STORE_NAME = "mapbox_navigation_preferences"
32+
private val Context.dataStore by preferencesDataStore(name = NAVIGATION_DATA_STORE_NAME)
33+
}
3034
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal constructor(
5454
*/
5555
override fun onAttached(mapboxNavigation: MapboxNavigation) {
5656
val context = mapboxNavigation.navigationOptions.applicationContext
57-
dataStoreOwner = audioGuidanceServices.dataStoreOwner(context, DEFAULT_DATA_STORE_NAME)
57+
dataStoreOwner = audioGuidanceServices.dataStoreOwner(context)
5858
configOwner = audioGuidanceServices.configOwner(context)
5959
mapboxVoiceInstructions.registerObservers(mapboxNavigation)
6060
job = scope.launch {
@@ -198,7 +198,6 @@ internal constructor(
198198
companion object {
199199
private val STORE_AUDIO_GUIDANCE_MUTED =
200200
booleanDataStoreKey("audio_guidance_muted", false)
201-
private const val DEFAULT_DATA_STORE_NAME = "mapbox_navigation_preferences"
202201

203202
/**
204203
* Construct an instance without registering to [MapboxNavigationApp].

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,5 @@ class MapboxAudioGuidanceServices {
4646

4747
fun configOwner(context: Context): NavigationConfigOwner = NavigationConfigOwner(context)
4848

49-
fun dataStoreOwner(context: Context, storeName: String) =
50-
NavigationDataStoreOwner(context, storeName)
49+
fun dataStoreOwner(context: Context) = NavigationDataStoreOwner(context)
5150
}

0 commit comments

Comments
 (0)