• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download

<lambda>null1 package com.android.systemui.communal.data.repository
2 
3 import android.content.res.Configuration
4 import com.android.compose.animation.scene.ObservableTransitionState
5 import com.android.compose.animation.scene.SceneKey
6 import com.android.compose.animation.scene.TransitionKey
7 import com.android.systemui.communal.shared.model.CommunalScenes
8 import kotlinx.coroutines.CoroutineScope
9 import kotlinx.coroutines.flow.Flow
10 import kotlinx.coroutines.flow.MutableStateFlow
11 import kotlinx.coroutines.flow.SharingStarted
12 import kotlinx.coroutines.flow.StateFlow
13 import kotlinx.coroutines.flow.asStateFlow
14 import kotlinx.coroutines.flow.flatMapLatest
15 import kotlinx.coroutines.flow.flowOf
16 import kotlinx.coroutines.flow.stateIn
17 import kotlinx.coroutines.launch
18 
19 /** Fake implementation of [CommunalSceneRepository]. */
20 class FakeCommunalSceneRepository(
21     private val applicationScope: CoroutineScope,
22     override val currentScene: MutableStateFlow<SceneKey> = MutableStateFlow(CommunalScenes.Default),
23 ) : CommunalSceneRepository {
24 
25     override fun changeScene(toScene: SceneKey, transitionKey: TransitionKey?) =
26         snapToScene(toScene)
27 
28     override fun snapToScene(toScene: SceneKey) {
29         applicationScope.launch {
30             currentScene.value = toScene
31             _transitionState.value = flowOf(ObservableTransitionState.Idle(toScene))
32         }
33     }
34 
35     private val defaultTransitionState = ObservableTransitionState.Idle(CommunalScenes.Default)
36     private val _transitionState = MutableStateFlow<Flow<ObservableTransitionState>?>(null)
37     override val transitionState: StateFlow<ObservableTransitionState> =
38         _transitionState
39             .flatMapLatest { innerFlowOrNull -> innerFlowOrNull ?: flowOf(defaultTransitionState) }
40             .stateIn(
41                 scope = applicationScope,
42                 started = SharingStarted.Eagerly,
43                 initialValue = defaultTransitionState,
44             )
45 
46     override fun setTransitionState(transitionState: Flow<ObservableTransitionState>?) {
47         _transitionState.value = transitionState
48     }
49 
50     private val _communalContainerOrientation =
51         MutableStateFlow(Configuration.ORIENTATION_UNDEFINED)
52     override val communalContainerOrientation: StateFlow<Int> =
53         _communalContainerOrientation.asStateFlow()
54 
55     override fun setCommunalContainerOrientation(orientation: Int) {
56         _communalContainerOrientation.value = orientation
57     }
58 }
59