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

Commit ab0315f3 authored by András Kurucz's avatar András Kurucz
Browse files

Restore the pre-flexi code path of maxDisplayedNotifications

This CL is a cleanup to restore the old maxDisplayedNotifications API,
that was in place pre- I083472c936d9057544c71ab58a7162b15465f9ec.

Flexiglass needs to couple the values that are meant to be updated
together with maxDisplayedNotifications, so we've migrated this API to
provide a data class.
Later on the calculation of these values have diverted so much between
the legacy and the flexi path, that it didn't make sense to keep them
together, and flexi received its own LockscreenDisplayConfig from a new
interactor. This meant that we can clean up the flexi specific code from
the legacy maxDisplayedNotifications. That's happening in this CL.

Bug: 361324188
Test: Check the Notifications behaviour over LockScreen
Flag: EXEMPT refactor
Change-Id: I5b22e315c411b833fc4fe2bbd8dbb85cee747429
parent 8590371f
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -843,26 +843,27 @@ class SharedNotificationContainerViewModelTest(flags: FlagsParameterization) : S
        kosmos.runTest {
            var notificationCount = 10
            val calculateSpace = { space: Float, useExtraShelfSpace: Boolean -> notificationCount }
            val config by collectLastValue(underTest.getLockscreenDisplayConfig(calculateSpace))
            val maxNotifications by collectLastValue(underTest.getMaxNotifications(calculateSpace))
            testScope.advanceTimeBy(50L)
            showLockscreen()

            shadeTestUtil.setSplitShade(false)
            fakeConfigurationRepository.onAnyConfigurationChange()

            assertThat(config?.maxNotifications).isEqualTo(10)
            assertThat(maxNotifications).isEqualTo(10)

            // Also updates when directly requested (as it would from NotificationStackScrollLayout)
            notificationCount = 25
            sharedNotificationContainerInteractor.notificationStackChanged()
            testScope.advanceTimeBy(50L)
            assertThat(config?.maxNotifications).isEqualTo(25)
            assertThat(maxNotifications).isEqualTo(25)

            // Also ensure another collection starts with the same value. As an example, folding
            // then unfolding will restart the coroutine and it must get the last value immediately.
            val newConfig by collectLastValue(underTest.getLockscreenDisplayConfig(calculateSpace))
            val newMaxNotifications by
                collectLastValue(underTest.getMaxNotifications(calculateSpace))
            testScope.advanceTimeBy(50L)
            assertThat(newConfig?.maxNotifications).isEqualTo(25)
            assertThat(newMaxNotifications).isEqualTo(25)
        }

    @Test
@@ -871,17 +872,17 @@ class SharedNotificationContainerViewModelTest(flags: FlagsParameterization) : S
            enableSingleShade()
            var notificationCount = 10
            val calculateSpace = { space: Float, useExtraShelfSpace: Boolean -> notificationCount }
            val config by collectLastValue(underTest.getLockscreenDisplayConfig(calculateSpace))
            val maxNotifications by collectLastValue(underTest.getMaxNotifications(calculateSpace))
            testScope.advanceTimeBy(50L)
            showLockscreen()

            fakeConfigurationRepository.onAnyConfigurationChange()

            assertThat(config?.maxNotifications).isEqualTo(10)
            assertThat(maxNotifications).isEqualTo(10)

            // Shade expanding... still 10
            shadeTestUtil.setLockscreenShadeExpansion(0.5f)
            assertThat(config?.maxNotifications).isEqualTo(10)
            assertThat(maxNotifications).isEqualTo(10)

            notificationCount = 25

@@ -889,20 +890,20 @@ class SharedNotificationContainerViewModelTest(flags: FlagsParameterization) : S
            shadeTestUtil.setLockscreenShadeTracking(true)

            // Should still be 10, since the user is interacting
            assertThat(config?.maxNotifications).isEqualTo(10)
            assertThat(maxNotifications).isEqualTo(10)

            shadeTestUtil.setLockscreenShadeTracking(false)
            shadeTestUtil.setLockscreenShadeExpansion(0f)

            // Stopped tracking, show 25
            assertThat(config?.maxNotifications).isEqualTo(25)
            assertThat(maxNotifications).isEqualTo(25)
        }

    @Test
    fun maxNotificationsOnShade() =
        kosmos.runTest {
            val calculateSpace = { space: Float, useExtraShelfSpace: Boolean -> 10 }
            val config by collectLastValue(underTest.getLockscreenDisplayConfig(calculateSpace))
            val maxNotifications by collectLastValue(underTest.getMaxNotifications(calculateSpace))
            testScope.advanceTimeBy(50L)

            // Show lockscreen with shade expanded
@@ -912,7 +913,7 @@ class SharedNotificationContainerViewModelTest(flags: FlagsParameterization) : S
            fakeConfigurationRepository.onAnyConfigurationChange()

            // -1 means No Limit
            assertThat(config?.maxNotifications).isEqualTo(-1)
            assertThat(maxNotifications).isEqualTo(-1)
        }

    @Test
+0 −3
Original line number Diff line number Diff line
@@ -100,9 +100,6 @@ public interface NotificationListContainer extends
     */
    void addContainerViewAt(View v, int index);

    /** Sets whether the notificatios are displayed on the unoccluded lockscreen. */
    void setOnLockscreen(boolean isOnKeyguard);

    /**
     * Sets the maximum number of notifications to display.
     *
+0 −11
Original line number Diff line number Diff line
@@ -1613,12 +1613,6 @@ public class NotificationStackScrollLayoutController implements Dumpable {
        mView.setPulsing(pulsing, animatePulse);
    }

    /** Sets whether the NSSL is displayed over the unoccluded Lockscreen. */
    public void setOnLockscreen(boolean isOnLockscreen) {
        if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return;
        mNotificationListContainer.setOnLockscreen(isOnLockscreen);
    }

    /**
     * Set the maximum number of notifications that can currently be displayed
     */
@@ -2031,11 +2025,6 @@ public class NotificationStackScrollLayoutController implements Dumpable {
            mView.addContainerViewAt(v, index);
        }

        @Override
        public void setOnLockscreen(boolean isOnLockscreen) {
            mView.setOnLockscreen(isOnLockscreen);
        }

        @Override
        public void setMaxDisplayedNotifications(int maxNotifications) {
            mView.setMaxDisplayedNotifications(maxNotifications);
+3 −8
Original line number Diff line number Diff line
@@ -119,13 +119,8 @@ constructor(

                    if (!SceneContainerFlag.isEnabled) {
                        launch {
                            viewModel
                                .getLockscreenDisplayConfig(calculateMaxNotifications)
                                .collect { (isOnLockscreen, maxNotifications) ->
                                    if (SceneContainerFlag.isEnabled) {
                                        controller.setOnLockscreen(isOnLockscreen)
                                    }
                                    controller.setMaxDisplayedNotifications(maxNotifications)
                            viewModel.getMaxNotifications(calculateMaxNotifications).collect {
                                controller.setMaxDisplayedNotifications(it)
                            }
                        }
                    }
+10 −36
Original line number Diff line number Diff line
@@ -850,11 +850,9 @@ constructor(
     * When expanding or when the user is interacting with the shade, keep the count stable; do not
     * emit a value.
     */
    fun getLockscreenDisplayConfig(
        calculateSpace: (Float, Boolean) -> Int
    ): Flow<LockscreenDisplayConfig> {
    fun getMaxNotifications(calculateSpace: (Float, Boolean) -> Int): Flow<Int> {
        val showLimitedNotifications = isOnLockscreenWithoutShade
        val showUnlimitedNotificationsAndIsOnLockScreen =
        val showUnlimitedNotifications =
            combine(
                    isOnLockscreen,
                    keyguardInteractor.statusBarState,
@@ -864,43 +862,31 @@ constructor(
                        )
                        .onStart { emit(false) },
                ) { isOnLockscreen, statusBarState, showAllNotifications ->
                    (statusBarState == SHADE_LOCKED || !isOnLockscreen || showAllNotifications) to
                        isOnLockscreen
                    statusBarState == SHADE_LOCKED || !isOnLockscreen || showAllNotifications
                }
                .dumpWhileCollecting("showUnlimitedNotificationsAndIsOnLockScreen")
                .dumpWhileCollecting("showUnlimitedNotifications")

        @Suppress("UNCHECKED_CAST")
        return combineTransform(
                showLimitedNotifications,
                showUnlimitedNotificationsAndIsOnLockScreen,
                showUnlimitedNotifications,
                shadeInteractor.isUserInteracting.dumpWhileCollecting("isUserInteracting"),
                availableHeight,
                interactor.useExtraShelfSpace,
                interactor.notificationStackChanged,
            ) { flows ->
                val showLimitedNotifications = flows[0] as Boolean
                val (showUnlimitedNotifications, isOnLockscreen) =
                    flows[1] as Pair<Boolean, Boolean>
                val showUnlimitedNotifications = flows[1] as Boolean
                val isUserInteracting = flows[2] as Boolean
                val availableHeight = flows[3] as Float
                val useExtraShelfSpace = flows[4] as Boolean

                if (!isUserInteracting) {
                    if (showLimitedNotifications) {
                        emit(
                            LockscreenDisplayConfig(
                                isOnLockscreen = isOnLockscreen,
                                maxNotifications =
                                    calculateSpace(availableHeight, useExtraShelfSpace),
                            )
                        )
                        emit(calculateSpace(availableHeight, useExtraShelfSpace))
                    } else if (showUnlimitedNotifications) {
                        emit(
                            LockscreenDisplayConfig(
                                isOnLockscreen = isOnLockscreen,
                                maxNotifications = -1,
                            )
                        )
                        // -1 means no limit
                        emit(-1)
                    }
                }
            }
@@ -931,10 +917,7 @@ constructor(
            .flatMapLatest { (hasNotifications, isOnLockscreen, hasActiveMedia) ->
                if ((hasNotifications || hasActiveMedia) && isOnLockscreen) {
                    combine(
                            getLockscreenDisplayConfig(calculateMaxNotifications).map {
                                (_, maxNotifications) ->
                                maxNotifications
                            },
                            getMaxNotifications(calculateMaxNotifications),
                            bounds.map { it.top },
                            isOnLockscreenWithoutShade,
                            interactor.notificationStackChanged,
@@ -983,13 +966,4 @@ constructor(
        /** The container is laid out from the given [ratio] of the screen width to the end edge. */
        data class MiddleToEdge(val ratio: Float = 0.5f) : HorizontalPosition
    }

    /**
     * Data class representing a configuration for displaying Notifications on the Lockscreen.
     *
     * @param isOnLockscreen is the user on the lockscreen
     * @param maxNotifications Limit for the max number of top-level Notifications to be displayed.
     *   A value of -1 indicates no limit.
     */
    data class LockscreenDisplayConfig(val isOnLockscreen: Boolean, val maxNotifications: Int)
}