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

Commit 20565500 authored by András Kurucz's avatar András Kurucz Committed by Android (Google) Code Review
Browse files

Merge "Flag creating HeadsUpNotificationInteractor's flows" into main

parents c1a45cb5 4c97b407
Loading
Loading
Loading
Loading
+59 −36
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.statusbar.notification.data.repository.HeadsUpRepository
import com.android.systemui.statusbar.notification.data.repository.HeadsUpRowRepository
import com.android.systemui.statusbar.notification.shared.HeadsUpRowKey
import com.android.systemui.statusbar.notification.shared.NotificationsHeadsUpRefactor
import javax.inject.Inject
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
@@ -50,11 +51,16 @@ constructor(
    val topHeadsUpRow: Flow<HeadsUpRowKey?> = headsUpRepository.topHeadsUpRow

    /** Set of currently pinned top-level heads up rows to be displayed. */
    val pinnedHeadsUpRows: Flow<Set<HeadsUpRowKey>> =
    val pinnedHeadsUpRows: Flow<Set<HeadsUpRowKey>> by lazy {
        if (NotificationsHeadsUpRefactor.isUnexpectedlyInLegacyMode()) {
            flowOf(emptySet())
        } else {
            headsUpRepository.activeHeadsUpRows.flatMapLatest { repositories ->
                if (repositories.isNotEmpty()) {
                    val toCombine: List<Flow<Pair<HeadsUpRowRepository, Boolean>>> =
                    repositories.map { repo -> repo.isPinned.map { isPinned -> repo to isPinned } }
                        repositories.map { repo ->
                            repo.isPinned.map { isPinned -> repo to isPinned }
                        }
                    combine(toCombine) { pairs ->
                        pairs.filter { (_, isPinned) -> isPinned }.map { (repo, _) -> repo }.toSet()
                    }
@@ -63,9 +69,14 @@ constructor(
                    flowOf(emptySet())
                }
            }
        }
    }

    /** Are there any pinned heads up rows to display? */
    val hasPinnedRows: Flow<Boolean> =
    val hasPinnedRows: Flow<Boolean> by lazy {
        if (NotificationsHeadsUpRefactor.isUnexpectedlyInLegacyMode()) {
            flowOf(false)
        } else {
            headsUpRepository.activeHeadsUpRows.flatMapLatest { rows ->
                if (rows.isNotEmpty()) {
                    combine(rows.map { it.isPinned }) { pins -> pins.any { it } }
@@ -74,8 +85,13 @@ constructor(
                    flowOf(false)
                }
            }
        }
    }

    val isHeadsUpOrAnimatingAway: Flow<Boolean> =
    val isHeadsUpOrAnimatingAway: Flow<Boolean> by lazy {
        if (NotificationsHeadsUpRefactor.isUnexpectedlyInLegacyMode()) {
            flowOf(false)
        } else {
            combine(hasPinnedRows, headsUpRepository.isHeadsUpAnimatingAway) {
                    hasPinnedRows,
                    animatingAway ->
@@ -92,6 +108,8 @@ constructor(
                }
                .onStart { emit(false) } // emit false, so we don't wait for the initial update
                .distinctUntilChanged()
        }
    }

    private val canShowHeadsUp: Flow<Boolean> =
        combine(
@@ -109,10 +127,15 @@ constructor(
            }
        }

    val showHeadsUpStatusBar: Flow<Boolean> =
    val showHeadsUpStatusBar: Flow<Boolean> by lazy {
        if (NotificationsHeadsUpRefactor.isUnexpectedlyInLegacyMode()) {
            flowOf(false)
        } else {
            combine(hasPinnedRows, canShowHeadsUp) { hasPinnedRows, canShowHeadsUp ->
                hasPinnedRows && canShowHeadsUp
            }
        }
    }

    fun headsUpRow(key: HeadsUpRowKey): HeadsUpRowInteractor =
        HeadsUpRowInteractor(key as HeadsUpRowRepository)
+3 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.ui.viewmodel

import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.FlagsParameterization
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -32,6 +33,7 @@ import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.statusbar.domain.interactor.keyguardStatusBarInteractor
import com.android.systemui.statusbar.notification.data.repository.FakeHeadsUpRowRepository
import com.android.systemui.statusbar.notification.shared.NotificationsHeadsUpRefactor
import com.android.systemui.statusbar.notification.stack.data.repository.headsUpNotificationRepository
import com.android.systemui.statusbar.notification.stack.data.repository.setNotifications
import com.android.systemui.statusbar.notification.stack.domain.interactor.headsUpNotificationInteractor
@@ -126,6 +128,7 @@ class KeyguardStatusBarViewModelTest(flags: FlagsParameterization) : SysuiTestCa
        }

    @Test
    @EnableFlags(NotificationsHeadsUpRefactor.FLAG_NAME)
    fun isVisible_headsUpStatusBarShown_false() =
        testScope.runTest {
            val latest by collectLastValue(underTest.isVisible)