feat: 优化flow订阅策略
This commit is contained in:
@@ -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
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user