new: persist preferences across sessions

This commit is contained in:
2026-07-03 13:48:29 +02:00
parent beb1973978
commit d2283ae347
12 changed files with 212 additions and 24 deletions
@@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.WhileSubscribed
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import kotlin.math.roundToInt
@@ -77,8 +78,9 @@ class PlayerViewModel(
}
}
private fun applyCurrentSpeed() {
playbackRepository.setSpeed(preferencesRepository.playbackPreferences.value.speed)
private suspend fun applyCurrentSpeed() {
val playbackPreferences = preferencesRepository.playbackPreferences.firstOrNull() ?: return
playbackRepository.setSpeed(playbackPreferences.speed)
}
fun performMainPlayAction() {
@@ -111,16 +113,22 @@ class PlayerViewModel(
PlaybackPreferences.MIN_SPEED,
PlaybackPreferences.MAX_SPEED,
)
preferencesRepository.setPlaybackSpeed(clampedSpeed)
playbackRepository.setSpeed(clampedSpeed)
viewModelScope.launch {
preferencesRepository.setPlaybackSpeed(clampedSpeed)
playbackRepository.setSpeed(clampedSpeed)
}
}
fun setShowTranscription(enabled: Boolean) {
preferencesRepository.setShowTranscription(enabled)
viewModelScope.launch {
preferencesRepository.setShowTranscription(enabled)
}
}
fun setShowTranslation(enabled: Boolean) {
preferencesRepository.setShowTranslation(enabled)
viewModelScope.launch {
preferencesRepository.setShowTranslation(enabled)
}
}
fun stop() {