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

Commit 61a39e2b authored by burakov's avatar burakov
Browse files

[Dual Shade] Render the shade header clock based on the compose state.

This removes the shade header's dependence on the `isShadeLayoutWide`
flow, which will soon be removed.

Bug: 354926927
Bug: 338033836
Test: Manually tested by opening and closing both shades on both a
 folded and unfolded device, verifying the shade header clock appears as
 expected.
Flag: com.android.systemui.scene_container
Change-Id: I0daeefe767a9703dcc235b066a57c7da74735b44
parent 98e14531
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -102,6 +102,8 @@ constructor(
        mediaHost.get().expansion =
            if (usingCollapsedLandscapeMedia && isLandscape()) COLLAPSED else EXPANDED

        val isFullWidth = isFullWidthShade()

        OverlayShade(
            panelElement = NotificationsShade.Elements.Panel,
            alignmentOnWideScreens = Alignment.TopStart,
@@ -114,13 +116,14 @@ constructor(
                    }
                OverlayShadeHeader(
                    viewModel = headerViewModel,
                    showClock = !isFullWidth,
                    modifier = Modifier.element(NotificationsShade.Elements.StatusBar),
                )
            },
        ) {
            Box {
                Column {
                    if (isFullWidthShade()) {
                    if (isFullWidth) {
                        val burnIn = rememberBurnIn(keyguardClockViewModel)

                        with(clockSection) {
+1 −0
Original line number Diff line number Diff line
@@ -142,6 +142,7 @@ constructor(
                header = {
                    OverlayShadeHeader(
                        viewModel = quickSettingsContainerViewModel.shadeHeaderViewModel,
                        showClock = true,
                        modifier = Modifier.element(QuickSettingsShade.Elements.StatusBar),
                    )
                },
+0 −14
Original line number Diff line number Diff line
@@ -313,20 +313,6 @@ fun ContentScope.ExpandedShadeHeader(
 */
@Composable
fun ContentScope.OverlayShadeHeader(
    viewModel: ShadeHeaderViewModel,
    modifier: Modifier = Modifier,
) {
    OverlayShadeHeaderPartialStateless(viewModel, viewModel.showClock, modifier)
}

/**
 * Ideally, we should have a stateless function for overlay shade header, which facilitates testing.
 * However, it is cumbersome to implement such a stateless function, especially when some of the
 * overlay shade header's children accept a view model as the param. Therefore, this function only
 * break up the clock visibility. It is where "PartialStateless" comes from.
 */
@Composable
fun ContentScope.OverlayShadeHeaderPartialStateless(
    viewModel: ShadeHeaderViewModel,
    showClock: Boolean,
    modifier: Modifier = Modifier,
+0 −30
Original line number Diff line number Diff line
@@ -93,36 +93,6 @@ class ShadeHeaderViewModelTest : SysuiTestCase() {
                )
        }

    @Test
    fun showClock_wideLayout_returnsTrue() =
        testScope.runTest {
            kosmos.enableDualShade(wideLayout = true)

            setupDualShadeState(scene = Scenes.Lockscreen, overlay = Overlays.NotificationsShade)
            assertThat(underTest.showClock).isTrue()

            setupDualShadeState(scene = Scenes.Lockscreen, overlay = Overlays.QuickSettingsShade)
            assertThat(underTest.showClock).isTrue()
        }

    @Test
    fun showClock_narrowLayoutOnNotificationsShade_returnsFalse() =
        testScope.runTest {
            kosmos.enableDualShade(wideLayout = false)
            setupDualShadeState(scene = Scenes.Lockscreen, overlay = Overlays.NotificationsShade)

            assertThat(underTest.showClock).isFalse()
        }

    @Test
    fun showClock_narrowLayoutOnQuickSettingsShade_returnsTrue() =
        testScope.runTest {
            kosmos.enableDualShade(wideLayout = false)
            setupDualShadeState(scene = Scenes.Lockscreen, overlay = Overlays.QuickSettingsShade)

            assertThat(underTest.showClock).isTrue()
        }

    @Test
    fun onShadeCarrierGroupClicked_launchesNetworkSettings() =
        testScope.runTest {
+0 −22
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.IntRect
import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.compose.animation.scene.OverlayKey
import com.android.systemui.battery.BatteryMeterViewController
import com.android.systemui.kairos.ExperimentalKairosApi
import com.android.systemui.kairos.KairosNetwork
@@ -99,22 +98,6 @@ constructor(
        (ViewGroup, StatusBarLocation) -> BatteryMeterViewController =
        batteryMeterViewControllerFactory::create

    val showClock: Boolean by
        hydrator.hydratedStateOf(
            traceName = "showClock",
            initialValue =
                shouldShowClock(
                    isShadeLayoutWide = shadeModeInteractor.isShadeLayoutWide.value,
                    overlays = sceneInteractor.currentOverlays.value,
                ),
            source =
                combine(
                    shadeModeInteractor.isShadeLayoutWide,
                    sceneInteractor.currentOverlays,
                    ::shouldShowClock,
                ),
        )

    val notificationsChipHighlight: HeaderChipHighlight by
        hydrator.hydratedStateOf(
            traceName = "notificationsChipHighlight",
@@ -310,11 +293,6 @@ constructor(
        }
    }

    private fun shouldShowClock(isShadeLayoutWide: Boolean, overlays: Set<OverlayKey>): Boolean {
        // Notifications shade on narrow layout renders its own clock. Hide the header clock.
        return isShadeLayoutWide || Overlays.NotificationsShade !in overlays
    }

    private fun getFormatFromPattern(pattern: String?): DateFormat {
        val format = DateFormat.getInstanceForSkeleton(pattern, Locale.getDefault())
        format.setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE)