https://kotlinlang.org logo
#codereview
Title
# codereview
n

Nick

08/18/2021, 3:18 PM
I have a property called captureMode which observes on a camera
StateFlow
and change it’s value when the camera changes. Additionally, I want to be able to set captureMode manually. But since captureMode is a stateFlow, I can’t set it. Is there a better way?
e

eneim

08/19/2021, 7:23 AM
How about:
Copy code
val mutableCaptureMode = MutableStateFlow<CaptureMode?>(null)

private val captureMode = camera.combine(mutableCaptureMode) { item, mutableMode ->
     if (mutableMode != null) emit(mutableMode)
     else if (item.foo) {
         emit(CaptureMode.Panoramic)
     } else {
         emit(CaptureMode.Standard)
     }
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), CaptureMode.Panoramic)

fun setCaptureMode(mode: CaptureMode) { mutableCaptureMode.value = mode }
n

Nick

08/19/2021, 2:17 PM
genius! 🧠
thanks!
5 Views