Auto commit Sat Mar 21 11:01:02 PM CDT 2026
This commit is contained in:
@@ -7,7 +7,6 @@ import androidx.datastore.preferences.core.intPreferencesKey
|
||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||
import androidx.datastore.preferences.preferencesDataStore
|
||||
import com.mindmachine.mvp.domain.AppSettings
|
||||
import com.mindmachine.mvp.domain.CountdownPreference
|
||||
import com.mindmachine.mvp.domain.SessionMode
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
@@ -19,8 +18,10 @@ class SettingsRepository(private val context: Context) {
|
||||
val safetyAcknowledged = booleanPreferencesKey("safety_ack")
|
||||
val safetyVersion = intPreferencesKey("safety_version")
|
||||
val countdownPref = stringPreferencesKey("countdown_pref")
|
||||
val countdownSeconds = intPreferencesKey("countdown_seconds")
|
||||
val defaultMode = stringPreferencesKey("default_mode")
|
||||
val showGuidance = booleanPreferencesKey("show_guidance")
|
||||
val showImmersiveProgressBar = booleanPreferencesKey("show_immersive_progress_bar")
|
||||
val lastPresetId = stringPreferencesKey("last_preset")
|
||||
}
|
||||
|
||||
@@ -28,9 +29,12 @@ class SettingsRepository(private val context: Context) {
|
||||
AppSettings(
|
||||
safetyAcknowledged = p[Keys.safetyAcknowledged] ?: false,
|
||||
safetyAcknowledgedVersion = p[Keys.safetyVersion] ?: 0,
|
||||
countdownPreference = runCatching { CountdownPreference.valueOf(p[Keys.countdownPref] ?: "FIVE") }.getOrDefault(CountdownPreference.FIVE),
|
||||
countdownSeconds = p[Keys.countdownSeconds]
|
||||
?: legacyCountdownStringToSeconds(p[Keys.countdownPref])
|
||||
?: 5,
|
||||
defaultModePreference = runCatching { SessionMode.valueOf(p[Keys.defaultMode] ?: "AUDIO_VISUAL") }.getOrDefault(SessionMode.AUDIO_VISUAL),
|
||||
showHolderGuidanceBeforeSession = p[Keys.showGuidance] ?: false,
|
||||
showImmersiveProgressBar = p[Keys.showImmersiveProgressBar] ?: true,
|
||||
lastPresetId = p[Keys.lastPresetId],
|
||||
)
|
||||
}
|
||||
@@ -42,8 +46,19 @@ class SettingsRepository(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updateCountdown(value: CountdownPreference) = context.dataStore.edit { it[Keys.countdownPref] = value.name }
|
||||
suspend fun updateCountdownSeconds(value: Int) = context.dataStore.edit {
|
||||
it[Keys.countdownSeconds] = value.coerceIn(0, 10)
|
||||
}
|
||||
|
||||
suspend fun updateDefaultMode(value: SessionMode) = context.dataStore.edit { it[Keys.defaultMode] = value.name }
|
||||
suspend fun updateGuidance(value: Boolean) = context.dataStore.edit { it[Keys.showGuidance] = value }
|
||||
suspend fun updateShowImmersiveProgressBar(value: Boolean) = context.dataStore.edit { it[Keys.showImmersiveProgressBar] = value }
|
||||
suspend fun updateLastPreset(id: String) = context.dataStore.edit { it[Keys.lastPresetId] = id }
|
||||
|
||||
private fun legacyCountdownStringToSeconds(raw: String?): Int? = when (raw) {
|
||||
"OFF" -> 0
|
||||
"FIVE" -> 5
|
||||
"TEN" -> 10
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user