Preserve map traffic enabled state across app restarts

like map type, which was implemented in 6cb682f0
This commit is contained in:
johan12345
2021-04-05 20:56:03 +02:00
parent aade4ec488
commit 38b82abc48
3 changed files with 11 additions and 1 deletions

View File

@@ -732,6 +732,7 @@ class MapFragment : Fragment(), OnMapReadyCallback, MapsActivity.FragmentCallbac
}
}
map.setMapType(vm.mapType.value)
map.setTrafficEnabled(vm.mapTrafficEnabled.value ?: false)
// set padding so that compass is not obstructed by toolbar
map.setPadding(0, binding.toolbarContainer.height, 0, 0)

View File

@@ -80,6 +80,12 @@ class PreferenceDataSource(val context: Context) {
sp.edit().putString("map_type", type.toString()).apply()
}
var mapTrafficEnabled: Boolean
get() = sp.getBoolean("map_traffic_enabled", false)
set(value) {
sp.edit().putBoolean("map_traffic_enabled", value).apply()
}
var welcomeDialogShown: Boolean
get() = sp.getBoolean("welcome_dialog_shown", false)
set(value) {

View File

@@ -217,7 +217,10 @@ class MapViewModel(application: Application, geApiKey: String) : AndroidViewMode
val mapTrafficEnabled: MutableLiveData<Boolean> by lazy {
MutableLiveData<Boolean>().apply {
value = false
value = prefs.mapTrafficEnabled
observeForever {
prefs.mapTrafficEnabled = it
}
}
}