Loading packages/SystemUI/multivalentTests/src/com/android/systemui/scene/data/repository/SceneContainerRepositoryTest.kt +19 −0 Original line number Diff line number Diff line Loading @@ -140,4 +140,23 @@ class SceneContainerRepositoryTest : SysuiTestCase() { ObservableTransitionState.Idle(kosmos.sceneContainerConfig.initialSceneKey) ) } @Test fun previousScene() = testScope.runTest { val underTest = kosmos.sceneContainerRepository val currentScene by collectLastValue(underTest.currentScene) val previousScene by collectLastValue(underTest.previousScene) assertThat(previousScene).isNull() val firstScene = currentScene underTest.changeScene(Scenes.Shade) assertThat(previousScene).isEqualTo(firstScene) assertThat(currentScene).isEqualTo(Scenes.Shade) underTest.changeScene(Scenes.QuickSettings) assertThat(previousScene).isEqualTo(Scenes.Shade) assertThat(currentScene).isEqualTo(Scenes.QuickSettings) } } packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/interactor/SceneInteractorTest.kt +15 −0 Original line number Diff line number Diff line Loading @@ -291,4 +291,19 @@ class SceneInteractorTest : SysuiTestCase() { assertThat(isVisible).isFalse() } @Test fun previousScene() = testScope.runTest { val currentScene by collectLastValue(underTest.currentScene) val previousScene by collectLastValue(underTest.previousScene) assertThat(previousScene).isNull() val firstScene = currentScene underTest.changeScene(toScene = Scenes.Shade, "reason") assertThat(previousScene).isEqualTo(firstScene) underTest.changeScene(toScene = Scenes.QuickSettings, "reason") assertThat(previousScene).isEqualTo(Scenes.Shade) } } packages/SystemUI/src/com/android/systemui/scene/data/repository/SceneContainerRepository.kt +29 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ import com.android.compose.animation.scene.TransitionKey import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.scene.shared.model.SceneContainerConfig import com.android.systemui.scene.shared.model.SceneDataSource import com.android.systemui.util.kotlin.WithPrev import com.android.systemui.util.kotlin.pairwise import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi Loading @@ -34,6 +36,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn /** Source of truth for scene framework application state. */ Loading @@ -44,7 +47,32 @@ constructor( private val config: SceneContainerConfig, private val dataSource: SceneDataSource, ) { val currentScene: StateFlow<SceneKey> = dataSource.currentScene private val previousAndCurrentScene: StateFlow<WithPrev<SceneKey?, SceneKey>> = dataSource.currentScene .pairwise() .stateIn( scope = applicationScope, started = SharingStarted.WhileSubscribed(), initialValue = WithPrev(null, dataSource.currentScene.value), ) val currentScene: StateFlow<SceneKey> = previousAndCurrentScene .map { it.newValue } .stateIn( scope = applicationScope, started = SharingStarted.WhileSubscribed(), initialValue = previousAndCurrentScene.value.newValue, ) val previousScene: StateFlow<SceneKey?> = previousAndCurrentScene .map { it.previousValue } .stateIn( scope = applicationScope, started = SharingStarted.WhileSubscribed(), initialValue = previousAndCurrentScene.value.previousValue, ) private val _isVisible = MutableStateFlow(true) val isVisible: StateFlow<Boolean> = _isVisible.asStateFlow() Loading packages/SystemUI/src/com/android/systemui/scene/domain/interactor/SceneInteractor.kt +8 −0 Original line number Diff line number Diff line Loading @@ -139,6 +139,14 @@ constructor( initialValue = isVisibleInternal() ) /** * The previous scene. * * This is effectively the previous value of [currentScene] which means that all caveats, for * example regarding when in a transition the current scene changes, apply. */ val previousScene: StateFlow<SceneKey?> = repository.previousScene /** * Returns the keys of all scenes in the container. * Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/scene/data/repository/SceneContainerRepositoryTest.kt +19 −0 Original line number Diff line number Diff line Loading @@ -140,4 +140,23 @@ class SceneContainerRepositoryTest : SysuiTestCase() { ObservableTransitionState.Idle(kosmos.sceneContainerConfig.initialSceneKey) ) } @Test fun previousScene() = testScope.runTest { val underTest = kosmos.sceneContainerRepository val currentScene by collectLastValue(underTest.currentScene) val previousScene by collectLastValue(underTest.previousScene) assertThat(previousScene).isNull() val firstScene = currentScene underTest.changeScene(Scenes.Shade) assertThat(previousScene).isEqualTo(firstScene) assertThat(currentScene).isEqualTo(Scenes.Shade) underTest.changeScene(Scenes.QuickSettings) assertThat(previousScene).isEqualTo(Scenes.Shade) assertThat(currentScene).isEqualTo(Scenes.QuickSettings) } }
packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/interactor/SceneInteractorTest.kt +15 −0 Original line number Diff line number Diff line Loading @@ -291,4 +291,19 @@ class SceneInteractorTest : SysuiTestCase() { assertThat(isVisible).isFalse() } @Test fun previousScene() = testScope.runTest { val currentScene by collectLastValue(underTest.currentScene) val previousScene by collectLastValue(underTest.previousScene) assertThat(previousScene).isNull() val firstScene = currentScene underTest.changeScene(toScene = Scenes.Shade, "reason") assertThat(previousScene).isEqualTo(firstScene) underTest.changeScene(toScene = Scenes.QuickSettings, "reason") assertThat(previousScene).isEqualTo(Scenes.Shade) } }
packages/SystemUI/src/com/android/systemui/scene/data/repository/SceneContainerRepository.kt +29 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ import com.android.compose.animation.scene.TransitionKey import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.scene.shared.model.SceneContainerConfig import com.android.systemui.scene.shared.model.SceneDataSource import com.android.systemui.util.kotlin.WithPrev import com.android.systemui.util.kotlin.pairwise import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi Loading @@ -34,6 +36,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn /** Source of truth for scene framework application state. */ Loading @@ -44,7 +47,32 @@ constructor( private val config: SceneContainerConfig, private val dataSource: SceneDataSource, ) { val currentScene: StateFlow<SceneKey> = dataSource.currentScene private val previousAndCurrentScene: StateFlow<WithPrev<SceneKey?, SceneKey>> = dataSource.currentScene .pairwise() .stateIn( scope = applicationScope, started = SharingStarted.WhileSubscribed(), initialValue = WithPrev(null, dataSource.currentScene.value), ) val currentScene: StateFlow<SceneKey> = previousAndCurrentScene .map { it.newValue } .stateIn( scope = applicationScope, started = SharingStarted.WhileSubscribed(), initialValue = previousAndCurrentScene.value.newValue, ) val previousScene: StateFlow<SceneKey?> = previousAndCurrentScene .map { it.previousValue } .stateIn( scope = applicationScope, started = SharingStarted.WhileSubscribed(), initialValue = previousAndCurrentScene.value.previousValue, ) private val _isVisible = MutableStateFlow(true) val isVisible: StateFlow<Boolean> = _isVisible.asStateFlow() Loading
packages/SystemUI/src/com/android/systemui/scene/domain/interactor/SceneInteractor.kt +8 −0 Original line number Diff line number Diff line Loading @@ -139,6 +139,14 @@ constructor( initialValue = isVisibleInternal() ) /** * The previous scene. * * This is effectively the previous value of [currentScene] which means that all caveats, for * example regarding when in a transition the current scene changes, apply. */ val previousScene: StateFlow<SceneKey?> = repository.previousScene /** * Returns the keys of all scenes in the container. * Loading