Rokid/app/src/main/java/com/yuanxuan/rokid/ui/SettingViewModel.kt

69 lines
2.2 KiB
Kotlin

package com.yuanxuan.rokid.ui
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.yuanxuan.rokid.dependencies.AppDependencies
import com.yuanxuan.rokid.device.DeviceServiceManager
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.shareIn
import kotlin.time.Duration.Companion.seconds
class SettingViewModel : ViewModel() {
val volumeFlow: SharedFlow<List<SeekBarAdapter.SeekBarBean>> =
AppDependencies.deviceServiceManager.volume.map { volume ->
buildList {
(1..DeviceServiceManager.MAX_VOLUME).map { i ->
add(
SeekBarAdapter.SeekBarBean(
value = i,
checked = i <= volume
)
)
}
}
}.shareIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5.seconds.inWholeMilliseconds),
replay = 1
)
val brightnessFlow: SharedFlow<List<SeekBarAdapter.SeekBarBean>> =
AppDependencies.deviceServiceManager.brightness.map { volume ->
buildList {
(1..DeviceServiceManager.MAX_BRIGHTNESS).map { i ->
add(
SeekBarAdapter.SeekBarBean(
value = i,
checked = i <= volume
)
)
}
}
}.shareIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5.seconds.inWholeMilliseconds),
replay = 1
)
fun brightnessAdd() {
AppDependencies.deviceServiceManager.brightnessAdd()
}
fun brightnessSubtract() {
AppDependencies.deviceServiceManager.brightnessSubtract()
}
fun volumeAdd() {
AppDependencies.deviceServiceManager.volumeAdd()
}
fun volumeSubtract() {
AppDependencies.deviceServiceManager.volumeSubtract()
}
fun deviceSn() = AppDependencies.deviceServiceManager.sn
}