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

Commit e722e013 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Remove the Communal fork of STL SceneKey

Bug: 293899074
Test: m sysuig
Test: m SystemUITests
Flag: N/A
Change-Id: I48e12cdb0508fe6a700d8cd5a6c742111a3b6215
parent 2d2f374b
Loading
Loading
Loading
Loading
+11 −36
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import com.android.compose.animation.scene.observableTransitionState
import com.android.compose.animation.scene.transitions
import com.android.compose.animation.scene.updateSceneTransitionLayoutState
import com.android.compose.theme.LocalAndroidColorScheme
import com.android.systemui.communal.shared.model.CommunalSceneKey
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.communal.shared.model.ObservableCommunalTransitionState
import com.android.systemui.communal.ui.compose.extensions.allowGestures
@@ -32,7 +31,6 @@ import com.android.systemui.communal.ui.viewmodel.BaseCommunalViewModel
import com.android.systemui.communal.ui.viewmodel.CommunalViewModel
import com.android.systemui.res.R
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.transform

object Communal {
    object Elements {
@@ -42,7 +40,7 @@ object Communal {
}

val sceneTransitions = transitions {
    to(TransitionSceneKey.Communal) {
    to(CommunalScenes.Communal) {
        spec = tween(durationMillis = 1000)
        translate(Communal.Elements.Content, Edge.Right)
        timestampRange(startMillis = 167, endMillis = 334) {
@@ -50,7 +48,7 @@ val sceneTransitions = transitions {
            fade(Communal.Elements.Content)
        }
    }
    to(TransitionSceneKey.Blank) {
    to(CommunalScenes.Blank) {
        spec = tween(durationMillis = 1000)
        translate(Communal.Elements.Content, Edge.Right)
        timestampRange(endMillis = 167) { fade(Communal.Elements.Content) }
@@ -69,14 +67,11 @@ fun CommunalContainer(
    modifier: Modifier = Modifier,
    viewModel: CommunalViewModel,
) {
    val currentScene: SceneKey by
        viewModel.currentScene
            .transform { value -> emit(value.toTransitionSceneKey()) }
            .collectAsState(TransitionSceneKey.Blank)
    val currentScene: SceneKey by viewModel.currentScene.collectAsState(CommunalScenes.Blank)
    val sceneTransitionLayoutState =
        updateSceneTransitionLayoutState(
            currentScene,
            onChangeScene = { viewModel.onSceneChanged(it.toCommunalSceneKey()) },
            onChangeScene = { viewModel.onSceneChanged(it) },
            transitions = sceneTransitions,
        )
    val touchesAllowed by viewModel.touchesAllowed.collectAsState(initial = false)
@@ -99,11 +94,10 @@ fun CommunalContainer(
            ),
    ) {
        scene(
            TransitionSceneKey.Blank,
            CommunalScenes.Blank,
            userActions =
                mapOf(
                    Swipe(SwipeDirection.Left, fromSource = Edge.Right) to
                        TransitionSceneKey.Communal
                    Swipe(SwipeDirection.Left, fromSource = Edge.Right) to CommunalScenes.Communal
                )
        ) {
            // This scene shows nothing only allowing for transitions to the communal scene.
@@ -111,11 +105,9 @@ fun CommunalContainer(
        }

        scene(
            TransitionSceneKey.Communal,
            CommunalScenes.Communal,
            userActions =
                mapOf(
                    Swipe(SwipeDirection.Right, fromSource = Edge.Left) to TransitionSceneKey.Blank
                ),
                mapOf(Swipe(SwipeDirection.Right, fromSource = Edge.Left) to CommunalScenes.Blank),
        ) {
            CommunalScene(viewModel, modifier = modifier)
        }
@@ -137,22 +129,6 @@ private fun SceneScope.CommunalScene(
    Box(modifier.element(Communal.Elements.Content)) { CommunalHub(viewModel = viewModel) }
}

// TODO(b/315490861): Remove these conversions once Compose can be used throughout SysUI.
object TransitionSceneKey {
    val Blank = CommunalScenes.Blank.toTransitionSceneKey()
    val Communal = CommunalScenes.Communal.toTransitionSceneKey()
}

// TODO(b/315490861): Remove these conversions once Compose can be used throughout SysUI.
fun SceneKey.toCommunalSceneKey(): CommunalSceneKey {
    return this.identity as CommunalSceneKey
}

// TODO(b/315490861): Remove these conversions once Compose can be used throughout SysUI.
fun CommunalSceneKey.toTransitionSceneKey(): SceneKey {
    return SceneKey(debugName = toString(), identity = this)
}

/**
 * Converts between the [SceneTransitionLayout] state class and our forked data class that can be
 * used throughout SysUI.
@@ -160,12 +136,11 @@ fun CommunalSceneKey.toTransitionSceneKey(): SceneKey {
// TODO(b/315490861): Remove these conversions once Compose can be used throughout SysUI.
fun ObservableTransitionState.toModel(): ObservableCommunalTransitionState {
    return when (this) {
        is ObservableTransitionState.Idle ->
            ObservableCommunalTransitionState.Idle(scene.toCommunalSceneKey())
        is ObservableTransitionState.Idle -> ObservableCommunalTransitionState.Idle(scene)
        is ObservableTransitionState.Transition ->
            ObservableCommunalTransitionState.Transition(
                fromScene = fromScene.toCommunalSceneKey(),
                toScene = toScene.toCommunalSceneKey(),
                fromScene = fromScene,
                toScene = toScene,
                progress = progress,
                isInitiatedByUserInput = isInitiatedByUserInput,
                isUserInputOngoing = isUserInputOngoing,
+4 −4
Original line number Diff line number Diff line
@@ -18,12 +18,12 @@ package com.android.systemui.communal.log

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.compose.animation.scene.SceneKey
import com.android.internal.logging.UiEventLogger
import com.android.systemui.SysuiTestCase
import com.android.systemui.communal.domain.interactor.CommunalInteractor
import com.android.systemui.communal.domain.interactor.communalInteractor
import com.android.systemui.communal.shared.log.CommunalUiEvent
import com.android.systemui.communal.shared.model.CommunalSceneKey
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.communal.shared.model.ObservableCommunalTransitionState
import com.android.systemui.kosmos.testScope
@@ -188,8 +188,8 @@ class CommunalLoggerStartableTest : SysuiTestCase() {
        }

    private fun transition(
        from: CommunalSceneKey = CommunalScenes.Default,
        to: CommunalSceneKey = CommunalScenes.Default,
        from: SceneKey = CommunalScenes.Default,
        to: SceneKey = CommunalScenes.Default,
    ): ObservableCommunalTransitionState.Transition {
        return ObservableCommunalTransitionState.Transition(
            fromScene = from,
@@ -200,7 +200,7 @@ class CommunalLoggerStartableTest : SysuiTestCase() {
        )
    }

    private fun idle(sceneKey: CommunalSceneKey): ObservableCommunalTransitionState.Idle {
    private fun idle(sceneKey: SceneKey): ObservableCommunalTransitionState.Idle {
        return ObservableCommunalTransitionState.Idle(sceneKey)
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -16,9 +16,9 @@

package com.android.systemui.communal

import com.android.compose.animation.scene.SceneKey
import com.android.systemui.CoreStartable
import com.android.systemui.communal.domain.interactor.CommunalInteractor
import com.android.systemui.communal.shared.model.CommunalSceneKey
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
@@ -83,7 +83,7 @@ constructor(

    private suspend fun determineSceneAfterTransition(
        lastStartedTransition: TransitionStep,
    ): CommunalSceneKey? {
    ): SceneKey? {
        val to = lastStartedTransition.to
        val from = lastStartedTransition.from
        val docked = dockManager.isDocked
+6 −7
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package com.android.systemui.communal.data.repository

import com.android.systemui.communal.shared.model.CommunalSceneKey
import com.android.compose.animation.scene.SceneKey
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.communal.shared.model.ObservableCommunalTransitionState
import com.android.systemui.dagger.SysUISingleton
@@ -41,13 +41,13 @@ interface CommunalRepository {
     * Target scene as requested by the underlying [SceneTransitionLayout] or through
     * [setDesiredScene].
     */
    val desiredScene: StateFlow<CommunalSceneKey>
    val desiredScene: StateFlow<SceneKey>

    /** Exposes the transition state of the communal [SceneTransitionLayout]. */
    val transitionState: StateFlow<ObservableCommunalTransitionState>

    /** Updates the requested scene. */
    fun setDesiredScene(desiredScene: CommunalSceneKey)
    fun setDesiredScene(desiredScene: SceneKey)

    /**
     * Updates the transition state of the hub [SceneTransitionLayout].
@@ -67,9 +67,8 @@ constructor(
    sceneContainerRepository: SceneContainerRepository,
) : CommunalRepository {

    private val _desiredScene: MutableStateFlow<CommunalSceneKey> =
        MutableStateFlow(CommunalScenes.Default)
    override val desiredScene: StateFlow<CommunalSceneKey> = _desiredScene.asStateFlow()
    private val _desiredScene: MutableStateFlow<SceneKey> = MutableStateFlow(CommunalScenes.Default)
    override val desiredScene: StateFlow<SceneKey> = _desiredScene.asStateFlow()

    private val defaultTransitionState =
        ObservableCommunalTransitionState.Idle(CommunalScenes.Default)
@@ -83,7 +82,7 @@ constructor(
                initialValue = defaultTransitionState,
            )

    override fun setDesiredScene(desiredScene: CommunalSceneKey) {
    override fun setDesiredScene(desiredScene: SceneKey) {
        _desiredScene.value = desiredScene
    }

+5 −5
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.communal.domain.interactor
import android.app.smartspace.SmartspaceTarget
import android.content.ComponentName
import android.os.UserHandle
import com.android.compose.animation.scene.SceneKey
import com.android.systemui.communal.data.repository.CommunalMediaRepository
import com.android.systemui.communal.data.repository.CommunalPrefsRepository
import com.android.systemui.communal.data.repository.CommunalRepository
@@ -29,7 +30,6 @@ import com.android.systemui.communal.shared.model.CommunalContentSize
import com.android.systemui.communal.shared.model.CommunalContentSize.FULL
import com.android.systemui.communal.shared.model.CommunalContentSize.HALF
import com.android.systemui.communal.shared.model.CommunalContentSize.THIRD
import com.android.systemui.communal.shared.model.CommunalSceneKey
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.communal.shared.model.CommunalWidgetContentModel
import com.android.systemui.communal.shared.model.ObservableCommunalTransitionState
@@ -134,7 +134,7 @@ constructor(
     *
     * If [isCommunalAvailable] is false, will return [CommunalScenes.Blank]
     */
    val desiredScene: Flow<CommunalSceneKey> =
    val desiredScene: Flow<SceneKey> =
        communalRepository.desiredScene.combine(isCommunalAvailable) { scene, available ->
            if (available) scene else CommunalScenes.Blank
        }
@@ -153,7 +153,7 @@ constructor(
    }

    /** Returns a flow that tracks the progress of transitions to the given scene from 0-1. */
    fun transitionProgressToScene(targetScene: CommunalSceneKey) =
    fun transitionProgressToScene(targetScene: SceneKey) =
        transitionState
            .flatMapLatest { state ->
                when (state) {
@@ -235,7 +235,7 @@ constructor(
        }

    /** Callback received whenever the [SceneTransitionLayout] finishes a scene transition. */
    fun onSceneChanged(newScene: CommunalSceneKey) {
    fun onSceneChanged(newScene: SceneKey) {
        communalRepository.setDesiredScene(newScene)
    }

@@ -423,7 +423,7 @@ constructor(
/** Simplified transition progress data class for tracking a single transition between scenes. */
sealed class CommunalTransitionProgress {
    /** No transition/animation is currently running. */
    data class Idle(val scene: CommunalSceneKey) : CommunalTransitionProgress()
    data class Idle(val scene: SceneKey) : CommunalTransitionProgress()

    /** There is a transition animating to the expected scene. */
    data class Transition(
Loading