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

Commit b25d0874 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[flexiglass] Auto-resolve scene families for non-current scene" into main

parents 89d2efd2 8936f43b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ fun SceneContainer(
                        if (sceneKey == currentSceneKey) {
                            currentDestinations
                        } else {
                            composableScene.destinationScenes.value
                            viewModel.resolveSceneFamilies(composableScene.destinationScenes.value)
                        },
                ) {
                    with(composableScene) {
+8 −1
Original line number Diff line number Diff line
@@ -330,9 +330,16 @@ constructor(
     * otherwise returns a singleton [Flow] containing [sceneKey].
     */
    fun resolveSceneFamily(sceneKey: SceneKey): Flow<SceneKey> = flow {
        emitAll(sceneFamilyResolvers.get()[sceneKey]?.resolvedScene ?: flowOf(sceneKey))
        emitAll(resolveSceneFamilyOrNull(sceneKey) ?: flowOf(sceneKey))
    }

    /**
     * Returns the [concrete scene][Scenes] for [sceneKey] if it is a [scene family][SceneFamilies],
     * otherwise returns `null`.
     */
    fun resolveSceneFamilyOrNull(sceneKey: SceneKey): StateFlow<SceneKey>? =
        sceneFamilyResolvers.get()[sceneKey]?.resolvedScene

    private fun isVisibleInternal(
        raw: Boolean = repository.isVisible.value,
        isRemoteUserInteractionOngoing: Boolean = repository.isRemoteUserInteractionOngoing.value,
+14 −0
Original line number Diff line number Diff line
@@ -147,6 +147,20 @@ constructor(
        } ?: true
    }

    /**
     * Immediately resolves any scene families present in [actionResultMap] to their current
     * resolution target.
     */
    fun resolveSceneFamilies(
        actionResultMap: Map<UserAction, UserActionResult>,
    ): Map<UserAction, UserActionResult> {
        return actionResultMap.mapValues { (_, actionResult) ->
            sceneInteractor.resolveSceneFamilyOrNull(actionResult.toScene)?.value?.let {
                actionResult.copy(toScene = it)
            } ?: actionResult
        }
    }

    private fun replaceSceneFamilies(
        destinationScenes: Map<UserAction, UserActionResult>,
    ): Flow<Map<UserAction, UserActionResult>> {