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

Commit 35df3b80 authored by Ahmed Mehfooz's avatar Ahmed Mehfooz Committed by Android (Google) Code Review
Browse files

Merge changes I97854060,I89dc8971 into main

* changes:
  [ROSP] Add framework for status bar popups
  [ROSP] Use Hydrator and AssistedInject for StatusBarPopupChipsViewModel
parents 376f1537 b9efcb0c
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -57,7 +57,7 @@ class FakeHomeStatusBarViewModel(
    override val ongoingActivityChipsLegacy =
    override val ongoingActivityChipsLegacy =
        MutableStateFlow(MultipleOngoingActivityChipsModelLegacy())
        MutableStateFlow(MultipleOngoingActivityChipsModelLegacy())


    override val statusBarPopupChips = MutableStateFlow(emptyList<PopupChipModel.Shown>())
    override val popupChips = emptyList<PopupChipModel.Shown>()


    override val mediaProjectionStopDialogDueToCallEndedState =
    override val mediaProjectionStopDialogDueToCallEndedState =
        MutableStateFlow(MediaProjectionStopDialogModel.Hidden)
        MutableStateFlow(MediaProjectionStopDialogModel.Hidden)
+0 −4
Original line number Original line Diff line number Diff line
@@ -82,10 +82,6 @@ constructor(
            chipId = PopupChipId.MediaControl,
            chipId = PopupChipId.MediaControl,
            icon = defaultIcon,
            icon = defaultIcon,
            chipText = model.songName.toString(),
            chipText = model.songName.toString(),
            isToggled = false,
            // TODO(b/385202114): Show a popup containing the media carousal when the chip is
            // toggled.
            onToggle = {},
            hoverBehavior = createHoverBehavior(model),
            hoverBehavior = createHoverBehavior(model),
        )
        )
    }
    }
+4 −3
Original line number Original line Diff line number Diff line
@@ -53,10 +53,11 @@ sealed class PopupChipModel {
        /** Default icon displayed on the chip */
        /** Default icon displayed on the chip */
        val icon: Icon,
        val icon: Icon,
        val chipText: String,
        val chipText: String,
        val isToggled: Boolean = false,
        val isPopupShown: Boolean = false,
        val onToggle: () -> Unit,
        val showPopup: () -> Unit = {},
        val hidePopup: () -> Unit = {},
        val hoverBehavior: HoverBehavior = HoverBehavior.None,
        val hoverBehavior: HoverBehavior = HoverBehavior.None,
    ) : PopupChipModel() {
    ) : PopupChipModel() {
        override val logName = "Shown(id=$chipId, toggled=$isToggled)"
        override val logName = "Shown(id=$chipId, toggled=$isPopupShown)"
    }
    }
}
}
+65 −0
Original line number Original line 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.statusbar.featurepods.popups.ui.compose

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Popup
import androidx.compose.ui.window.PopupProperties
import com.android.systemui.res.R
import com.android.systemui.statusbar.featurepods.popups.shared.model.PopupChipId
import com.android.systemui.statusbar.featurepods.popups.shared.model.PopupChipModel

/**
 * Displays a popup in the status bar area. The offset is calculated to draw the popup below the
 * status bar.
 */
@Composable
fun StatusBarPopup(viewModel: PopupChipModel.Shown) {
    val density = Density(LocalContext.current)
    Popup(
        properties =
            PopupProperties(
                focusable = false,
                dismissOnBackPress = true,
                dismissOnClickOutside = true,
            ),
        offset =
            IntOffset(
                x = 0,
                y = with(density) { dimensionResource(R.dimen.status_bar_height).roundToPx() },
            ),
        onDismissRequest = { viewModel.hidePopup() },
    ) {
        Box(modifier = Modifier.padding(8.dp).wrapContentSize()) {
            when (viewModel.chipId) {
                is PopupChipId.MediaControl -> {
                    // TODO(b/385202114): Populate MediaControlPopup contents.
                }
            }
            // Future popup types will be handled here.
        }
    }
}
+8 −8
Original line number Original line Diff line number Diff line
@@ -52,14 +52,14 @@ import com.android.systemui.statusbar.featurepods.popups.shared.model.PopupChipM
 * the chip can show text containing contextual information.
 * the chip can show text containing contextual information.
 */
 */
@Composable
@Composable
fun StatusBarPopupChip(model: PopupChipModel.Shown, modifier: Modifier = Modifier) {
fun StatusBarPopupChip(viewModel: PopupChipModel.Shown, modifier: Modifier = Modifier) {
    val hasHoverBehavior = model.hoverBehavior !is HoverBehavior.None
    val hasHoverBehavior = viewModel.hoverBehavior !is HoverBehavior.None
    val hoverInteractionSource = remember { MutableInteractionSource() }
    val hoverInteractionSource = remember { MutableInteractionSource() }
    val isHovered by hoverInteractionSource.collectIsHoveredAsState()
    val isHovered by hoverInteractionSource.collectIsHoveredAsState()
    val isToggled = model.isToggled
    val isPopupShown = viewModel.isPopupShown


    val chipBackgroundColor =
    val chipBackgroundColor =
        if (isToggled) {
        if (isPopupShown) {
            MaterialTheme.colorScheme.primaryContainer
            MaterialTheme.colorScheme.primaryContainer
        } else {
        } else {
            MaterialTheme.colorScheme.surfaceContainerHighest
            MaterialTheme.colorScheme.surfaceContainerHighest
@@ -72,7 +72,7 @@ fun StatusBarPopupChip(model: PopupChipModel.Shown, modifier: Modifier = Modifie
                .padding(vertical = 4.dp)
                .padding(vertical = 4.dp)
                .animateContentSize()
                .animateContentSize()
                .thenIf(hasHoverBehavior) { Modifier.hoverable(hoverInteractionSource) }
                .thenIf(hasHoverBehavior) { Modifier.hoverable(hoverInteractionSource) }
                .clickable { model.onToggle() },
                .thenIf(!isPopupShown) { Modifier.clickable { viewModel.showPopup() } },
        color = chipBackgroundColor,
        color = chipBackgroundColor,
    ) {
    ) {
        Row(
        Row(
@@ -82,14 +82,14 @@ fun StatusBarPopupChip(model: PopupChipModel.Shown, modifier: Modifier = Modifie
        ) {
        ) {
            val iconColor =
            val iconColor =
                if (isHovered) chipBackgroundColor else contentColorFor(chipBackgroundColor)
                if (isHovered) chipBackgroundColor else contentColorFor(chipBackgroundColor)
            val hoverBehavior = model.hoverBehavior
            val hoverBehavior = viewModel.hoverBehavior
            val iconBackgroundColor = contentColorFor(chipBackgroundColor)
            val iconBackgroundColor = contentColorFor(chipBackgroundColor)
            val iconInteractionSource = remember { MutableInteractionSource() }
            val iconInteractionSource = remember { MutableInteractionSource() }
            Icon(
            Icon(
                icon =
                icon =
                    when {
                    when {
                        isHovered && hoverBehavior is HoverBehavior.Button -> hoverBehavior.icon
                        isHovered && hoverBehavior is HoverBehavior.Button -> hoverBehavior.icon
                        else -> model.icon
                        else -> viewModel.icon
                    },
                    },
                modifier =
                modifier =
                    Modifier.thenIf(isHovered) {
                    Modifier.thenIf(isHovered) {
@@ -109,7 +109,7 @@ fun StatusBarPopupChip(model: PopupChipModel.Shown, modifier: Modifier = Modifie
            )
            )


            Text(
            Text(
                text = model.chipText,
                text = viewModel.chipText,
                style = MaterialTheme.typography.labelLarge,
                style = MaterialTheme.typography.labelLarge,
                softWrap = false,
                softWrap = false,
                overflow = TextOverflow.Ellipsis,
                overflow = TextOverflow.Ellipsis,
Loading