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

Commit 08ed81c6 authored by burakov's avatar burakov Committed by Danny Burakov
Browse files

[flexiglass] Remove redundant redefinitions in SceneContainerRepository.

Bug: 411400348
Test: Unit tests still pass.
Flag: com.android.systemui.scene_container
Change-Id: I9a90211a70be67de5a14717c19759962f80151bb
parent 78d7940e
Loading
Loading
Loading
Loading
+5 −25
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.systemui.scene.shared.model.SceneDataSource
import com.android.systemui.scene.shared.model.SceneDataSourceDelegator
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
@@ -40,11 +41,7 @@ import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.stateIn

/** Encapsulates the state of communal mode. */
interface CommunalSceneRepository {
    /**
     * Target scene as requested by the underlying [SceneTransitionLayout] or through [changeScene].
     */
    val currentScene: StateFlow<SceneKey>
interface CommunalSceneRepository : SceneDataSource {

    /** Exposes the transition state of the communal [SceneTransitionLayout]. */
    val transitionState: StateFlow<ObservableTransitionState>
@@ -52,12 +49,6 @@ interface CommunalSceneRepository {
    /** Current orientation of the communal container. */
    val communalContainerOrientation: StateFlow<Int>

    /** Updates the requested scene. */
    @MainThread fun changeScene(toScene: SceneKey, transitionKey: TransitionKey? = null)

    /** Immediately snaps to the desired scene. */
    @MainThread fun snapToScene(toScene: SceneKey)

    /** Shows the hub from a power button press. */
    @MainThread fun showHubFromPowerButton()

@@ -72,6 +63,7 @@ interface CommunalSceneRepository {
    fun setCommunalContainerOrientation(orientation: Int)
}

@OptIn(ExperimentalCoroutinesApi::class)
@SysUISingleton
class CommunalSceneRepositoryImpl
@Inject
@@ -79,9 +71,7 @@ constructor(
    @Background backgroundScope: CoroutineScope,
    @Communal private val sceneDataSource: SceneDataSource,
    @Communal private val delegator: SceneDataSourceDelegator,
) : CommunalSceneRepository {

    override val currentScene: StateFlow<SceneKey> = sceneDataSource.currentScene
) : CommunalSceneRepository, SceneDataSource by sceneDataSource {

    private val defaultTransitionState = ObservableTransitionState.Idle(CommunalScenes.Default)
    private val _transitionState = MutableStateFlow<Flow<ObservableTransitionState>?>(null)
@@ -99,16 +89,6 @@ constructor(
    override val communalContainerOrientation: StateFlow<Int> =
        _communalContainerOrientation.asStateFlow()

    @MainThread
    override fun changeScene(toScene: SceneKey, transitionKey: TransitionKey?) {
        sceneDataSource.changeScene(toScene, transitionKey)
    }

    @MainThread
    override fun snapToScene(toScene: SceneKey) {
        sceneDataSource.snapToScene(toScene)
    }

    override fun setCommunalContainerOrientation(orientation: Int) {
        _communalContainerOrientation.value = orientation
    }
@@ -135,7 +115,7 @@ constructor(
        _transitionState.value = transitionState
    }

    /** Noop implementation of a scene data source that always returns the initial [SceneKey]. */
    /** No-op implementation of a scene data source that always returns the initial [SceneKey]. */
    private class NoOpSceneDataSource(initialSceneKey: SceneKey) : SceneDataSource {
        override val currentScene: StateFlow<SceneKey> =
            MutableStateFlow(initialSceneKey).asStateFlow()
+4 −82
Original line number Diff line number Diff line
@@ -18,15 +18,13 @@ package com.android.systemui.scene.data.repository

import com.android.compose.animation.scene.ContentKey
import com.android.compose.animation.scene.ObservableTransitionState
import com.android.compose.animation.scene.OverlayKey
import com.android.compose.animation.scene.SceneKey
import com.android.compose.animation.scene.TransitionKey
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.scene.shared.model.SceneContainerConfig
import com.android.systemui.scene.shared.model.SceneDataSource
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
@@ -36,6 +34,7 @@ import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.stateIn

@OptIn(ExperimentalCoroutinesApi::class)
@SysUISingleton
/** Source of truth for scene framework application state. */
class SceneContainerRepository
@@ -44,7 +43,8 @@ constructor(
    @Application applicationScope: CoroutineScope,
    config: SceneContainerConfig,
    private val dataSource: SceneDataSource,
) {
) : SceneDataSource by dataSource {

    /**
     * The keys of all scenes and overlays in the container.
     *
@@ -53,16 +53,6 @@ constructor(
     */
    val allContentKeys: List<ContentKey> = config.sceneKeys + config.overlayKeys

    val currentScene: StateFlow<SceneKey> = dataSource.currentScene

    /**
     * The current set of overlays to be shown (may be empty).
     *
     * Note that during a transition between overlays, a different set of overlays may be rendered -
     * but only the ones in this set are considered the current overlays.
     */
    val currentOverlays: StateFlow<Set<OverlayKey>> = dataSource.currentOverlays

    private val _isVisible = MutableStateFlow(true)
    val isVisible: StateFlow<Boolean> = _isVisible.asStateFlow()

@@ -90,66 +80,6 @@ constructor(
    /** Number of currently active transition animations. */
    val activeTransitionAnimationCount = MutableStateFlow(0)

    fun changeScene(toScene: SceneKey, transitionKey: TransitionKey? = null) {
        dataSource.changeScene(toScene = toScene, transitionKey = transitionKey)
    }

    fun snapToScene(toScene: SceneKey) {
        dataSource.snapToScene(toScene = toScene)
    }

    /**
     * Request to show [overlay] so that it animates in from [currentScene] and ends up being
     * visible on screen.
     *
     * After this returns, this overlay will be included in [currentOverlays]. This does nothing if
     * [overlay] is already shown.
     */
    fun showOverlay(overlay: OverlayKey, transitionKey: TransitionKey? = null) {
        dataSource.showOverlay(overlay = overlay, transitionKey = transitionKey)
    }

    /**
     * Request to hide [overlay] so that it animates out to [currentScene] and ends up *not* being
     * visible on screen.
     *
     * After this returns, this overlay will not be included in [currentOverlays]. This does nothing
     * if [overlay] is already hidden.
     */
    fun hideOverlay(overlay: OverlayKey, transitionKey: TransitionKey? = null) {
        dataSource.hideOverlay(overlay = overlay, transitionKey = transitionKey)
    }

    /**
     * Replace [from] by [to] so that [from] ends up not being visible on screen and [to] ends up
     * being visible.
     *
     * This throws if [from] is not currently shown or if [to] is already shown.
     */
    fun replaceOverlay(from: OverlayKey, to: OverlayKey, transitionKey: TransitionKey? = null) {
        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
@@ -163,12 +93,4 @@ constructor(
    fun setTransitionState(transitionState: Flow<ObservableTransitionState>?) {
        _transitionState.value = transitionState
    }

    /**
     * If currently in a transition between contents, cancel that transition and go back to the
     * pre-transition state.
     */
    fun freezeAndAnimateToCurrentState() {
        dataSource.freezeAndAnimateToCurrentState()
    }
}
+19 −1
Original line number Diff line number Diff line
@@ -2,10 +2,12 @@ package com.android.systemui.communal.data.repository

import android.content.res.Configuration
import com.android.compose.animation.scene.ObservableTransitionState
import com.android.compose.animation.scene.OverlayKey
import com.android.compose.animation.scene.SceneKey
import com.android.compose.animation.scene.TransitionKey
import com.android.systemui.communal.shared.model.CommunalScenes
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
@@ -17,9 +19,12 @@ import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch

/** Fake implementation of [CommunalSceneRepository]. */
@OptIn(ExperimentalCoroutinesApi::class)
class FakeCommunalSceneRepository(
    private val applicationScope: CoroutineScope,
    override val currentScene: MutableStateFlow<SceneKey> = MutableStateFlow(CommunalScenes.Default),
    override val currentScene: MutableStateFlow<SceneKey> =
        MutableStateFlow(CommunalScenes.Default),
    override val currentOverlays: StateFlow<Set<OverlayKey>> = MutableStateFlow(emptySet()),
) : CommunalSceneRepository {

    override fun changeScene(toScene: SceneKey, transitionKey: TransitionKey?) =
@@ -32,6 +37,19 @@ class FakeCommunalSceneRepository(
        }
    }

    override fun showOverlay(overlay: OverlayKey, transitionKey: TransitionKey?) = Unit

    override fun hideOverlay(overlay: OverlayKey, transitionKey: TransitionKey?) = Unit

    override fun replaceOverlay(from: OverlayKey, to: OverlayKey, transitionKey: TransitionKey?) =
        Unit

    override fun instantlyShowOverlay(overlay: OverlayKey) = Unit

    override fun instantlyHideOverlay(overlay: OverlayKey) = Unit

    override fun freezeAndAnimateToCurrentState() = Unit

    override fun showHubFromPowerButton() {
        snapToScene(CommunalScenes.Communal)
    }