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

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

Merge "Use LaunchedEffectWithLifecycle for the QS footer actions" into main

parents 8c9b5dfc b253e1a5
Loading
Loading
Loading
Loading
+17 −25
Original line number Diff line number Diff line
@@ -80,11 +80,10 @@ import androidx.compose.ui.unit.em
import androidx.compose.ui.unit.sp
import androidx.core.graphics.drawable.toBitmap
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.android.compose.animation.Expandable
import com.android.compose.animation.scene.ContentScope
import com.android.compose.lifecycle.LaunchedEffectWithLifecycle
import com.android.compose.modifiers.animatedBackground
import com.android.compose.theme.LocalAndroidColorScheme
import com.android.compose.theme.colorAttr
@@ -117,7 +116,6 @@ fun ContentScope.FooterActionsWithAnimatedVisibility(
    viewModel: FooterActionsViewModel,
    isCustomizing: Boolean,
    customizingAnimationDuration: Int,
    lifecycleOwner: LifecycleOwner,
    modifier: Modifier = Modifier,
) {
    AnimatedVisibility(
@@ -138,7 +136,7 @@ fun ContentScope.FooterActionsWithAnimatedVisibility(
            // This view has its own horizontal padding
            // TODO(b/321716470) This should use a lifecycle tied to the scene.
            Element(QuickSettings.Elements.FooterActions, Modifier) {
                FooterActions(viewModel = viewModel, qsVisibilityLifecycleOwner = lifecycleOwner)
                FooterActions(viewModel = viewModel)
            }
        }
    }
@@ -146,11 +144,7 @@ fun ContentScope.FooterActionsWithAnimatedVisibility(

/** The Quick Settings footer actions row. */
@Composable
fun FooterActions(
    viewModel: FooterActionsViewModel,
    qsVisibilityLifecycleOwner: LifecycleOwner,
    modifier: Modifier = Modifier,
) {
fun FooterActions(viewModel: FooterActionsViewModel, modifier: Modifier = Modifier) {
    val context = LocalContext.current

    // Collect alphas as soon as we are composed, even when not visible.
@@ -167,28 +161,26 @@ fun FooterActions(
        mutableStateOf<TextFeedbackViewModel>(TextFeedbackViewModel.NoFeedback)
    }

    LaunchedEffect(
        context,
        qsVisibilityLifecycleOwner,
        viewModel,
        viewModel.security,
        viewModel.foregroundServices,
        viewModel.userSwitcher,
        viewModel.textFeedback,
    ) {
    LaunchedEffect(context, viewModel) {
        launch {
            // Listen for dialog requests as soon as we are composed, even when not visible.
            viewModel.observeDeviceMonitoringDialogRequests(context)
        }
    }

    // Listen for model changes only when QS are visible.
        qsVisibilityLifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) {
    LaunchedEffectWithLifecycle(
        viewModel.security,
        viewModel.foregroundServices,
        viewModel.userSwitcher,
        viewModel.textFeedback,
        minActiveState = Lifecycle.State.RESUMED,
    ) {
        launch { viewModel.security.collect { security = it } }
        launch { viewModel.foregroundServices.collect { foregroundServices = it } }
        launch { viewModel.userSwitcher.collect { userSwitcher = it } }
        launch { viewModel.textFeedback.collect { textFeedback = it } }
    }
    }

    val backgroundColor =
        if (!notificationShadeBlur()) colorAttr(R.attr.underSurface) else Color.Transparent
+0 −1
Original line number Diff line number Diff line
@@ -375,7 +375,6 @@ private fun ContentScope.QuickSettingsContent(
                viewModel = footerActionsViewModel,
                isCustomizing = false,
                customizingAnimationDuration = 0,
                lifecycleOwner = lifecycleOwner,
                modifier =
                    Modifier.align(Alignment.CenterHorizontally)
                        .sysuiResTag("qs_footer_actions")
+0 −1
Original line number Diff line number Diff line
@@ -517,7 +517,6 @@ private fun ContentScope.SplitShade(
                                        viewModel = footerActionsViewModel,
                                        isCustomizing = false,
                                        customizingAnimationDuration = 0,
                                        lifecycleOwner = lifecycleOwner,
                                        modifier =
                                            Modifier.align(Alignment.CenterHorizontally)
                                                .sysuiResTag("qs_footer_actions"),
+4 −6
Original line number Diff line number Diff line
package com.android.systemui.qs

import android.content.Context
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.compose.LocalLifecycleOwner
import com.android.compose.theme.PlatformTheme
import com.android.internal.policy.SystemBarUtils
import com.android.systemui.compose.modifiers.sysUiResTagContainer
@@ -36,12 +38,8 @@ object QSUtils {
        qsVisibilityLifecycleOwner: LifecycleOwner,
    ) {
        view.setContent {
            PlatformTheme {
                FooterActions(
                    viewModel,
                    qsVisibilityLifecycleOwner,
                    Modifier.sysUiResTagContainer(),
                )
            CompositionLocalProvider(LocalLifecycleOwner provides qsVisibilityLifecycleOwner) {
                PlatformTheme { FooterActions(viewModel, Modifier.sysUiResTagContainer()) }
            }
        }
    }
+1 −4
Original line number Diff line number Diff line
@@ -963,10 +963,7 @@ constructor(
                        Elements.FooterActions,
                        Modifier.sysuiResTag(ResIdTags.qsFooterActions),
                    ) {
                        FooterActions(
                            viewModel = viewModel.footerActionsViewModel,
                            qsVisibilityLifecycleOwner = this@QSFragmentCompose,
                        )
                        FooterActions(viewModel = viewModel.footerActionsViewModel)
                    }
                }
            }