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

Commit 198ac2da authored by Alejandro Nijamkin's avatar Alejandro Nijamkin
Browse files

[flexiglass] Adds instantly(Show|Hide)Overlay to SceneInteractor

Fix: 394632852
Test: unit tests added
Flag: com.android.systemui.scene_container
Change-Id: Ifba461b2149e4125b0e0ea9f178a2e4ad86a93b3
parent e0361336
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -59,10 +59,7 @@ class SceneTransitionLayoutDataSource(
                initialValue = emptySet(),
            )

    override fun changeScene(
        toScene: SceneKey,
        transitionKey: TransitionKey?,
    ) {
    override fun changeScene(toScene: SceneKey, transitionKey: TransitionKey?) {
        state.setTargetScene(
            targetScene = toScene,
            transitionKey = transitionKey,
@@ -71,9 +68,7 @@ class SceneTransitionLayoutDataSource(
    }

    override fun snapToScene(toScene: SceneKey) {
        state.snapToScene(
            scene = toScene,
        )
        state.snapToScene(scene = toScene)
    }

    override fun showOverlay(overlay: OverlayKey, transitionKey: TransitionKey?) {
@@ -100,4 +95,18 @@ class SceneTransitionLayoutDataSource(
            transitionKey = transitionKey,
        )
    }

    override fun instantlyShowOverlay(overlay: OverlayKey) {
        state.snapToScene(
            scene = state.transitionState.currentScene,
            currentOverlays = state.currentOverlays + overlay,
        )
    }

    override fun instantlyHideOverlay(overlay: OverlayKey) {
        state.snapToScene(
            scene = state.transitionState.currentScene,
            currentOverlays = state.currentOverlays - overlay,
        )
    }
}
+38 −0
Original line number Diff line number Diff line
@@ -675,4 +675,42 @@ class SceneInteractorTest : SysuiTestCase() {
            runCurrent()
            underTest.showOverlay(Overlays.QuickSettingsShade, "reason")
        }

    @Test
    fun instantlyShowOverlay() =
        kosmos.runTest {
            enableDualShade()
            runCurrent()
            val currentScene by collectLastValue(underTest.currentScene)
            val currentOverlays by collectLastValue(underTest.currentOverlays)
            val originalScene = currentScene
            assertThat(currentOverlays).isEmpty()

            val overlay = Overlays.NotificationsShade
            underTest.instantlyShowOverlay(overlay, "reason")
            runCurrent()

            assertThat(currentScene).isEqualTo(originalScene)
            assertThat(currentOverlays).contains(overlay)
        }

    @Test
    fun instantlyHideOverlay() =
        kosmos.runTest {
            enableDualShade()
            runCurrent()
            val currentScene by collectLastValue(underTest.currentScene)
            val currentOverlays by collectLastValue(underTest.currentOverlays)
            val overlay = Overlays.QuickSettingsShade
            underTest.showOverlay(overlay, "reason")
            runCurrent()
            val originalScene = currentScene
            assertThat(currentOverlays).contains(overlay)

            underTest.instantlyHideOverlay(overlay, "reason")
            runCurrent()

            assertThat(currentScene).isEqualTo(originalScene)
            assertThat(currentOverlays).isEmpty()
        }
}
+4 −0
Original line number Diff line number Diff line
@@ -147,5 +147,9 @@ constructor(
            to: OverlayKey,
            transitionKey: TransitionKey?,
        ) = Unit

        override fun instantlyShowOverlay(overlay: OverlayKey) = Unit

        override fun instantlyHideOverlay(overlay: OverlayKey) = Unit
    }
}
+20 −0
Original line number Diff line number Diff line
@@ -130,6 +130,26 @@ constructor(
        dataSource.replaceOverlay(from = from, to = to, transitionKey = transitionKey)
    }

    /**
     * Instantly shows [overlay].
     *
     * The change is instantaneous and not animated; it will be observable in the next frame and
     * there will be no transition animation.
     */
    fun instantlyShowOverlay(overlay: OverlayKey) {
        dataSource.instantlyShowOverlay(overlay)
    }

    /**
     * Instantly hides [overlay].
     *
     * The change is instantaneous and not animated; it will be observable in the next frame and
     * there will be no transition animation.
     */
    fun instantlyHideOverlay(overlay: OverlayKey) {
        dataSource.instantlyHideOverlay(overlay)
    }

    /** Sets whether the container is visible. */
    fun setVisible(isVisible: Boolean) {
        _isVisible.value = isVisible
+32 −0
Original line number Diff line number Diff line
@@ -338,6 +338,38 @@ constructor(
        repository.hideOverlay(overlay = overlay, transitionKey = transitionKey)
    }

    /**
     * Instantly shows [overlay].
     *
     * The change is instantaneous and not animated; it will be observable in the next frame and
     * there will be no transition animation.
     */
    fun instantlyShowOverlay(overlay: OverlayKey, loggingReason: String) {
        if (!validateOverlayChange(to = overlay, loggingReason = loggingReason)) {
            return
        }

        logger.logOverlayChangeRequested(to = overlay, reason = loggingReason)

        repository.instantlyShowOverlay(overlay)
    }

    /**
     * Instantly hides [overlay].
     *
     * The change is instantaneous and not animated; it will be observable in the next frame and
     * there will be no transition animation.
     */
    fun instantlyHideOverlay(overlay: OverlayKey, loggingReason: String) {
        if (!validateOverlayChange(from = overlay, loggingReason = loggingReason)) {
            return
        }

        logger.logOverlayChangeRequested(from = overlay, reason = loggingReason)

        repository.instantlyHideOverlay(overlay)
    }

    /**
     * Replace [from] by [to] so that [from] ends up not being visible on screen and [to] ends up
     * being visible.
Loading