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

Commit 80b21059 authored by Anton Potapov's avatar Anton Potapov
Browse files

Only apply the new tint API in the Volume Panel

This change causes various problems in other places where we use Icon.

Flag: com.android.systemui.volume_redesign
Fixes: 415250598
Fixes: 420824185
Test: atest VolumeDialogScreenshotTest
Test: atest VolumePanelScreenshotTest
Test: manual on foldable. Adjust volume and observe the icon
Change-Id: I31185297d703dc3ae72dd8f44b88174a4d6f4bd0
parent 4169cf92
Loading
Loading
Loading
Loading
+38 −3
Original line number Diff line number Diff line
@@ -30,17 +30,52 @@ import com.android.systemui.common.shared.model.Icon
 * Icon composable that draws [icon] using [tint].
 *
 * Note: You can use [Color.Unspecified] to disable the tint and keep the original icon colors.
 *
 * Note: Some drawables aren't compatible with [rememberDrawablePainter], used here for
 * [Icon.Loaded] icons, and won't be resized from their intrinsic size (b/394738023).
 */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Icon(icon: Icon, modifier: Modifier = Modifier, tint: Color = LocalContentColor.current) {
    val contentDescription = icon.contentDescription?.load()
    when (icon) {
        is Icon.Loaded -> {
            Icon(rememberDrawablePainter(icon.drawable), { tint }, contentDescription, modifier)
            Icon(rememberDrawablePainter(icon.drawable), contentDescription, modifier, tint)
        }
        is Icon.Resource -> {
            Icon(painterResource(icon.res), contentDescription, modifier, tint)
        }
    }
}

/**
 * Icon composable that draws [icon] using [tint]. Pass null [tint] to use the default tint color.
 *
 * Note: You can use [Color.Unspecified] to disable the tint and keep the original icon colors.
 *
 * Note: Some drawables aren't compatible with [rememberDrawablePainter], used here for
 * [Icon.Loaded] icons, and won't be resized from their intrinsic size (b/394738023).
 */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Icon(icon: Icon, tint: (() -> Color)?, modifier: Modifier = Modifier) {
    val localContentColor = LocalContentColor.current
    val contentDescription = icon.contentDescription?.load()
    when (icon) {
        is Icon.Loaded -> {
            Icon(
                rememberDrawablePainter(icon.drawable),
                tint ?: { localContentColor },
                contentDescription,
                modifier,
            )
        }
        is Icon.Resource -> {
            Icon(
                painterResource(icon.res),
                tint ?: { localContentColor },
                contentDescription,
                modifier,
            )
        }
        is Icon.Resource -> Icon(painterResource(icon.res), { tint }, contentDescription, modifier)
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -167,6 +167,7 @@ fun VolumeSlider(
                                            icon = {
                                                Icon(
                                                    icon = icon,
                                                    tint = null,
                                                    modifier =
                                                        Modifier.size(24.dp)
                                                            .testTag(
@@ -186,6 +187,7 @@ fun VolumeSlider(
                                            icon = {
                                                Icon(
                                                    icon = icon,
                                                    tint = null,
                                                    modifier =
                                                        Modifier.size(24.dp)
                                                            .testTag(
+10 −2
Original line number Diff line number Diff line
@@ -139,7 +139,11 @@ private fun VolumeDialogSlider(
                activeTrackEndIcon = { iconsState ->
                    SliderIcon(
                        icon = {
                            Icon(icon = sliderStateModel.icon, modifier = Modifier.size(20.dp))
                            Icon(
                                icon = sliderStateModel.icon,
                                tint = null,
                                modifier = Modifier.size(20.dp),
                            )
                        },
                        isVisible = !iconsState.isInactiveTrackEndIconVisible,
                    )
@@ -147,7 +151,11 @@ private fun VolumeDialogSlider(
                inactiveTrackEndIcon = { iconsState ->
                    SliderIcon(
                        icon = {
                            Icon(icon = sliderStateModel.icon, modifier = Modifier.size(20.dp))
                            Icon(
                                icon = sliderStateModel.icon,
                                tint = null,
                                modifier = Modifier.size(20.dp),
                            )
                        },
                        isVisible = iconsState.isInactiveTrackEndIconVisible,
                    )