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

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

Merge "Build Smartspace DateWeatherAlarm view the same way as non-flexi" into main

parents 70075093 52be5e19
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -138,8 +138,8 @@ constructor(

            LockscreenSceneLayout(
                viewModel = viewModel,
                elementFactory = elementFactory,
                elementContext = elementContext,
                factory = elementFactory,
                context = elementContext,
            )
        }
    }
+97 −67
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@ import android.content.Context
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
@@ -27,7 +30,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.android.compose.animation.scene.ContentScope
import com.android.compose.modifiers.padding
@@ -54,11 +56,10 @@ constructor(
    private val keyguardClockViewModel: KeyguardClockViewModel,
) : LockscreenElementProvider {
    override val elements: List<LockscreenElement> by lazy {
        listOf(smallClockRegionElement, largeClockRegionElement)
        listOf(SmallClockRegionElement(), LargeClockRegionElement())
    }

    private val smallClockRegionElement =
        object : LockscreenElement {
    private inner class SmallClockRegionElement : LockscreenElement {
        override val key = LockscreenElementKeys.Region.Clock.Small
        override val context = this@ClockRegionElementProvider.context

@@ -70,46 +71,38 @@ constructor(
            val shouldDateWeatherBeBelowSmallClock: Boolean by
                keyguardClockViewModel.shouldDateWeatherBeBelowSmallClock
                    .collectAsStateWithLifecycle()
                val paddingModifier =
                    Modifier.padding(
                        horizontal = dimensionResource(clocksR.dimen.clock_padding_start)
                    )

            // Horizontal Padding is handled internally within the SmartspaceCards element. This
            // makes the application here to other elements in the hierarchy slightly awkward.
            val xPadding = dimensionResource(clocksR.dimen.clock_padding_start)

            Column {
                Row(
                        horizontalArrangement = Arrangement.spacedBy(16.dp),
                    verticalAlignment = Alignment.CenterVertically,
                        modifier = paddingModifier,
                    modifier =
                        Modifier.padding(horizontal = xPadding)
                            .padding(top = dimensionResource(R.dimen.keyguard_clock_top_margin)),
                ) {
                    factory.lockscreenElement(Clock.Small, context)

                    if (!shouldDateWeatherBeBelowSmallClock) {
                        factory.lockscreenElement(
                            Clock.Small,
                            Smartspace.DWA.SmallClock.Column,
                            context,
                            Modifier.padding(
                                top = dimensionResource(R.dimen.keyguard_clock_top_margin)
                                horizontal =
                                    dimensionResource(R.dimen.smartspace_padding_horizontal)
                            ),
                        )

                        if (!shouldDateWeatherBeBelowSmallClock) {
                            Column(
                                horizontalAlignment = Alignment.Start,
                                verticalArrangement = Arrangement.spacedBy(4.dp),
                                modifier = context.burnInModifier,
                            ) {
                                factory.lockscreenElement(Smartspace.Date.SmallClock, context)
                                factory.lockscreenElement(Smartspace.Weather.SmallClock, context)
                            }
                    }
                }

                if (shouldDateWeatherBeBelowSmallClock) {
                        Row(
                            horizontalArrangement = Arrangement.spacedBy(8.dp),
                            verticalAlignment = Alignment.CenterVertically,
                            modifier = paddingModifier.then(context.burnInModifier),
                        ) {
                            factory.lockscreenElement(Smartspace.Date.SmallClock, context)
                            factory.lockscreenElement(Smartspace.Weather.SmallClock, context)
                        }
                    factory.lockscreenElement(
                        Smartspace.DWA.SmallClock.Row,
                        context,
                        Modifier.padding(horizontal = xPadding),
                    )
                }

                factory.lockscreenElement(Smartspace.Cards, context)
@@ -117,8 +110,7 @@ constructor(
        }
    }

    private val largeClockRegionElement =
        object : LockscreenElement {
    private inner class LargeClockRegionElement : LockscreenElement {
        override val key = LockscreenElementKeys.Region.Clock.Large
        override val context = this@ClockRegionElementProvider.context

@@ -127,20 +119,58 @@ constructor(
            factory: LockscreenElementFactory,
            context: LockscreenElementContext,
        ) {
            val shouldDateWeatherBeBelowLargeClock: Boolean by
                keyguardClockViewModel.shouldDateWeatherBeBelowLargeClock
                    .collectAsStateWithLifecycle()

            // Horizontal Padding is handled internally within the SmartspaceCards element. This
            // makes the application here to other elements in the hierarchy slightly awkward.
            val xPadding = dimensionResource(clocksR.dimen.clock_padding_start)

            Column(
                    horizontalAlignment = Alignment.CenterHorizontally,
                    verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.CenterVertically),
                horizontalAlignment = Alignment.Start,
                verticalArrangement = Arrangement.Top,
                modifier =
                    Modifier.fillMaxSize()
                        .padding(top = dimensionResource(R.dimen.keyguard_clock_top_margin)),
            ) {
                    factory.lockscreenElement(Smartspace.Cards, context)
                    factory.lockscreenElement(Clock.Large, context)
                Column(
                    horizontalAlignment = Alignment.Start,
                    verticalArrangement = Arrangement.Top,
                    modifier = Modifier.fillMaxWidth(),
                ) {
                    if (!shouldDateWeatherBeBelowLargeClock) {
                        factory.lockscreenElement(
                            Smartspace.DWA.LargeClock.Above,
                            context,
                            Modifier.padding(horizontal = xPadding),
                        )
                    }

                    Row(
                        horizontalArrangement = Arrangement.spacedBy(8.dp),
                        verticalAlignment = Alignment.CenterVertically,
                        modifier = context.burnInModifier,
                    factory.lockscreenElement(
                        Smartspace.Cards,
                        context,
                        // Always reserve space for smartspace cards, even if they're not visible.
                        // This keeps the clock position stable when smartspace enters/exits.
                        Modifier.heightIn(
                            min = dimensionResource(clocksR.dimen.enhanced_smartspace_height)
                        ),
                    )
                }

                Column(
                    horizontalAlignment = Alignment.CenterHorizontally,
                    verticalArrangement =
                        Arrangement.spacedBy(
                            dimensionResource(R.dimen.smartspace_padding_vertical),
                            Alignment.CenterVertically,
                        ),
                    modifier = Modifier.padding(horizontal = xPadding).fillMaxWidth().weight(1f),
                ) {
                        factory.lockscreenElement(Smartspace.Date.LargeClock, context)
                        factory.lockscreenElement(Smartspace.Weather.LargeClock, context)
                    factory.lockscreenElement(Clock.Large, context)
                    if (shouldDateWeatherBeBelowLargeClock) {
                        factory.lockscreenElement(Smartspace.DWA.LargeClock.Below, context)
                    }
                }
            }
        }
+27 −33
Original line number Diff line number Diff line
@@ -55,10 +55,9 @@ constructor(
    private val viewModelFactory: LockscreenLowerRegionViewModel.Factory,
) : LockscreenElementProvider {
    private val logger = Logger(blueprintLog, "LockscreenLowerRegionElementProvider")
    override val elements: List<LockscreenElement> by lazy { listOf(lowerRegionElement) }
    override val elements: List<LockscreenElement> by lazy { listOf(LowerRegionElement()) }

    private val lowerRegionElement =
        object : LockscreenElement {
    private inner class LowerRegionElement : LockscreenElement {
        override val key = LockscreenElementKeys.Region.Lower
        override val context = this@LockscreenLowerRegionElementProvider.context

@@ -67,8 +66,7 @@ constructor(
            factory: LockscreenElementFactory,
            context: LockscreenElementContext,
        ) {
                val viewModel =
                    rememberViewModel("LockscreenLowerRegion") { viewModelFactory.create() }
            val viewModel = rememberViewModel("LockscreenLowerRegion") { viewModelFactory.create() }

            Row(
                verticalAlignment = Alignment.CenterVertically,
@@ -80,17 +78,13 @@ constructor(
                                dimensionResource(R.dimen.keyguard_affordance_horizontal_offset)
                        ),
            ) {
                    Box(
                        Modifier.graphicsLayer { translationX = viewModel.unfoldTranslations.start }
                    ) {
                Box(Modifier.graphicsLayer { translationX = viewModel.unfoldTranslations.start }) {
                    factory.lockscreenElement(Shortcuts.Start, context)
                }

                Box(Modifier.weight(1f)) { factory.lockscreenElement(IndicationArea, context) }

                    Box(
                        Modifier.graphicsLayer { translationX = viewModel.unfoldTranslations.end }
                    ) {
                Box(Modifier.graphicsLayer { translationX = viewModel.unfoldTranslations.end }) {
                    factory.lockscreenElement(Shortcuts.End, context)
                }
            }
+14 −16
Original line number Diff line number Diff line
@@ -62,13 +62,12 @@ constructor(
    private val viewModelFactory: LockscreenUpperRegionViewModel.Factory,
) : LockscreenElementProvider {
    private val logger = Logger(blueprintLog, "LockscreenUpperRegionElementProvider")
    override val elements: List<LockscreenElement> by lazy { listOf(upperRegionElement) }
    override val elements: List<LockscreenElement> by lazy { listOf(UpperRegionElement()) }

    private val wideLayout = WideLayout()
    private val narrowLayout = NarrowLayout()

    private val upperRegionElement =
        object : LockscreenElement {
    private inner class UpperRegionElement : LockscreenElement {
        override val key = LockscreenElementKeys.Region.Upper
        override val context = this@LockscreenUpperRegionElementProvider.context

@@ -77,8 +76,7 @@ constructor(
            factory: LockscreenElementFactory,
            context: LockscreenElementContext,
        ) {
                val viewModel =
                    rememberViewModel("LockscreenUpperRegion") { viewModelFactory.create() }
            val viewModel = rememberViewModel("LockscreenUpperRegion") { viewModelFactory.create() }
            when (getLayoutType()) {
                LayoutType.WIDE -> with(wideLayout) { Layout(viewModel, factory, context) }
                LayoutType.NARROW -> with(narrowLayout) { Layout(viewModel, factory, context) }
+26 −38
Original line number Diff line number Diff line
@@ -28,10 +28,10 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.content.res.ResourcesCompat
import com.android.compose.animation.scene.ContentScope
import com.android.compose.animation.scene.ElementKey
import com.android.compose.modifiers.padding
import com.android.systemui.animation.view.LaunchableImageView
import com.android.systemui.keyguard.ui.binder.KeyguardQuickAffordanceViewBinder
@@ -40,12 +40,13 @@ import com.android.systemui.keyguard.ui.viewmodel.KeyguardQuickAffordancesCombin
import com.android.systemui.plugins.keyguard.ui.composable.elements.LockscreenElement
import com.android.systemui.plugins.keyguard.ui.composable.elements.LockscreenElementContext
import com.android.systemui.plugins.keyguard.ui.composable.elements.LockscreenElementFactory
import com.android.systemui.plugins.keyguard.ui.composable.elements.LockscreenElementKeys
import com.android.systemui.plugins.keyguard.ui.composable.elements.LockscreenElementKeys.Shortcuts
import com.android.systemui.plugins.keyguard.ui.composable.elements.LockscreenElementProvider
import com.android.systemui.res.R
import com.android.systemui.shade.ShadeDisplayAware
import com.android.systemui.statusbar.KeyguardIndicationController
import javax.inject.Inject
import kotlin.collections.List
import kotlinx.coroutines.flow.Flow

class ShortcutElementProvider
@@ -56,25 +57,17 @@ constructor(
    private val keyguardQuickAffordanceViewBinder: KeyguardQuickAffordanceViewBinder,
    private val indicationController: KeyguardIndicationController,
) : LockscreenElementProvider {
    override val elements by lazy { listOf(startButtonElement, endButtonElement) }

    private val startButtonElement =
        object : LockscreenElement {
            override val key = LockscreenElementKeys.Shortcuts.Start
            override val context = this@ShortcutElementProvider.context

            @Composable
            override fun ContentScope.LockscreenElement(
                factory: LockscreenElementFactory,
                context: LockscreenElementContext,
            ) {
                Shortcut(isStart = true, applyPadding = false)
            }
    override val elements: List<LockscreenElement> by lazy {
        listOf(
            ShortcutElement(Shortcuts.Start, isStart = true),
            ShortcutElement(Shortcuts.End, isStart = false),
        )
    }

    private val endButtonElement =
        object : LockscreenElement {
            override val key = LockscreenElementKeys.Shortcuts.End
    private inner class ShortcutElement(
        override val key: ElementKey,
        private val isStart: Boolean,
    ) : LockscreenElement {
        override val context = this@ShortcutElementProvider.context

        @Composable
@@ -82,7 +75,7 @@ constructor(
            factory: LockscreenElementFactory,
            context: LockscreenElementContext,
        ) {
                Shortcut(isStart = false, applyPadding = false)
            Shortcut(isStart, applyPadding = false)
        }
    }

@@ -94,7 +87,7 @@ constructor(
     *   shortcut is placed along the edges of the display.
     */
    @Composable
    fun ContentScope.Shortcut(
    private fun ContentScope.Shortcut(
        isStart: Boolean,
        applyPadding: Boolean,
        onTopChanged: ((Float) -> Unit)? = null,
@@ -110,14 +103,6 @@ constructor(
        )
    }

    @Composable
    fun shortcutSizeDp(): DpSize {
        return DpSize(
            width = dimensionResource(R.dimen.keyguard_affordance_fixed_width),
            height = dimensionResource(R.dimen.keyguard_affordance_fixed_height),
        )
    }

    @Composable
    private fun Shortcut(
        @IdRes viewId: Int,
@@ -165,7 +150,10 @@ constructor(
            },
            onRelease = { binding?.destroy() },
            modifier =
                modifier.size(width = shortcutSizeDp().width, height = shortcutSizeDp().height),
                modifier.size(
                    width = dimensionResource(R.dimen.keyguard_affordance_fixed_width),
                    height = dimensionResource(R.dimen.keyguard_affordance_fixed_height),
                ),
        )
    }

Loading