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

Commit a314b132 authored by Matt Pietal's avatar Matt Pietal
Browse files

On fold/unfold, recalculate notif count immediately

One of the dependent flows was using shareIn, which prevents
the combine from running right away. Switching to stateIn
allows caching of the last value, which is the correct model
for this. Fold/unfold triggers this because the view is
detached then reattached, causing the previous coroutine
to stop and a new one to start.

Fixes: 331164146
Test: atest SharedNotificationContainerViewModelTest
Flag: ACONFIG com.android.systemui.migrate_clocks_to_blueprint
TEAMFOOD

Change-Id: Ib5ce8e77f6e07c925398a3ccc4af9144894cad43
parent fdfea51d
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -585,6 +585,12 @@ class SharedNotificationContainerViewModelTest : SysuiTestCase() {
            notificationCount = 25
            sharedNotificationContainerInteractor.notificationStackChanged()
            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 newMaxNotifications by
                collectLastValue(underTest.getMaxNotifications(calculateSpace))
            assertThat(newMaxNotifications).isEqualTo(25)
        }

    @Test
+6 −3
Original line number Diff line number Diff line
@@ -82,7 +82,6 @@ import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.transformWhile
import kotlinx.coroutines.isActive
@@ -198,8 +197,12 @@ constructor(
            ) { constrainedNotificationState, transitioningToOrFromLockscreen ->
                constrainedNotificationState || transitioningToOrFromLockscreen
            }
            .shareIn(scope = applicationScope, started = SharingStarted.Eagerly)
            .dumpWhileCollecting("isOnLockscreen")
            .stateIn(
                scope = applicationScope,
                started = SharingStarted.Eagerly,
                initialValue = false
            )
            .dumpValue("isOnLockscreen")

    /** Are we purely on the keyguard without the shade/qs? */
    val isOnLockscreenWithoutShade: Flow<Boolean> =