1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.scene.data.repository
18 
19 import com.android.compose.animation.scene.ObservableTransitionState
20 import com.android.compose.animation.scene.SceneKey
21 import com.android.systemui.kosmos.Kosmos
22 import com.android.systemui.kosmos.testScope
23 import com.android.systemui.scene.shared.model.Scenes
24 import kotlinx.coroutines.flow.Flow
25 import kotlinx.coroutines.flow.MutableStateFlow
26 import kotlinx.coroutines.flow.flowOf
27 import kotlinx.coroutines.test.TestScope
28 import kotlinx.coroutines.test.runCurrent
29 
30 private val mutableTransitionState =
31     MutableStateFlow<ObservableTransitionState>(ObservableTransitionState.Idle(Scenes.Lockscreen))
32 
setSceneTransitionnull33 fun Kosmos.setSceneTransition(
34     transition: ObservableTransitionState,
35     scope: TestScope = testScope,
36     repository: SceneContainerRepository = sceneContainerRepository
37 ) {
38     repository.setTransitionState(mutableTransitionState)
39     mutableTransitionState.value = transition
40     scope.runCurrent()
41 }
42 
Transitionnull43 fun Transition(
44     from: SceneKey,
45     to: SceneKey,
46     currentScene: Flow<SceneKey> = flowOf(to),
47     progress: Flow<Float> = flowOf(0f),
48     isInitiatedByUserInput: Boolean = false,
49     isUserInputOngoing: Flow<Boolean> = flowOf(false),
50 ): ObservableTransitionState.Transition {
51     return ObservableTransitionState.Transition(
52         fromScene = from,
53         toScene = to,
54         currentScene = currentScene,
55         progress = progress,
56         isInitiatedByUserInput = isInitiatedByUserInput,
57         isUserInputOngoing = isUserInputOngoing
58     )
59 }
60 
Idlenull61 fun Idle(currentScene: SceneKey): ObservableTransitionState.Idle {
62     return ObservableTransitionState.Idle(currentScene)
63 }
64