mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 23:21:59 +01:00
choose the stream bitrate and format from settings
This commit is contained in:
@@ -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) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user