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

Commit c491b9d2 authored by Aaron Liu's avatar Aaron Liu
Browse files

Move binding back to constructor

The bindings need to exist even when lockscreen is not showing. We need
the bindings also when phone is unlocked and in shade.

Fixes: 323965777
Test: unlock phone and look at notifications.
Flag:  ACONFIG com.android.systemui.scene_container DEVELOPMENT

Change-Id: Iea1d8b4ac5e9deb9e05c91caceb02278474e3c92
parent 0c999165
Loading
Loading
Loading
Loading
+28 −54
Original line number Diff line number Diff line
@@ -19,11 +19,6 @@ package com.android.systemui.keyguard.ui.composable.section
import android.content.Context
import android.view.ViewGroup
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import com.android.compose.animation.scene.SceneScope
import com.android.systemui.dagger.SysUISingleton
@@ -45,7 +40,6 @@ import com.android.systemui.statusbar.notification.stack.ui.viewmodel.Notificati
import com.android.systemui.statusbar.notification.stack.ui.viewmodel.SharedNotificationContainerViewModel
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.DisposableHandle

@SysUISingleton
class NotificationSection
@@ -53,39 +47,31 @@ class NotificationSection
constructor(
    @Application private val context: Context,
    private val viewModel: NotificationsPlaceholderViewModel,
    private val controller: NotificationStackScrollLayoutController,
    private val sceneContainerFlags: SceneContainerFlags,
    private val sharedNotificationContainer: SharedNotificationContainer,
    private val sharedNotificationContainerViewModel: SharedNotificationContainerViewModel,
    private val stackScrollLayout: NotificationStackScrollLayout,
    private val notificationStackAppearanceViewModel: NotificationStackAppearanceViewModel,
    private val ambientState: AmbientState,
    private val notificationStackSizeCalculator: NotificationStackSizeCalculator,
    controller: NotificationStackScrollLayoutController,
    sceneContainerFlags: SceneContainerFlags,
    sharedNotificationContainer: SharedNotificationContainer,
    sharedNotificationContainerViewModel: SharedNotificationContainerViewModel,
    stackScrollLayout: NotificationStackScrollLayout,
    notificationStackAppearanceViewModel: NotificationStackAppearanceViewModel,
    ambientState: AmbientState,
    notificationStackSizeCalculator: NotificationStackSizeCalculator,
    @Main private val mainDispatcher: CoroutineDispatcher,
) {
    @Composable
    fun SceneScope.Notifications(modifier: Modifier = Modifier) {
        if (KeyguardShadeMigrationNssl.isUnexpectedlyInLegacyMode()) {

    init {
        if (!KeyguardShadeMigrationNssl.isUnexpectedlyInLegacyMode()) {
            // This scene container section moves the NSSL to the SharedNotificationContainer.
            // This also requires that SharedNotificationContainer gets moved to the
            // SceneWindowRootView by the SceneWindowRootViewBinder. Prior to Scene Container,
            // but when the KeyguardShadeMigrationNssl flag is enabled, NSSL is moved into this
            // container by the NotificationStackScrollLayoutSection.
            return
        }

        var isBound by remember { mutableStateOf(false) }

        DisposableEffect(Unit) {
            val disposableHandles: MutableList<DisposableHandle> = mutableListOf()

            // Ensure stackScrollLayout is a child of sharedNotificationContainer.

            if (stackScrollLayout.parent != sharedNotificationContainer) {
                (stackScrollLayout.parent as? ViewGroup)?.removeView(stackScrollLayout)
                sharedNotificationContainer.addNotificationStackScrollLayout(stackScrollLayout)
            }

            disposableHandles.add(
            SharedNotificationContainerBinder.bind(
                sharedNotificationContainer,
                sharedNotificationContainerViewModel,
@@ -94,10 +80,8 @@ constructor(
                notificationStackSizeCalculator,
                mainDispatcher,
            )
            )

            if (sceneContainerFlags.flexiNotifsEnabled()) {
                disposableHandles.add(
                NotificationStackAppearanceViewBinder.bind(
                    context,
                    sharedNotificationContainer,
@@ -105,22 +89,12 @@ constructor(
                    ambientState,
                    controller,
                )
                )
            }

            isBound = true

            onDispose {
                disposableHandles.forEach { it.dispose() }
                disposableHandles.clear()
                isBound = false
            }
        }

        if (!isBound) {
            return
    }

    @Composable
    fun SceneScope.Notifications(modifier: Modifier = Modifier) {
        NotificationStack(
            viewModel = viewModel,
            modifier = modifier,