Files
GPS2Audio/app/src/main/kotlin/de/waypointaudio/data/ExplorerSettings.kt
T
2026-05-30 05:42:44 +00:00

41 lines
1.2 KiB
Kotlin

package de.waypointaudio.data
import android.content.Context
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.preferencesDataStore
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
/**
* Persistente Einstellungen des Explorers (v2.2.3).
*
* Aktuell nur „GPS-Nachführung an/aus". Die Einstellung überlebt
* Neustarts und Navigation; eine manuelle Kartenverschiebung darf
* den Wert nicht automatisch wieder auf „an" setzen.
*/
data class ExplorerSettings(
val followLocation: Boolean = true,
)
private val Context.explorerDataStore by preferencesDataStore(name = "explorer_settings")
class ExplorerSettingsStore(private val context: Context) {
private companion object {
val KEY_FOLLOW = booleanPreferencesKey("follow_location")
}
val settings: Flow<ExplorerSettings> = context.explorerDataStore.data.map { prefs ->
ExplorerSettings(
followLocation = prefs[KEY_FOLLOW] ?: true
)
}
suspend fun setFollowLocation(enabled: Boolean) {
context.explorerDataStore.edit { prefs ->
prefs[KEY_FOLLOW] = enabled
}
}
}