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

Commit a9e2b1ce authored by Julia Tuttle's avatar Julia Tuttle Committed by Android (Google) Code Review
Browse files

Merge "Support 'base' notifications with null style" into main

parents 974cd4aa 1cbeadaa
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -171,6 +171,17 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {
        assertThat(content?.shortCriticalText).isNull()
    }

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractsContent_fromBaseStyle() {
        val entry = createEntry { setStyle(null) }

        val content = extractContent(entry)

        assertThat(content).isNotNull()
        assertThat(content?.style).isEqualTo(Style.Base)
    }

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractsContent_fromBigPictureStyle() {
+14 −10
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ private val PromotedNotificationContentModel.layoutResource: Int?
    get() {
        return if (Flags.notificationsRedesignTemplates()) {
            when (style) {
                Style.Base -> R.layout.notification_2025_template_expanded_base
                Style.BigPicture -> R.layout.notification_2025_template_expanded_big_picture
                Style.BigText -> R.layout.notification_2025_template_expanded_big_text
                Style.Call -> R.layout.notification_2025_template_expanded_call
@@ -86,6 +87,7 @@ private val PromotedNotificationContentModel.layoutResource: Int?
            }
        } else {
            when (style) {
                Style.Base -> R.layout.notification_template_material_big_base
                Style.BigPicture -> R.layout.notification_template_material_big_picture
                Style.BigText -> R.layout.notification_template_material_big_text
                Style.Call -> R.layout.notification_template_material_big_call
@@ -133,6 +135,7 @@ private class AODPromotedNotificationViewUpdater(root: View) {

    fun update(content: PromotedNotificationContentModel) {
        when (content.style) {
            Style.Base -> updateBase(content)
            Style.BigPicture -> updateBigPicture(content)
            Style.BigText -> updateBigText(content)
            Style.Call -> updateCall(content)
@@ -141,20 +144,24 @@ private class AODPromotedNotificationViewUpdater(root: View) {
        }
    }

    private fun updateBigPicture(content: PromotedNotificationContentModel) {
    private fun updateBase(
        content: PromotedNotificationContentModel,
        textView: ImageFloatingTextView? = null,
    ) {
        updateHeader(content)

        updateTitle(title, content)
        updateText(text, content)
        updateText(textView ?: text, content)
    }

    private fun updateBigPicture(content: PromotedNotificationContentModel) {
        updateBase(content)

        bigPicture?.visibility = GONE
    }

    private fun updateBigText(content: PromotedNotificationContentModel) {
        updateHeader(content)

        updateTitle(title, content)
        updateText(bigText, content)
        updateBase(content, textView = bigText)
    }

    private fun updateCall(content: PromotedNotificationContentModel) {
@@ -164,10 +171,7 @@ private class AODPromotedNotificationViewUpdater(root: View) {
    }

    private fun updateProgress(content: PromotedNotificationContentModel) {
        updateHeader(content)

        updateTitle(title, content)
        updateText(text, content)
        updateBase(content)

        updateNewProgressBar(content)
    }
+11 −8
Original line number Diff line number Diff line
@@ -98,8 +98,7 @@ constructor(
                primaryTextColor = colorsFromNotif.primaryTextColor,
            )

        recoveredBuilder.style?.extractContent(contentBuilder)
            ?: run { contentBuilder.style = Style.Ineligible }
        recoveredBuilder.extractStyleContent(contentBuilder)

        return contentBuilder.build().also { logger.logExtractionSucceeded(entry, it) }
    }
@@ -140,28 +139,32 @@ private fun Notification.extractWhen(): When? {
    }
}

private fun Notification.Style.extractContent(
private fun Notification.Builder.extractStyleContent(
    contentBuilder: PromotedNotificationContentModel.Builder
) {
    val style = this.style

    contentBuilder.style =
        when (this) {
        when (style) {
            null -> Style.Base

            is BigPictureStyle -> {
                extractContent(contentBuilder)
                style.extractContent(contentBuilder)
                Style.BigPicture
            }

            is BigTextStyle -> {
                extractContent(contentBuilder)
                style.extractContent(contentBuilder)
                Style.BigText
            }

            is CallStyle -> {
                extractContent(contentBuilder)
                style.extractContent(contentBuilder)
                Style.Call
            }

            is ProgressStyle -> {
                extractContent(contentBuilder)
                style.extractContent(contentBuilder)
                Style.Progress
            }

+1 −0
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ data class PromotedNotificationContentModel(

    /** The promotion-eligible style of a notification, or [Style.Ineligible] if not. */
    enum class Style {
        Base, // style == null
        BigPicture,
        BigText,
        Call,