42 lines
1.4 KiB
Kotlin
42 lines
1.4 KiB
Kotlin
package de.waypointaudio.data
|
|
|
|
import android.content.Context
|
|
import androidx.datastore.preferences.core.edit
|
|
import androidx.datastore.preferences.core.stringPreferencesKey
|
|
import androidx.datastore.preferences.preferencesDataStore
|
|
import kotlinx.coroutines.flow.Flow
|
|
import kotlinx.coroutines.flow.map
|
|
|
|
/**
|
|
* v2.5.9 — Persistiert die vom Nutzer akzeptierte Version der
|
|
* Nutzungsbedingungen. Wird beim ersten App-Start abgefragt; eine
|
|
* neue Terms-Version (z. B. „2.5.11-terms-1") führt zur erneuten
|
|
* Anzeige des Zustimmungsdialogs.
|
|
*/
|
|
private val Context.termsDataStore by preferencesDataStore(name = "terms_settings")
|
|
|
|
object TermsVersions {
|
|
/**
|
|
* Aktuell gültige Terms-Version. Beim Bump dieser Konstante muss
|
|
* der In-App-Dialog beim nächsten Start neu zustimmen lassen.
|
|
*/
|
|
const val CURRENT = "2.5.11-terms-1"
|
|
}
|
|
|
|
class TermsStore(private val context: Context) {
|
|
|
|
private companion object {
|
|
val KEY_ACCEPTED_VERSION = stringPreferencesKey("accepted_terms_version")
|
|
}
|
|
|
|
/** Zuletzt akzeptierte Terms-Version (Leerstring = noch nie akzeptiert). */
|
|
val acceptedVersion: Flow<String> = context.termsDataStore.data
|
|
.map { it[KEY_ACCEPTED_VERSION] ?: "" }
|
|
|
|
suspend fun setAccepted(version: String) {
|
|
context.termsDataStore.edit { prefs ->
|
|
prefs[KEY_ACCEPTED_VERSION] = version
|
|
}
|
|
}
|
|
}
|