feat: 基础功能
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
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
|
||||
|
||||
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.Eagerly,
|
||||
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.Eagerly,
|
||||
replay = 1
|
||||
)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user