choose the stream bitrate and format from settings

This commit is contained in:
austinried
2026-10-04 00:29:51 +00:00
parent 6e4e911f95
commit 659df47c14
11 changed files with 221 additions and 12 deletions
@@ -3,6 +3,7 @@ package com.subtracks.ui.settings
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.subtracks.data.model.Source
import com.subtracks.data.prefs.UserPreferences
import com.subtracks.data.repo.SourceRepository
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
@@ -11,6 +12,7 @@ import kotlinx.coroutines.launch
class SettingsViewModel(
private val sourceRepository: SourceRepository,
private val userPreferences: UserPreferences,
) : ViewModel() {
val sources: StateFlow<List<Source>> =
sourceRepository.sources().stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())
@@ -18,6 +20,14 @@ class SettingsViewModel(
val activeSourceId: StateFlow<Long?> =
sourceRepository.activeSourceId().stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), null)
val maxBitrate: StateFlow<Int> =
userPreferences.maxBitrate
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), 0)
val streamFormat: StateFlow<String?> =
userPreferences.streamFormat
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), null)
fun selectSource(id: Long) {
viewModelScope.launch { sourceRepository.selectSource(id) }
}
@@ -25,4 +35,12 @@ class SettingsViewModel(
fun deleteSource(id: Long) {
viewModelScope.launch { sourceRepository.deleteSource(id) }
}
fun setMaxBitrate(kbps: Int) {
viewModelScope.launch { userPreferences.setMaxBitrate(kbps) }
}
fun setStreamFormat(format: String?) {
viewModelScope.launch { userPreferences.setStreamFormat(format) }
}
}