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

Commit 4d29ed23 authored by William Xiao's avatar William Xiao Committed by Android (Google) Code Review
Browse files

Merge "Remove CommunalContainer touch forwarding" into main

parents 00599c9c 570200e1
Loading
Loading
Loading
Loading
+23 −54
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
@@ -21,10 +20,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInteropFilter
import androidx.compose.ui.unit.dp
import com.android.compose.animation.scene.Edge
import com.android.compose.animation.scene.ElementKey
@@ -41,7 +38,6 @@ import com.android.compose.animation.scene.updateSceneTransitionLayoutState
import com.android.systemui.communal.shared.model.CommunalSceneKey
import com.android.systemui.communal.shared.model.ObservableCommunalTransitionState
import com.android.systemui.communal.ui.viewmodel.BaseCommunalViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.transform

@@ -66,7 +62,6 @@ val sceneTransitions = transitions {
 * This is a temporary container to allow the communal UI to use [SceneTransitionLayout] for gesture
 * handling and transitions before the full Flexiglass layout is ready.
 */
@OptIn(ExperimentalComposeUiApi::class, ExperimentalCoroutinesApi::class)
@Composable
fun CommunalContainer(
    modifier: Modifier = Modifier,
@@ -83,8 +78,8 @@ fun CommunalContainer(
            transitions = sceneTransitions,
        )

    // Don't show hub mode UI if keyguard is present. This is important since we're in the shade,
    // which can be opened from many locations.
    // Don't show hub mode UI if keyguard is not present. This is important since we're in the
    // shade, which can be opened from many locations.
    val isKeyguardShowing by viewModel.isKeyguardVisible.collectAsState(initial = false)

    // Failsafe to hide the whole SceneTransitionLayout in case of bugginess.
@@ -102,18 +97,16 @@ fun CommunalContainer(
        onDispose { viewModel.setTransitionState(null) }
    }

    Box(modifier = modifier.fillMaxSize()) {
    SceneTransitionLayout(
        state = sceneTransitionLayoutState,
            modifier = Modifier.fillMaxSize(),
        modifier = modifier.fillMaxSize(),
        edgeDetector = FixedSizeEdgeDetector(ContainerDimensions.EdgeSwipeSize),
    ) {
        scene(
            TransitionSceneKey.Blank,
            userActions =
                mapOf(
                        Swipe(SwipeDirection.Left, fromEdge = Edge.Right) to
                            TransitionSceneKey.Communal
                    Swipe(SwipeDirection.Left, fromEdge = Edge.Right) to TransitionSceneKey.Communal
                )
        ) {
            BlankScene { showSceneTransitionLayout = false }
@@ -123,36 +116,12 @@ fun CommunalContainer(
            TransitionSceneKey.Communal,
            userActions =
                mapOf(
                        Swipe(SwipeDirection.Right, fromEdge = Edge.Left) to
                            TransitionSceneKey.Blank
                    Swipe(SwipeDirection.Right, fromEdge = Edge.Left) to TransitionSceneKey.Blank
                ),
        ) {
            CommunalScene(viewModel, modifier = modifier)
        }
    }

        // TODO(b/308813166): remove once CommunalContainer is moved lower in z-order and doesn't
        //  block touches anymore.
        Box(
            modifier =
                Modifier.fillMaxSize()
                    // Offsetting to the left so that edge swipe to open the hub still works. This
                    // does mean that the very right edge of the hub won't refresh the screen
                    // timeout, but should be good enough for a temporary solution.
                    .offset(x = -ContainerDimensions.EdgeSwipeSize)
                    .pointerInteropFilter {
                        viewModel.onUserActivity()
                        if (
                            sceneTransitionLayoutState.transitionState.currentScene ==
                                TransitionSceneKey.Blank
                        ) {
                            viewModel.onOuterTouch(it)
                            return@pointerInteropFilter true
                        }
                        false
                    }
        )
    }
}

/**
+0 −7
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.app.Activity.RESULT_OK
import android.app.smartspace.SmartspaceTarget
import android.appwidget.AppWidgetHost
import android.content.ComponentName
import android.os.PowerManager
import android.provider.Settings
import android.widget.RemoteViews
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -41,13 +40,11 @@ import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
import com.android.systemui.kosmos.testScope
import com.android.systemui.media.controls.ui.MediaHost
import com.android.systemui.shade.ShadeViewController
import com.android.systemui.smartspace.data.repository.FakeSmartspaceRepository
import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import javax.inject.Provider
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
@@ -64,8 +61,6 @@ import org.mockito.MockitoAnnotations
@RunWith(AndroidJUnit4::class)
class CommunalEditModeViewModelTest : SysuiTestCase() {
    @Mock private lateinit var mediaHost: MediaHost
    @Mock private lateinit var shadeViewController: ShadeViewController
    @Mock private lateinit var powerManager: PowerManager
    @Mock private lateinit var appWidgetHost: AppWidgetHost
    @Mock private lateinit var uiEventLogger: UiEventLogger

@@ -97,8 +92,6 @@ class CommunalEditModeViewModelTest : SysuiTestCase() {
            CommunalEditModeViewModel(
                withDeps.communalInteractor,
                appWidgetHost,
                Provider { shadeViewController },
                powerManager,
                mediaHost,
                uiEventLogger,
            )
+0 −7
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.systemui.communal.view.viewmodel

import android.app.smartspace.SmartspaceTarget
import android.os.PowerManager
import android.provider.Settings
import android.widget.RemoteViews
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -36,12 +35,10 @@ import com.android.systemui.communal.widgets.WidgetInteractionHandler
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
import com.android.systemui.media.controls.ui.MediaHost
import com.android.systemui.shade.ShadeViewController
import com.android.systemui.smartspace.data.repository.FakeSmartspaceRepository
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import javax.inject.Provider
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.advanceTimeBy
@@ -58,8 +55,6 @@ import org.mockito.MockitoAnnotations
@RunWith(AndroidJUnit4::class)
class CommunalViewModelTest : SysuiTestCase() {
    @Mock private lateinit var mediaHost: MediaHost
    @Mock private lateinit var shadeViewController: ShadeViewController
    @Mock private lateinit var powerManager: PowerManager

    private lateinit var testScope: TestScope

@@ -92,8 +87,6 @@ class CommunalViewModelTest : SysuiTestCase() {
                withDeps.communalInteractor,
                WidgetInteractionHandler(mock()),
                withDeps.tutorialInteractor,
                Provider { shadeViewController },
                powerManager,
                mediaHost,
            )
    }
+0 −27
Original line number Diff line number Diff line
@@ -17,17 +17,12 @@
package com.android.systemui.communal.ui.viewmodel

import android.content.ComponentName
import android.os.PowerManager
import android.os.SystemClock
import android.view.MotionEvent
import android.widget.RemoteViews
import com.android.systemui.communal.domain.interactor.CommunalInteractor
import com.android.systemui.communal.domain.model.CommunalContentModel
import com.android.systemui.communal.shared.model.CommunalSceneKey
import com.android.systemui.communal.shared.model.ObservableCommunalTransitionState
import com.android.systemui.media.controls.ui.MediaHost
import com.android.systemui.shade.ShadeViewController
import javax.inject.Provider
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.flowOf
@@ -35,8 +30,6 @@ import kotlinx.coroutines.flow.flowOf
/** The base view model for the communal hub. */
abstract class BaseCommunalViewModel(
    private val communalInteractor: CommunalInteractor,
    private val shadeViewController: Provider<ShadeViewController>,
    private val powerManager: PowerManager,
    val mediaHost: MediaHost,
) {
    val isKeyguardVisible: Flow<Boolean> = communalInteractor.isKeyguardVisible
@@ -71,26 +64,6 @@ abstract class BaseCommunalViewModel(
        return true
    }

    // TODO(b/308813166): remove once CommunalContainer is moved lower in z-order and doesn't block
    //  touches anymore.
    /** Called when a touch is received outside the edge swipe area when hub mode is closed. */
    fun onOuterTouch(motionEvent: MotionEvent) {
        // Forward the touch to the shade so that basic gestures like swipe up/down for
        // shade/bouncer work.
        shadeViewController.get().handleExternalTouch(motionEvent)
    }

    // TODO(b/308813166): remove once CommunalContainer is moved lower in z-order and doesn't block
    //  touches anymore.
    /** Called to refresh the screen timeout when a user touch is received. */
    fun onUserActivity() {
        powerManager.userActivity(
            SystemClock.uptimeMillis(),
            PowerManager.USER_ACTIVITY_EVENT_TOUCH,
            0
        )
    }

    /** A list of all the communal content to be displayed in the communal hub. */
    abstract val communalContent: Flow<List<CommunalContentModel>>

+1 −6
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.app.ActivityOptions
import android.appwidget.AppWidgetHost
import android.content.ActivityNotFoundException
import android.content.ComponentName
import android.os.PowerManager
import android.widget.RemoteViews
import com.android.internal.logging.UiEventLogger
import com.android.systemui.communal.domain.interactor.CommunalInteractor
@@ -32,11 +31,9 @@ import com.android.systemui.communal.shared.log.CommunalUiEvent
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.media.controls.ui.MediaHost
import com.android.systemui.media.dagger.MediaModule
import com.android.systemui.shade.ShadeViewController
import com.android.systemui.util.nullableAtomicReference
import javax.inject.Inject
import javax.inject.Named
import javax.inject.Provider
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
@@ -49,11 +46,9 @@ class CommunalEditModeViewModel
constructor(
    private val communalInteractor: CommunalInteractor,
    private val appWidgetHost: AppWidgetHost,
    shadeViewController: Provider<ShadeViewController>,
    powerManager: PowerManager,
    @Named(MediaModule.COMMUNAL_HUB) mediaHost: MediaHost,
    private val uiEventLogger: UiEventLogger,
) : BaseCommunalViewModel(communalInteractor, shadeViewController, powerManager, mediaHost) {
) : BaseCommunalViewModel(communalInteractor, mediaHost) {

    private companion object {
        private const val KEY_SPLASH_SCREEN_STYLE = "android.activity.splashScreenStyle"
Loading