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

Commit 80ce70aa authored by burakov's avatar burakov
Browse files

[Dual Shade] Avoid showing the battery icon twice in QuickSettings shade

Fix: 414749885
Test: Manually tested by opening the single shade on a device without a
 center cutout, and observing that the battery estimate is shown instead
 of percentage.
Flag: com.android.systemui.scene_container
Change-Id: Icd69362a3636d8e504f1cb76354b708c644652c9
parent 0a2bbf95
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -243,8 +243,9 @@ fun ContentScope.CollapsedShadeHeader(
                            useExpandedFormat = useExpandedTextFormat,
                            modifier = Modifier.padding(end = paddingEnd).weight(1f, fill = false),
                        )
                        BatteryIcon(
                        BatteryInfo(
                            viewModel = viewModel,
                            showIcon = true,
                            useExpandedFormat = useExpandedTextFormat,
                            modifier = Modifier.padding(vertical = 8.dp),
                        )
@@ -316,7 +317,11 @@ fun ContentScope.ExpandedShadeHeader(
                        useExpandedFormat = useExpandedFormat,
                        modifier = Modifier.padding(end = paddingEnd).weight(1f, fill = false),
                    )
                    BatteryIcon(viewModel = viewModel, useExpandedFormat = useExpandedFormat)
                    BatteryInfo(
                        viewModel = viewModel,
                        showIcon = true,
                        useExpandedFormat = useExpandedFormat,
                    )
                }
            }
        }
@@ -408,8 +413,9 @@ fun ContentScope.OverlayShadeHeader(
                        modifier = Modifier.padding(end = paddingEnd).weight(1f, fill = false),
                        isHighlighted = isHighlighted,
                    )
                    BatteryIcon(
                    BatteryInfo(
                        viewModel = viewModel,
                        showIcon = true,
                        useExpandedFormat = false,
                        isHighlighted = isHighlighted,
                    )
@@ -436,7 +442,7 @@ fun QuickSettingsOverlayHeader(viewModel: ShadeHeaderViewModel, modifier: Modifi
        modifier = modifier.fillMaxWidth(),
    ) {
        ShadeCarrierGroup(viewModel = viewModel)
        BatteryIcon(viewModel = viewModel, useExpandedFormat = true)
        BatteryInfo(viewModel = viewModel, showIcon = false, useExpandedFormat = true)
    }
}

@@ -538,8 +544,9 @@ private fun ContentScope.Clock(
}

@Composable
private fun BatteryIcon(
private fun BatteryInfo(
    viewModel: ShadeHeaderViewModel,
    showIcon: Boolean,
    useExpandedFormat: Boolean,
    modifier: Modifier = Modifier,
    isHighlighted: Boolean = false,
@@ -548,6 +555,7 @@ private fun BatteryIcon(
        BatteryWithEstimate(
            viewModelFactory = viewModel.batteryViewModelFactory,
            isDarkProvider = { viewModel.isShadeAreaDark },
            showIcon = showIcon,
            showEstimate = useExpandedFormat,
            modifier = modifier,
        )
+14 −11
Original line number Diff line number Diff line
@@ -16,11 +16,9 @@

package com.android.systemui.statusbar.pipeline.battery.ui.composable

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
@@ -42,6 +40,7 @@ fun BatteryWithEstimate(
    isDarkProvider: () -> IsAreaDark,
    showEstimate: Boolean,
    modifier: Modifier = Modifier,
    showIcon: Boolean = true,
) {
    val viewModel =
        rememberViewModel(traceName = "BatteryWithEstimate") { viewModelFactory.create() }
@@ -49,16 +48,20 @@ fun BatteryWithEstimate(
    val batteryHeight =
        with(LocalDensity.current) { BatteryViewModel.STATUS_BAR_BATTERY_HEIGHT.toDp() }

    Row(modifier = modifier, verticalAlignment = Alignment.CenterVertically) {
    Row(
        modifier = modifier,
        horizontalArrangement = Arrangement.spacedBy(4.dp),
        verticalAlignment = Alignment.CenterVertically,
    ) {
        if (showIcon) {
            UnifiedBattery(
                viewModel = viewModel,
                isDarkProvider = isDarkProvider,
            modifier =
                Modifier.height(batteryHeight).align(Alignment.CenterVertically).wrapContentWidth(),
                modifier = Modifier.height(batteryHeight).align(Alignment.CenterVertically),
            )
        }
        if (showEstimate) {
            viewModel.batteryTimeRemainingEstimate?.let {
                Spacer(modifier.width(4.dp))
                Text(
                    text = it,
                    color = Color.White,