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

Commit d1d34022 authored by Andre Le's avatar Andre Le Committed by Android (Google) Code Review
Browse files

Merge "Flexiglass: Fix clock click callback on desktop" into main

parents 6504f56c 16962c25
Loading
Loading
Loading
Loading
+63 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.systemui.plugins.activityStarter
import com.android.systemui.privacy.PrivacyApplication
import com.android.systemui.privacy.PrivacyItem
import com.android.systemui.privacy.PrivacyType
import com.android.systemui.res.R
import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.shared.model.Overlays
import com.android.systemui.scene.shared.model.Scenes
@@ -77,9 +78,26 @@ class ShadeHeaderViewModelTest : SysuiTestCase() {
        }

    @Test
    fun onClockClicked_launchesClock() =
    fun onClockClicked_enableDesktopFeatureSetFalse_launchesClock() =
        testScope.runTest {
            overrideResource(R.bool.config_enableDesktopFeatureSet, false)
            val activityStarter = kosmos.activityStarter

            underTest.onClockClicked()

            verify(activityStarter)
                .postStartActivityDismissingKeyguard(
                    argThat(IntentMatcherAction(AlarmClock.ACTION_SHOW_ALARMS)),
                    anyInt(),
                )
        }

    @Test
    fun onClockClicked_enableDesktopFeatureSetTrueAndSingleShade_launchesClock() =
        testScope.runTest {
            overrideResource(R.bool.config_enableDesktopFeatureSet, true)
            val activityStarter = kosmos.activityStarter

            underTest.onClockClicked()

            verify(activityStarter)
@@ -89,6 +107,50 @@ class ShadeHeaderViewModelTest : SysuiTestCase() {
                )
        }

    @Test
    fun onClockClicked_enableDesktopFeatureSetTrueAndDualShade_openNotifShade() =
        testScope.runTest {
            overrideResource(R.bool.config_enableDesktopFeatureSet, true)
            setupDualShadeState(scene = Scenes.Gone)
            val currentScene by collectLastValue(sceneInteractor.currentScene)
            val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)

            underTest.onClockClicked()

            assertThat(currentScene).isEqualTo(Scenes.Gone)
            assertThat(currentOverlays).contains(Overlays.NotificationsShade)
            assertThat(currentOverlays).doesNotContain(Overlays.QuickSettingsShade)
        }

    @Test
    fun onClockClicked_enableDesktopFeatureSetTrueOnNotifShade_closesShade() =
        testScope.runTest {
            overrideResource(R.bool.config_enableDesktopFeatureSet, true)
            setupDualShadeState(scene = Scenes.Gone, overlay = Overlays.NotificationsShade)
            val currentScene by collectLastValue(sceneInteractor.currentScene)
            val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)

            underTest.onClockClicked()

            assertThat(currentScene).isEqualTo(Scenes.Gone)
            assertThat(currentOverlays).isEmpty()
        }

    @Test
    fun onClockClicked_enableDesktopFeatureSetTrueOnQSShade_openNotifShade() =
        testScope.runTest {
            overrideResource(R.bool.config_enableDesktopFeatureSet, true)
            setupDualShadeState(scene = Scenes.Gone, overlay = Overlays.QuickSettingsShade)
            val currentScene by collectLastValue(sceneInteractor.currentScene)
            val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)

            underTest.onClockClicked()

            assertThat(currentScene).isEqualTo(Scenes.Gone)
            assertThat(currentOverlays).contains(Overlays.NotificationsShade)
            assertThat(currentOverlays).doesNotContain(Overlays.QuickSettingsShade)
        }

    @Test
    fun onShadeCarrierGroupClicked_launchesNetworkSettings() =
        testScope.runTest {
+26 −4
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ import kotlinx.coroutines.flow.mapLatest
class ShadeHeaderViewModel
@AssistedInject
constructor(
    @ShadeDisplayAware context: Context,
    @ShadeDisplayAware private val context: Context,
    private val activityStarter: ActivityStarter,
    private val sceneInteractor: SceneInteractor,
    private val shadeInteractor: ShadeInteractor,
@@ -207,22 +207,44 @@ constructor(

    /** Notifies that the clock was clicked. */
    fun onClockClicked() {
        if (shadeModeInteractor.isDualShade && isDesktopFeatureSetEnabled()) {
            toggleNotificationShade(
                loggingReason = "ShadeHeaderViewModel.onClockChipClicked",
                launchClockActivityOnCollapse = false,
            )
        } else {
            clockInteractor.launchClockActivity()
        }
    }

    /** Notifies that the notification icons container was clicked. */
    fun onNotificationIconChipClicked() {
        if (!shadeModeInteractor.isDualShade) {
            return
        }
        val loggingReason = "ShadeHeaderViewModel.onNotificationIconChipClicked"
        toggleNotificationShade(
            loggingReason = "ShadeHeaderViewModel.onNotificationIconChipClicked",
            launchClockActivityOnCollapse = !isDesktopFeatureSetEnabled(),
        )
    }

    private fun isDesktopFeatureSetEnabled(): Boolean {
        return context.resources.getBoolean(R.bool.config_enableDesktopFeatureSet)
    }

    private fun toggleNotificationShade(
        loggingReason: String,
        launchClockActivityOnCollapse: Boolean,
    ) {
        val currentOverlays = sceneInteractor.currentOverlays.value
        if (Overlays.NotificationsShade in currentOverlays) {
            shadeInteractor.collapseNotificationsShade(
                loggingReason = loggingReason,
                transitionKey = SlightlyFasterShadeCollapse,
            )
            onClockClicked()
            if (launchClockActivityOnCollapse) {
                clockInteractor.launchClockActivity()
            }
        } else {
            shadeInteractor.expandNotificationsShade(loggingReason)
        }