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

Commit 0302afaa authored by Ale Nijamkin's avatar Ale Nijamkin Committed by Android (Google) Code Review
Browse files

Merge "[flexiglass] SmartSpaceSection in Compose." into main

parents ce31eaf8 62c6f607
Loading
Loading
Loading
Loading
+137 −14
Original line number Diff line number Diff line
@@ -16,32 +16,155 @@

package com.android.systemui.keyguard.ui.composable.section

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import android.widget.FrameLayout
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Text
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import com.android.compose.animation.scene.ElementKey
import com.android.compose.animation.scene.SceneScope
import com.android.systemui.keyguard.KeyguardUnlockAnimationController
import com.android.systemui.keyguard.ui.viewmodel.KeyguardSmartspaceViewModel
import com.android.systemui.res.R
import com.android.systemui.statusbar.lockscreen.LockscreenSmartspaceController
import javax.inject.Inject

class SmartSpaceSection @Inject constructor() {
class SmartSpaceSection
@Inject
constructor(
    private val lockscreenSmartspaceController: LockscreenSmartspaceController,
    private val keyguardUnlockAnimationController: KeyguardUnlockAnimationController,
    private val keyguardSmartspaceViewModel: KeyguardSmartspaceViewModel,
) {
    @Composable
    fun SceneScope.SmartSpace(modifier: Modifier = Modifier) {
        MovableElement(key = SmartSpaceElementKey, modifier = modifier) {
            Box(
                modifier = Modifier.fillMaxWidth().background(Color.Cyan),
        Column(
            modifier = modifier.element(SmartSpaceElementKey),
        ) {
            if (!keyguardSmartspaceViewModel.isSmartspaceEnabled) {
                return
            }

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

            if (keyguardSmartspaceViewModel.isDateWeatherDecoupled) {
                Row(
                    verticalAlignment = Alignment.CenterVertically,
                    modifier =
                        Modifier.fillMaxWidth()
                            // All items will be constrained to be as tall as the shortest item.
                            .height(IntrinsicSize.Min)
                            .padding(
                                start = paddingBelowClockStart,
                            ),
                ) {
                    Date()
                    Spacer(modifier = Modifier.width(4.dp))
                    Weather()
                }
            }

            Card(
                modifier =
                    Modifier.fillMaxWidth()
                        .padding(
                            start = paddingBelowClockStart,
                            end = paddingBelowClockEnd,
                        )
            )
        }
    }

    @Composable
    private fun Card(
        modifier: Modifier = Modifier,
    ) {
        AndroidView(
            factory = { context ->
                FrameLayout(context).apply {
                    addView(
                        lockscreenSmartspaceController.buildAndConnectView(this).apply {
                            layoutParams =
                                FrameLayout.LayoutParams(
                                    FrameLayout.LayoutParams.MATCH_PARENT,
                                    FrameLayout.LayoutParams.WRAP_CONTENT,
                                )

                            keyguardUnlockAnimationController.lockscreenSmartspace = this
                        }
                    )
                }
            },
            onRelease = { keyguardUnlockAnimationController.lockscreenSmartspace = null },
            modifier = modifier,
        )
    }

    @Composable
    private fun Weather(
        modifier: Modifier = Modifier,
    ) {
        val isVisible by keyguardSmartspaceViewModel.isWeatherVisible.collectAsState()
        if (!isVisible) {
            return
        }

        AndroidView(
            factory = { context ->
                FrameLayout(context).apply {
                    addView(
                        lockscreenSmartspaceController.buildAndConnectWeatherView(this).apply {
                            layoutParams =
                                FrameLayout.LayoutParams(
                                    FrameLayout.LayoutParams.WRAP_CONTENT,
                                    FrameLayout.LayoutParams.WRAP_CONTENT,
                                )
                        }
                    )
                }
            },
            modifier = modifier,
        )
    }

    @Composable
    private fun Date(
        modifier: Modifier = Modifier,
    ) {
                Text(
                    text = "TODO(b/316211368): Smart space",
                    color = Color.White,
                    modifier = Modifier.align(Alignment.Center),
        val isVisible by keyguardSmartspaceViewModel.isDateVisible.collectAsState()
        if (!isVisible) {
            return
        }

        AndroidView(
            factory = { context ->
                FrameLayout(context).apply {
                    addView(
                        lockscreenSmartspaceController.buildAndConnectDateView(this).apply {
                            layoutParams =
                                FrameLayout.LayoutParams(
                                    FrameLayout.LayoutParams.WRAP_CONTENT,
                                    FrameLayout.LayoutParams.WRAP_CONTENT,
                                )
                        }
                    )
                }
            },
            modifier = modifier,
        )
    }
}