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

Commit 8936f43b authored by Steve Elliott's avatar Steve Elliott
Browse files

[flexiglass] Auto-resolve scene families for non-current scene

Flag: com.android.systemui.scene_container DEVELOPMENT
Fixes: 347041673
Test: manual
  1. swipe shade all the way open
  2. swipe it to close
  3. interrupt close by placing finger back down
  Observe: no crash
Change-Id: I28dc6c8629aefbc07d561824e9005202843da407
parent b915c239
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>> {