feat: 优化flow订阅策略

This commit is contained in:
2025-11-27 17:40:43 +08:00
parent 0c122b9352
commit 84961a367c
8 changed files with 44 additions and 52 deletions
@@ -8,6 +8,7 @@ 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() {
@@ -25,7 +26,7 @@ class SettingViewModel : ViewModel() {
}
}.shareIn(
scope = viewModelScope,
started = SharingStarted.Eagerly,
started = SharingStarted.WhileSubscribed(5.seconds.inWholeMilliseconds),
replay = 1
)
@@ -43,26 +44,26 @@ class SettingViewModel : ViewModel() {
}
}.shareIn(
scope = viewModelScope,
started = SharingStarted.Eagerly,
started = SharingStarted.WhileSubscribed(5.seconds.inWholeMilliseconds),
replay = 1
)
fun brightnessAdd(){
fun brightnessAdd() {
AppDependencies.deviceServiceManager.brightnessAdd()
}
fun brightnessSubtract(){
fun brightnessSubtract() {
AppDependencies.deviceServiceManager.brightnessSubtract()
}
fun volumeAdd(){
fun volumeAdd() {
AppDependencies.deviceServiceManager.volumeAdd()
}
fun volumeSubtract(){
fun volumeSubtract() {
AppDependencies.deviceServiceManager.volumeSubtract()
}
fun deviceSn()= AppDependencies.deviceServiceManager.sn
fun deviceSn() = AppDependencies.deviceServiceManager.sn
}