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

Commit edd0b451 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Introduce ElementWithValues to make Element cheaper and simpler (1/3)

Bug: 389985793
Test: ElementTest
Flag: com.android.systemui.scene_container
Change-Id: I46a7066df39a8eae7a85c38a7bcc32a3471fb030
parent 8aca17bc
Loading
Loading
Loading
Loading
+17 −21
Original line number Diff line number Diff line
@@ -70,7 +70,6 @@ constructor(
            key = if (isStart) StartButtonElementKey else EndButtonElementKey,
            modifier = modifier,
        ) {
            content {
            Shortcut(
                viewId = if (isStart) R.id.start_button else R.id.end_button,
                viewModel = if (isStart) viewModel.startButton else viewModel.endButton,
@@ -86,19 +85,16 @@ constructor(
            )
        }
    }
    }

    @Composable
    fun ContentScope.IndicationArea(modifier: Modifier = Modifier) {
        Element(key = IndicationAreaElementKey, modifier = modifier.indicationAreaPadding()) {
            content {
            IndicationArea(
                indicationAreaViewModel = indicationAreaViewModel,
                indicationController = indicationController,
            )
        }
    }
    }

    @Composable
    fun shortcutSizeDp(): DpSize {
+10 −14
Original line number Diff line number Diff line
@@ -26,11 +26,9 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.view.contains
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.android.compose.animation.scene.ContentScope
import com.android.compose.modifiers.padding
@@ -132,7 +130,6 @@ constructor(
        }

        Element(key = largeClockElementKey, modifier = modifier) {
            content {
            ClockView(
                checkNotNull(currentClock).largeClock.view,
                modifier =
@@ -145,7 +142,6 @@ constructor(
            )
        }
    }
    }

    fun getClockCenteringDistance(): Float {
        return Resources.getSystem().displayMetrics.widthPixels / 4f
+50 −53
Original line number Diff line number Diff line
@@ -66,7 +66,6 @@ constructor(
        val resources = LocalContext.current.resources

        Element(key = ClockElementKeys.smartspaceElementKey, modifier = modifier) {
            content {
            Column(
                modifier =
                    modifier
@@ -84,8 +83,7 @@ constructor(
                    return@Column
                }

                    val paddingBelowClockStart =
                        dimensionResource(R.dimen.below_clock_padding_start)
                val paddingBelowClockStart = dimensionResource(R.dimen.below_clock_padding_start)
                val paddingBelowClockEnd = dimensionResource(R.dimen.below_clock_padding_end)
                val paddingCardHorizontal = paddingBelowClockEnd

@@ -126,7 +124,6 @@ constructor(
            }
        }
    }
    }

    @Composable
    private fun Card(modifier: Modifier = Modifier) {
+4 −9
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.key
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
@@ -109,16 +108,12 @@ constructor(
        modifier: Modifier = Modifier,
    ) {
        Element(key = elementKey, modifier) {
            content {
            ClockView(
                    clock.largeClock.layout.views.firstOrNull {
                        it.id == weatherClockElementViewId
                    },
                clock.largeClock.layout.views.firstOrNull { it.id == weatherClockElementViewId },
                modifier,
            )
        }
    }
    }

    @Composable
    fun ContentScope.LargeClockSectionBelowSmartspace(
+29 −26
Original line number Diff line number Diff line
@@ -466,8 +466,10 @@ private fun CutoutAwareShadeHeader(
private fun ContentScope.Clock(scale: Float, onClick: () -> Unit, modifier: Modifier = Modifier) {
    val layoutDirection = LocalLayoutDirection.current

    Element(key = ShadeHeader.Elements.Clock, modifier = modifier) {
    ElementWithValues(key = ShadeHeader.Elements.Clock, modifier = modifier) {
        val animatedScale by animateElementFloatAsState(scale, ClockScale, canOverflow = false)

        content {
            AndroidView(
                factory = { context ->
                    Clock(
@@ -477,8 +479,8 @@ private fun ContentScope.Clock(scale: Float, onClick: () -> Unit, modifier: Modi
                },
                modifier =
                    modifier
                    // use graphicsLayer instead of Modifier.scale to anchor transform
                    // to the (start, top) corner
                        // use graphicsLayer instead of Modifier.scale to anchor transform to the
                        // (start, top) corner
                        .graphicsLayer {
                            scaleX = animatedScale
                            scaleY = animatedScale
@@ -495,6 +497,7 @@ private fun ContentScope.Clock(scale: Float, onClick: () -> Unit, modifier: Modi
            )
        }
    }
}

@Composable
private fun BatteryIcon(
Loading