Skip to content

Commit 1708fac

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

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ 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)
1716
private var dataStore: DataStore<Preferences> = context.dataStore
1817

1918
fun <T> read(key: NavigationDataStoreKey<T>): Flow<T> {
@@ -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 DEFAULT_DATA_STORE_NAME = "mapbox_navigation_preferences"
32+
private val Context.dataStore by preferencesDataStore(name = DEFAULT_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)