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

Commit 7b67cd32 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Rename ObservableTransitionState.{from,to}Scene to {from,to}Content

Bug: 353679003
Test: Existing tests (pure refactoring)
Flag: com.android.systemui.scene_container
Change-Id: Ie6e234f80114dfcc28ccaeaadc89f083d7919162
parent 86128b7f
Loading
Loading
Loading
Loading
+8 −12
Original line number Diff line number Diff line
@@ -31,9 +31,6 @@ import kotlinx.coroutines.flow.flowOf
 *    layout or Compose drawing phases.
 * 2. [ObservableTransitionState] values are backed by Kotlin [Flow]s and can be collected by
 *    non-Compose code to observe value changes.
 * 3. [ObservableTransitionState.Transition.fromScene] and
 *    [ObservableTransitionState.Transition.toScene] will never be equal, while
 *    [TransitionState.Transition.fromScene] and [TransitionState.Transition.toScene] can be equal.
 */
sealed interface ObservableTransitionState {
    /**
@@ -54,9 +51,8 @@ sealed interface ObservableTransitionState {

    /** There is a transition animating between two scenes. */
    sealed class Transition(
        // TODO(b/353679003): Rename these to fromContent and toContent.
        open val fromScene: ContentKey,
        open val toScene: ContentKey,
        val fromContent: ContentKey,
        val toContent: ContentKey,
        val currentOverlays: Flow<Set<OverlayKey>>,
        val progress: Flow<Float>,

@@ -86,8 +82,8 @@ sealed interface ObservableTransitionState {
    ) : ObservableTransitionState {
        override fun toString(): String =
            """Transition
                |(from=$fromScene,
                | to=$toScene,
                |(from=$fromContent,
                | to=$toContent,
                | isInitiatedByUserInput=$isInitiatedByUserInput,
                | isUserInputOngoing=$isUserInputOngoing
                |)"""
@@ -95,8 +91,8 @@ sealed interface ObservableTransitionState {

        /** A transition animating between [fromScene] and [toScene]. */
        class ChangeScene(
            override val fromScene: SceneKey,
            override val toScene: SceneKey,
            val fromScene: SceneKey,
            val toScene: SceneKey,
            val currentScene: Flow<SceneKey>,
            currentOverlays: Flow<Set<OverlayKey>>,
            progress: Flow<Float>,
@@ -196,8 +192,8 @@ sealed interface ObservableTransitionState {

    fun isTransitioning(from: ContentKey? = null, to: ContentKey? = null): Boolean {
        return this is Transition &&
            (from == null || this.fromScene == from) &&
            (to == null || this.toScene == to)
            (from == null || this.fromContent == from) &&
            (to == null || this.toContent == to)
    }
}

+6 −6
Original line number Diff line number Diff line
@@ -90,16 +90,16 @@ class ObservableTransitionStateTest {
            at(0) {
                val state = observableState()
                assertThat(state).isInstanceOf(ObservableTransitionState.Transition::class.java)
                assertThat((state as ObservableTransitionState.Transition).fromScene)
                assertThat((state as ObservableTransitionState.Transition).fromContent)
                    .isEqualTo(SceneA)
                assertThat(state.toScene).isEqualTo(SceneB)
                assertThat(state.toContent).isEqualTo(SceneB)
                assertThat(state.progress()).isEqualTo(0f)
            }
            at(TestTransitionDuration / 2) {
                val state = observableState()
                assertThat((state as ObservableTransitionState.Transition).fromScene)
                assertThat((state as ObservableTransitionState.Transition).fromContent)
                    .isEqualTo(SceneA)
                assertThat(state.toScene).isEqualTo(SceneB)
                assertThat(state.toContent).isEqualTo(SceneB)
                assertThat(state.progress()).isEqualTo(0.5f)
            }
            after {
@@ -200,7 +200,7 @@ class ObservableTransitionStateTest {

        var state = observableState()
        assertThat(state).isInstanceOf(ObservableTransitionState.Transition::class.java)
        assertThat((state as ObservableTransitionState.Transition).fromScene).isEqualTo(SceneA)
        assertThat((state as ObservableTransitionState.Transition).fromContent).isEqualTo(SceneA)
        assertThat(state.previewProgress()).isEqualTo(0.4f)
        assertThat(state.isInPreviewStage()).isEqualTo(true)

@@ -218,7 +218,7 @@ class ObservableTransitionStateTest {
        }
        state = observableState()
        assertThat(state).isInstanceOf(ObservableTransitionState.Transition::class.java)
        assertThat((state as ObservableTransitionState.Transition).fromScene).isEqualTo(SceneA)
        assertThat((state as ObservableTransitionState.Transition).fromContent).isEqualTo(SceneA)
        assertThat(state.previewProgress()).isEqualTo(0.4f)
        assertThat(state.isInPreviewStage()).isEqualTo(false)

+1 −1
Original line number Diff line number Diff line
@@ -195,7 +195,7 @@ constructor(
                    is ObservableTransitionState.Idle ->
                        flowOf(CommunalTransitionProgressModel.Idle(state.currentScene))
                    is ObservableTransitionState.Transition ->
                        if (state.toScene == targetScene) {
                        if (state.toContent == targetScene) {
                            state.progress.map {
                                CommunalTransitionProgressModel.Transition(
                                    // Clamp the progress values between 0 and 1 as actual progress
+6 −4
Original line number Diff line number Diff line
@@ -161,7 +161,7 @@ constructor(
        if (
            prevTransition is ObservableTransitionState.Transition &&
                currentTransitionId != null &&
                idle.currentScene == prevTransition.toScene
                idle.currentScene == prevTransition.toContent
        ) {
            finishCurrentTransition()
        } else {
@@ -219,17 +219,19 @@ constructor(
        prevTransition: ObservableTransitionState,
        transition: ObservableTransitionState.Transition
    ) {
        if (prevTransition.isTransitioning(from = transition.fromScene, to = transition.toScene)) {
        if (
            prevTransition.isTransitioning(from = transition.fromContent, to = transition.toContent)
        ) {
            // This is a new transition, but exactly the same as the previous state. Skip resetting
            // KTF for this case and just collect the new progress instead.
            collectProgress(transition)
        } else if (transition.toScene == CommunalScenes.Communal) {
        } else if (transition.toContent == CommunalScenes.Communal) {
            if (currentToState == KeyguardState.GLANCEABLE_HUB) {
                transitionKtfTo(transitionInteractor.startedKeyguardTransitionStep.value.from)
            }
            startTransitionToGlanceableHub()
            collectProgress(transition)
        } else if (transition.toScene == CommunalScenes.Blank) {
        } else if (transition.toContent == CommunalScenes.Blank) {
            // Another transition started before this one is completed. Transition to the
            // GLANCEABLE_HUB state so that we can properly transition away from it.
            transitionKtfTo(KeyguardState.GLANCEABLE_HUB)
+2 −2
Original line number Diff line number Diff line
@@ -126,13 +126,13 @@ private fun ObservableTransitionState.isNotOnCommunal(): Boolean {
/** Whether currently transitioning from another scene to communal. */
private fun ObservableTransitionState.isSwipingToCommunal(): Boolean {
    return this is ObservableTransitionState.Transition &&
        toScene == CommunalScenes.Communal &&
        toContent == CommunalScenes.Communal &&
        isInitiatedByUserInput
}

/** Whether currently transitioning from communal to another scene. */
private fun ObservableTransitionState.isSwipingFromCommunal(): Boolean {
    return this is ObservableTransitionState.Transition &&
        fromScene == CommunalScenes.Communal &&
        fromContent == CommunalScenes.Communal &&
        isInitiatedByUserInput
}
Loading