Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone.
#### Features
#### Bug fixes and improvements
- 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)
- Fix crash due to multiple DataStores active. [#6392](https://github.com/mapbox/mapbox-navigation-android/pull/6392)

## Mapbox Navigation SDK 2.9.0-alpha.3 - 23 September, 2022
### Changelog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import kotlinx.coroutines.flow.map
/**
* Implementation for preferences that exist beyond app and car sessions.
*/
class NavigationDataStoreOwner(context: Context, storeName: String) {
class NavigationDataStoreOwner(context: Context) {

private val Context.dataStore by preferencesDataStore(storeName)
private var dataStore: DataStore<Preferences> = context.dataStore
private val dataStore: DataStore<Preferences> = context.dataStore

fun <T> read(key: NavigationDataStoreKey<T>): Flow<T> {
return dataStore.data.map { preferences ->
Expand All @@ -27,4 +26,9 @@ class NavigationDataStoreOwner(context: Context, storeName: String) {
preferences[key.preferenceKey] = value ?: key.defaultValue
}
}

private companion object {
private const val NAVIGATION_DATA_STORE_NAME = "mapbox_navigation_preferences"
private val Context.dataStore by preferencesDataStore(name = NAVIGATION_DATA_STORE_NAME)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal constructor(
*/
override fun onAttached(mapboxNavigation: MapboxNavigation) {
val context = mapboxNavigation.navigationOptions.applicationContext
dataStoreOwner = audioGuidanceServices.dataStoreOwner(context, DEFAULT_DATA_STORE_NAME)
dataStoreOwner = audioGuidanceServices.dataStoreOwner(context)
configOwner = audioGuidanceServices.configOwner(context)
mapboxVoiceInstructions.registerObservers(mapboxNavigation)
job = scope.launch {
Expand Down Expand Up @@ -198,7 +198,6 @@ internal constructor(
companion object {
private val STORE_AUDIO_GUIDANCE_MUTED =
booleanDataStoreKey("audio_guidance_muted", false)
private const val DEFAULT_DATA_STORE_NAME = "mapbox_navigation_preferences"

/**
* Construct an instance without registering to [MapboxNavigationApp].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@ class MapboxAudioGuidanceServices {

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

fun dataStoreOwner(context: Context, storeName: String) =
NavigationDataStoreOwner(context, storeName)
fun dataStoreOwner(context: Context) = NavigationDataStoreOwner(context)
}