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

Commit 4e864a5c authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Simplify OngoingActivityChipsViewModel, remove isScreenReasonablyLarge." into main

parents 3ada4be7 b1c17dd1
Loading
Loading
Loading
Loading
+6 −55
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package com.android.systemui.statusbar.chips.ui.viewmodel

import android.content.DialogInterface
import android.content.packageManager
import android.content.res.Configuration
import android.content.res.mainResources
import android.graphics.Bitmap
import android.graphics.RectF
import android.graphics.drawable.BitmapDrawable
@@ -30,7 +28,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.animation.Expandable
import com.android.systemui.common.ui.data.repository.fakeConfigurationRepository
import com.android.systemui.display.data.repository.displayStateRepository
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.collectLastValue
@@ -558,59 +555,13 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {

    @DisableChipsModernization
    @Test
    fun chipsLegacy_twoChips_isLandscape_notSquished() =
    fun chipsLegacy_twoChips_isWideScreen_notSquished() =
        kosmos.runTest {
            screenRecordState.value = ScreenRecordModel.Recording
            addOngoingCallState(key = "call", isAppVisible = false)

            // WHEN we're in landscape
            val config =
                Configuration(kosmos.mainResources.configuration).apply {
                    orientation = Configuration.ORIENTATION_LANDSCAPE
                }
            kosmos.fakeConfigurationRepository.onConfigurationChange(config)

            val latest by collectLastValue(underTest.chipsLegacy)

            // THEN the chips aren't squished (squished chips would be icon only)
            assertThat((latest!!.primary as OngoingActivityChipModel.Active).content)
                .isInstanceOf(OngoingActivityChipModel.Content.Timer::class.java)
            assertThat((latest!!.secondary as OngoingActivityChipModel.Active).content)
                .isInstanceOf(OngoingActivityChipModel.Content.Timer::class.java)
        }

    @EnableChipsModernization
    @Test
    fun chips_twoChips_isLandscape_notSquished() =
        kosmos.runTest {
            screenRecordState.value = ScreenRecordModel.Recording
            addOngoingCallState(key = "call")

            // WHEN we're in landscape
            val config =
                Configuration(kosmos.mainResources.configuration).apply {
                    orientation = Configuration.ORIENTATION_LANDSCAPE
                }
            kosmos.fakeConfigurationRepository.onConfigurationChange(config)

            val latest by collectLastValue(underTest.chips)

            // THEN the chips aren't squished (squished chips would be icon only)
            assertThat(latest!!.active[0].content)
                .isInstanceOf(OngoingActivityChipModel.Content.Timer::class.java)
            assertThat(latest!!.active[1].content)
                .isInstanceOf(OngoingActivityChipModel.Content.Timer::class.java)
        }

    @DisableChipsModernization
    @Test
    fun chipsLegacy_twoChips_isLargeScreen_notSquished() =
        kosmos.runTest {
            screenRecordState.value = ScreenRecordModel.Recording
            addOngoingCallState(key = "call", isAppVisible = false)

            // WHEN we're on a large screen
            kosmos.displayStateRepository.setIsLargeScreen(true)
            // WHEN we're on a wide screen
            kosmos.displayStateRepository.setIsWideScreen(true)

            val latest by collectLastValue(underTest.chipsLegacy)

@@ -623,13 +574,13 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {

    @EnableChipsModernization
    @Test
    fun chips_twoChips_isLargeScreen_notSquished() =
    fun chips_twoChips_isWideScreen_notSquished() =
        kosmos.runTest {
            screenRecordState.value = ScreenRecordModel.Recording
            addOngoingCallState(key = "call")

            // WHEN we're on a large screen
            kosmos.displayStateRepository.setIsLargeScreen(true)
            // WHEN we're on a wide screen
            kosmos.displayStateRepository.setIsWideScreen(true)

            val latest by collectLastValue(underTest.chips)

+15 −55
Original line number Diff line number Diff line
@@ -16,9 +16,7 @@

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

import android.content.res.Configuration
import android.graphics.RectF
import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.display.domain.interactor.DisplayStateInteractor
@@ -49,7 +47,6 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn

/**
@@ -69,29 +66,8 @@ constructor(
    callChipViewModel: CallChipViewModel,
    notifChipsViewModel: NotifChipsViewModel,
    displayStateInteractor: DisplayStateInteractor,
    configurationInteractor: ConfigurationInteractor,
    @StatusBarChipsLog private val logger: LogBuffer,
) {
    private val isLandscape: Flow<Boolean> =
        configurationInteractor.configurationValues
            .map { it.isLandscape }
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)

    private val isScreenReasonablyLarge: Flow<Boolean> =
        combine(isLandscape, displayStateInteractor.isLargeScreen) { isLandscape, isLargeScreen ->
                isLandscape || isLargeScreen
            }
            .distinctUntilChanged()
            .onEach {
                logger.log(
                    TAG,
                    LogLevel.DEBUG,
                    { bool1 = it },
                    { "isScreenReasonablyLarge: $bool1" },
                )
            }
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)

    private enum class ChipType {
        ScreenRecord,
        ShareToApp,
@@ -168,10 +144,10 @@ constructor(
                    notifs = notifs,
                )
            }
            // Some of the chips could have timers in them and we don't want the start time
            // for those timers to get reset for any reason. So, as soon as any subscriber has
            // requested the chip information, we maintain it forever by using
            // [SharingStarted.Lazily]. See b/347726238.
            // Some of the chips could have timers in them and we don't want the start time for
            // those timers to get reset for any reason. So, as soon as any subscriber has requested
            // the chip information, we maintain it forever by using [SharingStarted.Lazily].
            // See b/347726238.
            .stateIn(scope, SharingStarted.Lazily, ChipBundle())

    private val internalChip: Flow<InternalChipModel> =
@@ -201,7 +177,7 @@ constructor(
    )

    private val internalChips: Flow<InternalMultipleOngoingActivityChipsModel> =
        combine(incomingChipBundle, isScreenReasonablyLarge) { bundle, isScreenReasonablyLarge ->
        combine(incomingChipBundle, displayStateInteractor.isWideScreen) { bundle, isWideScreen ->
            // First: Find the most important chip.
            val primaryChipResult = pickMostImportantChip(bundle)
            when (val primaryChip = primaryChipResult.mostImportantChip) {
@@ -217,7 +193,7 @@ constructor(
                    if (
                        secondaryChip is InternalChipModel.Active &&
                            PromotedNotificationUi.isEnabled &&
                            !isScreenReasonablyLarge
                            !isWideScreen
                    ) {
                        // If we have two showing chips and we don't have a ton of room
                        // (!isScreenReasonablyLarge), then we want to make both of them as small as
@@ -283,18 +259,18 @@ constructor(
        if (StatusBarChipsModernization.isEnabled) {
            combine(
                    incomingChipBundle.map { bundle -> rankChips(bundle) },
                    isScreenReasonablyLarge,
                ) { rankedChips, isScreenReasonablyLarge ->
                    displayStateInteractor.isWideScreen,
                ) { rankedChips, isWideScreen ->
                    if (
                        PromotedNotificationUi.isEnabled &&
                            !isScreenReasonablyLarge &&
                            !isWideScreen &&
                            rankedChips.active.filter { !it.isHidden }.size >= 2
                    ) {
                        // If we have at least two showing chips and we don't have a ton of room
                        // (!isScreenReasonablyLarge), then we want to make both of them as small as
                        // possible so that we have the highest chance of showing both chips (as
                        // opposed to showing the first chip with a lot of text and completely
                        // hiding the other chips).
                        // (!isWideScreen), then we want to make both of them as small as possible
                        // so that we have the highest chance of showing both chips (as opposed to
                        // showing the first chip with a lot of text and completely hiding the other
                        // chips).
                        val squishedActiveChips =
                            rankedChips.active.map {
                                if (!it.isHidden && it.shouldSquish()) {
@@ -357,14 +333,7 @@ constructor(
            chips.map { it.active }
        } else {
            chipsLegacy.map {
                val list = mutableListOf<OngoingActivityChipModel.Active>()
                if (it.primary is OngoingActivityChipModel.Active) {
                    list.add(it.primary)
                }
                if (it.secondary is OngoingActivityChipModel.Active) {
                    list.add(it.secondary)
                }
                list
                listOf(it.primary, it.secondary).filterIsInstance<OngoingActivityChipModel.Active>()
            }
        }

@@ -428,13 +397,7 @@ constructor(
        val inactiveChips = mutableListOf<OngoingActivityChipModel.Inactive>()

        val sortedChips =
            mutableListOf(
                    bundle.screenRecord,
                    bundle.shareToApp,
                    bundle.castToOtherDevice,
                    bundle.call,
                )
                .apply { bundle.notifs.forEach { add(it) } }
            with(bundle) { listOf(screenRecord, shareToApp, castToOtherDevice, call) + notifs }

        var shownSlotsRemaining = MAX_VISIBLE_CHIPS
        for (chip in sortedChips) {
@@ -582,9 +545,6 @@ constructor(
        }
    }

    private val Configuration.isLandscape: Boolean
        get() = orientation == Configuration.ORIENTATION_LANDSCAPE

    companion object {
        private val TAG = "ChipsViewModel".pad()

+0 −2
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

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

import com.android.systemui.common.ui.domain.interactor.configurationInteractor
import com.android.systemui.display.domain.interactor.displayStateInteractor
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.testScope
@@ -37,7 +36,6 @@ val Kosmos.ongoingActivityChipsViewModel: OngoingActivityChipsViewModel by
            callChipViewModel = callChipViewModel,
            notifChipsViewModel = notifChipsViewModel,
            displayStateInteractor = displayStateInteractor,
            configurationInteractor = configurationInteractor,
            logger = statusBarChipsLogger,
        )
    }