Auto commit Sat Mar 21 11:01:02 PM CDT 2026

This commit is contained in:
Tretzi
2026-03-21 23:01:02 -05:00
parent 5c48387dc2
commit 869c98a47c
11 changed files with 354 additions and 104 deletions

View File

@@ -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
}
}