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

Commit 9af43385 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB] Move chips Composable to its own function.

It was already a bit nested, and to address b/397506207 I think even
more code will be added to the chips logic.

Bug: 397506207
Flag: EXEMPT refactor
Test: manually verified chips still work
Change-Id: If0c99b8f4657c50647e82b8e95db4e5be0535ae7
parent 9500ceb5
Loading
Loading
Loading
Loading
+48 −36
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.pipeline.shared.ui.composable

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -194,42 +195,12 @@ fun StatusBarRoot(
                    iconController.addIconGroup(darkIconManager)

                    if (StatusBarChipsModernization.isEnabled) {
                        val startSideExceptHeadsUp =
                            phoneStatusBarView.requireViewById<LinearLayout>(
                                R.id.status_bar_start_side_except_heads_up
                            )

                        val composeView =
                            ComposeView(context).apply {
                                layoutParams =
                                    LinearLayout.LayoutParams(
                                        LinearLayout.LayoutParams.WRAP_CONTENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT,
                                    )

                                setContent {
                                    val chipsVisibilityModel =
                                        statusBarViewModel.ongoingActivityChips
                                    if (chipsVisibilityModel.areChipsAllowed) {
                                        OngoingActivityChips(
                                            chips = chipsVisibilityModel.chips,
                                            iconViewStore = iconViewStore,
                                            onChipBoundsChanged =
                                                statusBarViewModel::onChipBoundsChanged,
                                            modifier = Modifier.sysUiResTagContainer(),
                                        )
                                    }
                                }
                            }

                        // Add the composable container for ongoingActivityChips before the
                        // notification_icon_area to maintain the same ordering for ongoing activity
                        // chips in the status bar layout.
                        val notificationIconAreaIndex =
                            startSideExceptHeadsUp.indexOfChild(
                                startSideExceptHeadsUp.findViewById(R.id.notification_icon_area)
                        addStartSideChipsComposable(
                            phoneStatusBarView,
                            statusBarViewModel,
                            iconViewStore,
                            context,
                        )
                        startSideExceptHeadsUp.addView(composeView, notificationIconAreaIndex)
                    }

                    HomeStatusBarIconBlockListBinder.bind(
@@ -337,6 +308,47 @@ fun StatusBarRoot(
    }
}

/** Adds the composable chips shown on the start side of the status bar. */
private fun addStartSideChipsComposable(
    phoneStatusBarView: PhoneStatusBarView,
    statusBarViewModel: HomeStatusBarViewModel,
    iconViewStore: NotificationIconContainerViewBinder.IconViewStore?,
    context: Context,
) {
    val startSideExceptHeadsUp =
        phoneStatusBarView.requireViewById<LinearLayout>(R.id.status_bar_start_side_except_heads_up)

    val composeView =
        ComposeView(context).apply {
            layoutParams =
                LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT,
                )

            setContent {
                val chipsVisibilityModel = statusBarViewModel.ongoingActivityChips
                if (chipsVisibilityModel.areChipsAllowed) {
                    OngoingActivityChips(
                        chips = chipsVisibilityModel.chips,
                        iconViewStore = iconViewStore,
                        onChipBoundsChanged = statusBarViewModel::onChipBoundsChanged,
                        modifier = Modifier.sysUiResTagContainer(),
                    )
                }
            }
        }

    // Add the composable container for ongoingActivityChips before the
    // notification_icon_area to maintain the same ordering for ongoing activity
    // chips in the status bar layout.
    val notificationIconAreaIndex =
        startSideExceptHeadsUp.indexOfChild(
            startSideExceptHeadsUp.findViewById(R.id.notification_icon_area)
        )
    startSideExceptHeadsUp.addView(composeView, notificationIconAreaIndex)
}

/** Create a new [UnifiedBattery] and add it to the end of the system_icons container */
private fun addBatteryComposable(
    phoneStatusBarView: PhoneStatusBarView,