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

Commit eb8bf797 authored by Darrell Shi's avatar Darrell Shi
Browse files

Implement UMO transitions to & from the communal hub

Bug: 311243906
Fix: 311243906
Test: verified UMO transitions to & from keyguard and dream
Test: atest MediaHierarchyManagerTest
Flag: ACONFIG com.android.systemui.communal_hub STAGING
Change-Id: Iaaba3e3d2d83815082e940d7741375e5f6e01329
parent 962cf068
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import com.android.systemui.communal.data.repository.CommunalRepositoryModule
import com.android.systemui.communal.data.repository.CommunalSettingsRepositoryModule
import com.android.systemui.communal.data.repository.CommunalTutorialRepositoryModule
import com.android.systemui.communal.data.repository.CommunalWidgetRepositoryModule
import com.android.systemui.communal.ui.viewmodel.CommunalTransitionViewModel
import com.android.systemui.communal.ui.viewmodel.CommunalTransitionViewModelImpl
import com.android.systemui.communal.widgets.CommunalWidgetModule
import com.android.systemui.communal.widgets.EditWidgetsActivityStarter
import com.android.systemui.communal.widgets.EditWidgetsActivityStarterImpl
@@ -47,4 +49,9 @@ interface CommunalModule {
    fun bindEditWidgetsActivityStarter(
        starter: EditWidgetsActivityStarterImpl
    ): EditWidgetsActivityStarter

    @Binds
    fun bindCommunalTransitionViewModel(
        impl: CommunalTransitionViewModelImpl
    ): CommunalTransitionViewModel
}
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.communal.ui.viewmodel

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.keyguard.ui.viewmodel.DreamingToGlanceableHubTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.GlanceableHubToDreamingTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.GlanceableHubToLockscreenTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.LockscreenToGlanceableHubTransitionViewModel
import javax.inject.Inject
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.merge

/** View model for transitions related to the communal hub. */
interface CommunalTransitionViewModel {
    val isUmoOnCommunal: Flow<Boolean>
}

@OptIn(ExperimentalCoroutinesApi::class)
@SysUISingleton
class CommunalTransitionViewModelImpl
@Inject
constructor(
    glanceableHubToLockscreenTransitionViewModel: GlanceableHubToLockscreenTransitionViewModel,
    lockscreenToGlanceableHubTransitionViewModel: LockscreenToGlanceableHubTransitionViewModel,
    dreamToGlanceableHubTransitionViewModel: DreamingToGlanceableHubTransitionViewModel,
    glanceableHubToDreamTransitionViewModel: GlanceableHubToDreamingTransitionViewModel,
) : CommunalTransitionViewModel {
    /**
     * Whether UMO location should be on communal. This flow is responsive to transitions so that a
     * new value is emitted at the right step of a transition to/from communal hub that the location
     * of UMO should be updated.
     */
    override val isUmoOnCommunal: Flow<Boolean> =
        merge(
                lockscreenToGlanceableHubTransitionViewModel.showUmo,
                glanceableHubToLockscreenTransitionViewModel.showUmo,
                dreamToGlanceableHubTransitionViewModel.showUmo,
                glanceableHubToDreamTransitionViewModel.showUmo,
            )
            .distinctUntilChanged()
}
+10 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.map

@OptIn(ExperimentalCoroutinesApi::class)
@SysUISingleton
@@ -65,6 +66,15 @@ constructor(
            name = "DREAMING->GLANCEABLE_HUB: dreamOverlayAlpha",
        )

    // Show UMO once the transition starts.
    val showUmo: Flow<Boolean> =
        transitionAnimation
            .sharedFlow(
                duration = TO_GLANCEABLE_HUB_DURATION,
                onStep = { it },
            )
            .map { step -> step != 0f }

    private companion object {
        val TO_GLANCEABLE_HUB_DURATION = 1.seconds
    }
+10 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.map

@OptIn(ExperimentalCoroutinesApi::class)
@SysUISingleton
@@ -66,6 +67,15 @@ constructor(
                )
            }

    // Show UMO until transition finishes.
    val showUmo: Flow<Boolean> =
        transitionAnimation
            .sharedFlow(
                duration = FROM_GLANCEABLE_HUB_DURATION,
                onStep = { it },
            )
            .map { step -> step != 1f }

    private companion object {
        val FROM_GLANCEABLE_HUB_DURATION = 1.seconds
    }
+3 −0
Original line number Diff line number Diff line
@@ -64,6 +64,9 @@ constructor(
            )
            .onStart { emit(0f) }

    // Show UMO as long as keyguard is not visible.
    val showUmo: Flow<Boolean> = keyguardAlpha.map { alpha -> alpha == 0f }

    val keyguardTranslationX: Flow<StateToValue> =
        configurationInteractor
            .dimensionPixelSize(R.dimen.hub_to_lockscreen_transition_lockscreen_translation_x)
Loading