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

Commit cdbccfa3 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB][Notif] Use PromotedNotificationContentModel.time for chip time.

`PromotedNotificationContentModel` has a `time` field, so we should
re-use that field instead of having a custom `whenTime` field.

This CL also updates the chip to not show the time if
`Notification.showWhen` is false (if `showWhen` is false, then
`PNCModel.time` will be null).

Bug: 364653005
Flag: com.android.systemui.status_bar_notification_chips
Test: Post RON with showWhen=false -> verify chip just shows icon
Test: Post RON with showWhen=true -> verify chip shows time difference
("4min" for 4 minutes in the future, "1hr ago" for 1 hour in the past)
Test: atest NotifChipsViewModelTest SingleNotificationChipInteractorTest

Change-Id: I43d2c6cf2bd70ef2232cbd66357893e201a4f8dd
parent 403e530d
Loading
Loading
Loading
Loading
+5 −25
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.statusbar.StatusBarIconView
import com.android.systemui.statusbar.chips.notification.domain.model.NotificationChipModel
import com.android.systemui.statusbar.core.StatusBarConnectedDisplays
import com.android.systemui.statusbar.notification.data.model.activeNotificationModel
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel
@@ -50,7 +49,6 @@ class SingleNotificationChipInteractorTest : SysuiTestCase() {
                activeNotificationModel(
                    key = "notif1",
                    statusBarChipIcon = icon,
                    whenTime = 5432,
                    promotedContent = PROMOTED_CONTENT,
                )

@@ -60,7 +58,7 @@ class SingleNotificationChipInteractorTest : SysuiTestCase() {

            assertThat(latest!!.key).isEqualTo("notif1")
            assertThat(latest!!.statusBarChipIconView).isEqualTo(icon)
            assertThat(latest!!.whenTime).isEqualTo(5432)
            assertThat(latest!!.promotedContent).isEqualTo(PROMOTED_CONTENT)
        }

    @Test
@@ -83,14 +81,12 @@ class SingleNotificationChipInteractorTest : SysuiTestCase() {
                activeNotificationModel(
                    key = "notif1",
                    statusBarChipIcon = newIconView,
                    whenTime = 6543,
                    promotedContent = PROMOTED_CONTENT,
                )
            )

            assertThat(latest!!.key).isEqualTo("notif1")
            assertThat(latest!!.statusBarChipIconView).isEqualTo(newIconView)
            assertThat(latest!!.whenTime).isEqualTo(6543)
        }

    @Test
@@ -174,22 +170,14 @@ class SingleNotificationChipInteractorTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif1",
                        statusBarChipIcon = null,
                        whenTime = 123L,
                        promotedContent = PROMOTED_CONTENT,
                    )
                )

            val latest by collectLastValue(underTest.notificationChip)

            assertThat(latest)
                .isEqualTo(
                    NotificationChipModel(
                        "notif1",
                        statusBarChipIconView = null,
                        whenTime = 123L,
                        promotedContent = PROMOTED_CONTENT,
                    )
                )
            assertThat(latest).isNotNull()
            assertThat(latest!!.key).isEqualTo("notif1")
        }

    @Test
@@ -234,20 +222,12 @@ class SingleNotificationChipInteractorTest : SysuiTestCase() {
                activeNotificationModel(
                    key = "notif1",
                    statusBarChipIcon = null,
                    whenTime = 123L,
                    promotedContent = PROMOTED_CONTENT,
                )
            )

            assertThat(latest)
                .isEqualTo(
                    NotificationChipModel(
                        key = "notif1",
                        statusBarChipIconView = null,
                        whenTime = 123L,
                        promotedContent = PROMOTED_CONTENT,
                    )
                )
            assertThat(latest).isNotNull()
            assertThat(latest!!.key).isEqualTo("notif1")
        }

    @Test
+125 −6
Original line number Diff line number Diff line
@@ -241,16 +241,130 @@ class NotifChipsViewModelTest : SysuiTestCase() {
            assertIsNotifKey(latest!![1], secondKey)
        }


    @Test
    fun chips_noTime_isIconOnly() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)

            val promotedContentBuilder =
                PromotedNotificationContentModel.Builder("notif").apply { this.time = null }
            setNotifs(
                listOf(
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = mock<StatusBarIconView>(),
                        promotedContent = promotedContentBuilder.build(),
                    )
                )
            )

            assertThat(latest).hasSize(1)
            assertThat(latest!![0])
                .isInstanceOf(OngoingActivityChipModel.Shown.IconOnly::class.java)
        }

    @Test
    fun chips_basicTime_isShortTimeDelta() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)

            val promotedContentBuilder =
                PromotedNotificationContentModel.Builder("notif").apply {
                    this.time =
                        PromotedNotificationContentModel.When(
                            time = 6543L,
                            mode = PromotedNotificationContentModel.When.Mode.BasicTime,
                        )
                }
            setNotifs(
                listOf(
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = mock<StatusBarIconView>(),
                        promotedContent = promotedContentBuilder.build(),
                    )
                )
            )

            assertThat(latest).hasSize(1)
            assertThat(latest!![0])
                .isInstanceOf(OngoingActivityChipModel.Shown.ShortTimeDelta::class.java)
        }

    @Test
    fun chips_countUpTime_isTimer() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)

            val promotedContentBuilder =
                PromotedNotificationContentModel.Builder("notif").apply {
                    this.time =
                        PromotedNotificationContentModel.When(
                            time = 6543L,
                            mode = PromotedNotificationContentModel.When.Mode.CountUp,
                        )
                }
            setNotifs(
                listOf(
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = mock<StatusBarIconView>(),
                        promotedContent = promotedContentBuilder.build(),
                    )
                )
            )

            assertThat(latest).hasSize(1)
            assertThat(latest!![0]).isInstanceOf(OngoingActivityChipModel.Shown.Timer::class.java)
        }

    @Test
    fun chips_countDownTime_isTimer() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)

            val promotedContentBuilder =
                PromotedNotificationContentModel.Builder("notif").apply {
                    this.time =
                        PromotedNotificationContentModel.When(
                            time = 6543L,
                            mode = PromotedNotificationContentModel.When.Mode.CountDown,
                        )
                }
            setNotifs(
                listOf(
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = mock<StatusBarIconView>(),
                        promotedContent = promotedContentBuilder.build(),
                    )
                )
            )

            assertThat(latest).hasSize(1)
            assertThat(latest!![0]).isInstanceOf(OngoingActivityChipModel.Shown.Timer::class.java)
        }

    @Test
    fun chips_noHeadsUp_showsTime() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)

            val promotedContentBuilder =
                PromotedNotificationContentModel.Builder("notif").apply {
                    this.time =
                        PromotedNotificationContentModel.When(
                            time = 6543L,
                            mode = PromotedNotificationContentModel.When.Mode.BasicTime,
                        )
                }
            setNotifs(
                listOf(
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = mock<StatusBarIconView>(),
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                        promotedContent = promotedContentBuilder.build(),
                    )
                )
            )
@@ -267,12 +381,21 @@ class NotifChipsViewModelTest : SysuiTestCase() {
    fun chips_hasHeadsUpByUser_onlyShowsIcon() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)

            val promotedContentBuilder =
                PromotedNotificationContentModel.Builder("notif").apply {
                    this.time =
                        PromotedNotificationContentModel.When(
                            time = 6543L,
                            mode = PromotedNotificationContentModel.When.Mode.BasicTime,
                        )
                }
            setNotifs(
                listOf(
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = mock<StatusBarIconView>(),
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                        promotedContent = promotedContentBuilder.build(),
                    )
                )
            )
@@ -324,15 +447,11 @@ class NotifChipsViewModelTest : SysuiTestCase() {

    companion object {
        fun assertIsNotifChip(latest: OngoingActivityChipModel?, expectedIcon: StatusBarIconView) {
            assertThat(latest)
                .isInstanceOf(OngoingActivityChipModel.Shown.ShortTimeDelta::class.java)
            assertThat((latest as OngoingActivityChipModel.Shown).icon)
                .isEqualTo(OngoingActivityChipModel.ChipIcon.StatusBarView(expectedIcon))
        }

        fun assertIsNotifKey(latest: OngoingActivityChipModel?, expectedKey: String) {
            assertThat(latest)
                .isInstanceOf(OngoingActivityChipModel.Shown.ShortTimeDelta::class.java)
            assertThat((latest as OngoingActivityChipModel.Shown).icon)
                .isEqualTo(OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon(expectedKey))
        }
+1 −1
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ constructor(
            }
        }

        return NotificationChipModel(key, statusBarChipIconView, whenTime, promotedContent)
        return NotificationChipModel(key, statusBarChipIconView, promotedContent)
    }

    @AssistedFactory
+0 −2
Original line number Diff line number Diff line
@@ -23,7 +23,5 @@ import com.android.systemui.statusbar.notification.promoted.shared.model.Promote
data class NotificationChipModel(
    val key: String,
    val statusBarChipIconView: StatusBarIconView?,
    // TODO(b/364653005): Use [PromotedNotificationContentModel.time] instead of a custom field.
    val whenTime: Long,
    val promotedContent: PromotedNotificationContentModel,
)
+35 −12
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel
import com.android.systemui.statusbar.core.StatusBarConnectedDisplays
import com.android.systemui.statusbar.notification.domain.interactor.HeadsUpNotificationInteractor
import com.android.systemui.statusbar.notification.headsup.PinnedStatus
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
@@ -82,21 +83,43 @@ constructor(
                    )
                }
            }
        return if (headsUpState == PinnedStatus.PinnedByUser) {

        if (headsUpState == PinnedStatus.PinnedByUser) {
            // If the user tapped the chip to show the HUN, we want to just show the icon because
            // the HUN will show the rest of the information.
            OngoingActivityChipModel.Shown.IconOnly(icon, colors, onClickListener)
        } else {
            OngoingActivityChipModel.Shown.ShortTimeDelta(
            return OngoingActivityChipModel.Shown.IconOnly(icon, colors, onClickListener)
        }

        if (this.promotedContent.time == null) {
            return OngoingActivityChipModel.Shown.IconOnly(icon, colors, onClickListener)
        }
        when (this.promotedContent.time.mode) {
            PromotedNotificationContentModel.When.Mode.BasicTime -> {
                return OngoingActivityChipModel.Shown.ShortTimeDelta(
                    icon,
                    colors,
                    time = this.promotedContent.time.time,
                    onClickListener,
                )
            }
            PromotedNotificationContentModel.When.Mode.CountUp -> {
                return OngoingActivityChipModel.Shown.Timer(
                    icon,
                    colors,
                    startTimeMs = this.promotedContent.time.time,
                    onClickListener,
                )
            }
            PromotedNotificationContentModel.When.Mode.CountDown -> {
                // TODO(b/364653005): Support CountDown.
                return OngoingActivityChipModel.Shown.Timer(
                    icon,
                    colors,
                time = this.whenTime,
                    startTimeMs = this.promotedContent.time.time,
                    onClickListener,
                )
            }
        // TODO(b/364653005): Use Notification.showWhen to determine if we should show the time.
        }
        // TODO(b/364653005): If Notification.shortCriticalText is set, use that instead of `when`.
        // TODO(b/364653005): If the app that posted the notification is in the foreground, don't
        // show that app's chip.
    }
}
Loading