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

Commit a1ad2631 authored by Jesse Dai's avatar Jesse Dai Committed by Android (Google) Code Review
Browse files

Merge "Convert KeyguardTouchHandlingViewModel to Activatable" into main

parents b1cc4bfd 8f73b9bd
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -36,25 +36,25 @@ import androidx.compose.ui.input.pointer.pointerInput
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.android.systemui.communal.ui.compose.extensions.detectLongPressGesture
import com.android.systemui.keyguard.ui.viewmodel.KeyguardTouchHandlingViewModel
import com.android.systemui.lifecycle.rememberViewModel

/** Container for lockscreen content that handles long-press to bring up the settings menu. */
@Composable
// TODO(b/344879669): now that it's more generic than long-press, rename it.
fun LockscreenLongPress(
    viewModel: KeyguardTouchHandlingViewModel,
    viewModelFactory: KeyguardTouchHandlingViewModel.Factory,
    modifier: Modifier = Modifier,
    content: @Composable BoxScope.(onSettingsMenuPlaces: (coordinates: Rect?) -> Unit) -> Unit,
) {
    val isEnabled: Boolean by
        viewModel.isLongPressHandlingEnabled.collectAsStateWithLifecycle(initialValue = false)
    val viewModel = rememberViewModel("LockscreenLongPress") { viewModelFactory.create() }
    val (settingsMenuBounds, setSettingsMenuBounds) = remember { mutableStateOf<Rect?>(null) }
    val interactionSource = remember { MutableInteractionSource() }

    Box(
        modifier =
            modifier
                .pointerInput(isEnabled) {
                    if (isEnabled) {
                .pointerInput(viewModel.isLongPressHandlingEnabled) {
                    if (viewModel.isLongPressHandlingEnabled) {
                        detectLongPressGesture { viewModel.onLongPress(isA11yAction = false) }
                    }
                }
+4 −1
Original line number Diff line number Diff line
@@ -38,7 +38,10 @@ class CommunalBlueprint @Inject constructor() : ComposableLockscreenSceneBluepri

    @Composable
    override fun ContentScope.Content(viewModel: LockscreenContentViewModel, modifier: Modifier) {
        LockscreenLongPress(viewModel = viewModel.touchHandling, modifier = modifier) { _ ->
        LockscreenLongPress(
            viewModelFactory = viewModel.touchHandlingFactory,
            modifier = modifier,
        ) { _ ->
            Box(modifier.background(Color.Black)) {
                Text(
                    text = "TODO(b/316211368): communal blueprint",
+4 −2
Original line number Diff line number Diff line
@@ -78,8 +78,10 @@ constructor(
            with(notificationSection) { HeadsUpNotifications() }
        }

        LockscreenLongPress(viewModel = viewModel.touchHandling, modifier = modifier) {
            onSettingsMenuPlaced ->
        LockscreenLongPress(
            viewModelFactory = viewModel.touchHandlingFactory,
            modifier = modifier,
        ) { onSettingsMenuPlaced ->
            Layout(
                content = {
                    // Constrained to above the lock icon.
+6 −12
Original line number Diff line number Diff line
@@ -42,25 +42,19 @@ class SettingsMenuSection
@Inject
constructor(
    private val viewModel: KeyguardSettingsMenuViewModel,
    private val touchHandlingViewModel: KeyguardTouchHandlingViewModel,
    private val touchHandlingViewModelFactory: KeyguardTouchHandlingViewModel.Factory,
    private val vibratorHelper: VibratorHelper,
    private val activityStarter: ActivityStarter,
) {
    @Composable
    @SuppressWarnings("InflateParams") // null is passed into the inflate call, on purpose.
    fun SettingsMenu(
        onPlaced: (Rect?) -> Unit,
        modifier: Modifier = Modifier,
    ) {
    fun SettingsMenu(onPlaced: (Rect?) -> Unit, modifier: Modifier = Modifier) {
        val (disposableHandle, setDisposableHandle) =
            remember { mutableStateOf<DisposableHandle?>(null) }
        AndroidView(
            factory = { context ->
                LayoutInflater.from(context)
                    .inflate(
                        R.layout.keyguard_settings_popup_menu,
                        null,
                    )
                    .inflate(R.layout.keyguard_settings_popup_menu, null)
                    .apply {
                        isVisible = false
                        alpha = 0f
@@ -69,7 +63,7 @@ constructor(
                            KeyguardSettingsViewBinder.bind(
                                view = this,
                                viewModel = viewModel,
                                touchHandlingViewModel = touchHandlingViewModel,
                                touchHandlingViewModelFactory = touchHandlingViewModelFactory,
                                rootViewModel = null,
                                vibratorHelper = vibratorHelper,
                                activityStarter = activityStarter,
@@ -81,11 +75,11 @@ constructor(
            modifier =
                modifier
                    .padding(
                        bottom = dimensionResource(R.dimen.keyguard_affordance_vertical_offset),
                        bottom = dimensionResource(R.dimen.keyguard_affordance_vertical_offset)
                    )
                    .padding(
                        horizontal =
                            dimensionResource(R.dimen.keyguard_affordance_horizontal_offset),
                            dimensionResource(R.dimen.keyguard_affordance_horizontal_offset)
                    )
                    .onPlaced { coordinates ->
                        onPlaced(
+2 −2
Original line number Diff line number Diff line
@@ -260,7 +260,7 @@ public class NotificationPanelViewControllerBaseTest extends SysuiTestCase {
    @Mock protected DreamingToLockscreenTransitionViewModel
            mDreamingToLockscreenTransitionViewModel;
    @Mock protected KeyguardTransitionInteractor mKeyguardTransitionInteractor;
    @Mock protected KeyguardTouchHandlingViewModel mKeyuardTouchHandlingViewModel;
    @Mock protected KeyguardTouchHandlingViewModel.Factory mKeyguardTouchHandlingViewModelFactory;
    @Mock protected WallpaperFocalAreaViewModel mWallpaperFocalAreaViewModel;
    @Mock protected AlternateBouncerInteractor mAlternateBouncerInteractor;
    @Mock protected MotionEvent mDownMotionEvent;
@@ -565,7 +565,7 @@ public class NotificationPanelViewControllerBaseTest extends SysuiTestCase {
                mMainDispatcher,
                mKeyguardTransitionInteractor,
                mDumpManager,
                mKeyuardTouchHandlingViewModel,
                mKeyguardTouchHandlingViewModelFactory,
                mWallpaperFocalAreaViewModel,
                mKeyguardInteractor,
                mActivityStarter,
Loading