Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 62b26c0c authored by Ale Nijamkin's avatar Ale Nijamkin Committed by Android (Google) Code Review
Browse files

Merge "[flexiglass] Introduces a previousScene flow." into main

parents 2e58e2d9 6f6b35d0
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -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)
        }
}
+15 −0
Original line number Diff line number Diff line
@@ -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)
        }
}
+29 −1
Original line number Diff line number Diff line
@@ -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
@@ -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. */
@@ -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()
+8 −0
Original line number Diff line number Diff line
@@ -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.
     *