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

Commit 1d79be47 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Show "+N" when there're more than 1 MR. Unexpaned the MR label when...

Merge "Show "+N" when there're more than 1 MR. Unexpaned the MR label when ActionList is collapsed and there're >1 MR and MA." into main
parents af3330ec aa3e66e1
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import androidx.compose.material3.IconButtonColors
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@@ -92,6 +93,13 @@ fun NavBarPill(

    val density = LocalDensity.current
    val collapsedWidthPx = with(density) { navBarWidth.toPx() }
    var wasEverCollapsed by remember(actions) { mutableStateOf(false) }
    LaunchedEffect(expanded) {
        if (expanded) {
            wasEverCollapsed = true
        }
    }

    var expandedSize by remember { mutableStateOf(IntSize.Zero) }
    val visibleState = remember { MutableTransitionState(false) }
    visibleState.targetState = visible
@@ -248,7 +256,27 @@ fun NavBarPill(
                                        modifier =
                                            Modifier.size(16.dp).then(iconBorder).clip(CircleShape),
                                    )
                                    if (!action.icon.repeated) {
                                    if (
                                        isMrAction &&
                                            !(wasEverCollapsed && filteredActions.size > 1)
                                    ) {
                                        Text(
                                            text = action.label,
                                            style = MaterialTheme.typography.labelMedium,
                                            maxLines = 1,
                                            overflow = TextOverflow.Ellipsis,
                                            color = MaterialTheme.colorScheme.onSurface,
                                            modifier = Modifier.widthIn(0.dp, maxPillWidth * 0.5f),
                                        )
                                        if (action.icon.repeatCount > 0) {
                                            Text(
                                                text = "+${action.icon.repeatCount}",
                                                style = MaterialTheme.typography.labelMedium,
                                                color = MaterialTheme.colorScheme.onSurfaceVariant,
                                                modifier = Modifier.padding(end = 3.dp),
                                            )
                                        }
                                    } else if (action.icon.repeatCount == 0) {
                                        Text(
                                            text = action.label,
                                            style = MaterialTheme.typography.labelMedium,
+5 −5
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ class FilterUtilsTest : SysuiTestCase() {
    fun setUp() {
        calendarAction1 =
            ActionViewModel(
                icon = IconViewModel(mock(), "calendar_icon", false),
                icon = IconViewModel(mock(), "calendar_icon", 0),
                label = "Sunday Morning",
                attribution = null,
                onClick = {},
@@ -51,7 +51,7 @@ class FilterUtilsTest : SysuiTestCase() {
            )
        calendarAction2 =
            ActionViewModel(
                icon = IconViewModel(mock(), "calendar_icon", false),
                icon = IconViewModel(mock(), "calendar_icon", 0),
                label = "Sunday Evening",
                attribution = null,
                onClick = {},
@@ -60,7 +60,7 @@ class FilterUtilsTest : SysuiTestCase() {
            )
        mapsAction =
            ActionViewModel(
                icon = IconViewModel(mock(), "map_icon", false),
                icon = IconViewModel(mock(), "map_icon", 0),
                label = "Philz Coffee San Carlos",
                onClick = {},
                onLongClick = {},
@@ -82,7 +82,7 @@ class FilterUtilsTest : SysuiTestCase() {
        val filterActions = FilterUtils.filterActions(listOf(calendarAction1, calendarAction2))

        assertThat(filterActions.size).isEqualTo(1)
        assertThat(filterActions[0].label).isEqualTo("Sunday Morning Sunday Evening")
        assertThat(filterActions[0].icon.repeated).isTrue()
        assertThat(filterActions[0].label).isEqualTo("Sunday Morning")
        assertThat(filterActions[0].icon.repeatCount).isEqualTo(1)
    }
}
+15 −4
Original line number Diff line number Diff line
@@ -16,12 +16,13 @@

package com.android.systemui.ambientcue.ui.utils

import com.android.systemui.ambientcue.ui.viewmodel.ActionType
import com.android.systemui.ambientcue.ui.viewmodel.ActionViewModel

object FilterUtils {
    /**
     * Filters a list of actions, combining actions with the same icon id. The labels of the
     * combined actions are concatenated, and the icon is marked as repeated.
     * combined actions uses the first action label, and the icon repeatCount increases.
     *
     * @param actions The list of actions to filter.
     * @return A new list of filtered actions.
@@ -35,12 +36,22 @@ object FilterUtils {
                    if (existingAction !== action) {
                        filteredActionMap[action.icon.iconId] =
                            existingAction.copy(
                                label = existingAction.label + " " + action.label,
                                icon = existingAction.icon.copy(repeated = true),
                                icon =
                                    existingAction.icon.copy(
                                        repeatCount = existingAction.icon.repeatCount + 1
                                    )
                            )
                    }
                }
        }
        val filteredList = mutableListOf<ActionViewModel>()
        for (action in filteredActionMap.values) {
            if (action.actionType == ActionType.MR) {
                filteredList.add(0, action)
            } else {
                filteredList.add(action)
            }
        }
        return filteredActionMap.values.toList()
        return filteredList
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -33,4 +33,4 @@ enum class ActionType {
    Unknown,
}

data class IconViewModel(val drawable: Drawable, val iconId: String, val repeated: Boolean)
data class IconViewModel(val drawable: Drawable, val iconId: String, val repeatCount: Int)
+1 −1
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ constructor(
                                IconViewModel(
                                    drawable = action.icon.drawable,
                                    iconId = action.icon.iconId,
                                    repeated = false,
                                    repeatCount = 0,
                                ),
                            label = action.label,
                            attribution = action.attribution,