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

Commit 06d21441 authored by Julia Tuttle's avatar Julia Tuttle
Browse files

[AOD RONs] Clean up view updater a little

Also, discard blank CharSequences and Strings in the extractor.

Bug: 402147652
Bug: 402510675
Flag: com.android.systemui.aod_ui_rich_ongoing
Test: NA, refactor
Change-Id: I3d09322e8a3a76f2cb173a733fb347a9a3a50969
parent e50dd973
Loading
Loading
Loading
Loading
+25 −35
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui.statusbar.notification.promoted

import android.app.Flags
import android.app.Flags.notificationsRedesignTemplates
import android.app.Notification
import android.content.Context
@@ -202,7 +201,7 @@ private class FrameLayoutWithMaxHeight(maxHeight: Int, context: Context) : Frame

private val PromotedNotificationContentModel.layoutResource: Int?
    get() {
        return if (Flags.notificationsRedesignTemplates()) {
        return if (notificationsRedesignTemplates()) {
            when (style) {
                Style.Base -> R.layout.notification_2025_template_expanded_base
                Style.BigPicture -> R.layout.notification_2025_template_expanded_big_picture
@@ -289,7 +288,7 @@ private class AODPromotedNotificationViewUpdater(root: View) {
        setTextViewColor(timeDivider, SecondaryText)
        setTextViewColor(verificationDivider, SecondaryText)

        if (Flags.notificationsRedesignTemplates()) {
        if (notificationsRedesignTemplates()) {
            (mainColumn?.layoutParams as? MarginLayoutParams)?.let { mainColumnMargins ->
                mainColumnMargins.topMargin =
                    Notification.Builder.getContentMarginTop(
@@ -315,20 +314,16 @@ private class AODPromotedNotificationViewUpdater(root: View) {

    private fun updateBase(
        content: PromotedNotificationContentModel,
        textView: ImageFloatingTextView? = null,
        showOldProgress: Boolean = true,
        textView: ImageFloatingTextView? = text,
    ) {
        updateHeader(content, hideTitle = true)
        updateHeader(content)

        updateTitle(title, content)
        updateText(textView ?: text, content)
        updateText(textView, content)
        updateSmallIcon(icon, content)
        updateImageView(rightIcon, content.skeletonLargeIcon)

        if (showOldProgress) {
        updateOldProgressBar(content)
    }
    }

    private fun updateBigPictureStyle(content: PromotedNotificationContentModel) {
        updateBase(content)
@@ -345,13 +340,14 @@ private class AODPromotedNotificationViewUpdater(root: View) {
    }

    private fun updateProgressStyle(content: PromotedNotificationContentModel) {
        updateBase(content, showOldProgress = false)
        updateBase(content)

        updateNewProgressBar(content)
    }

    private fun updateOldProgressBar(content: PromotedNotificationContentModel) {
        if (
            content.style == Style.Progress ||
                content.oldProgress == null ||
                content.oldProgress.max == 0 ||
                content.oldProgress.isIndeterminate
@@ -381,27 +377,22 @@ private class AODPromotedNotificationViewUpdater(root: View) {
        }
    }

    private fun updateHeader(
        content: PromotedNotificationContentModel,
        hideTitle: Boolean = false,
    ) {
    private fun updateHeader(content: PromotedNotificationContentModel) {
        updateAppName(content)
        updateTextView(headerTextSecondary, content.subText)
        if (!hideTitle) {
            updateTitle(headerText, content)
        }
        // Not calling updateTitle(headerText, content) because the title is always a separate
        // element in the expanded layout used for AOD RONs.
        updateTimeAndChronometer(content)

        updateHeaderDividers(content, hideTitle = hideTitle)
        updateHeaderDividers(content)
    }

    private fun updateHeaderDividers(
        content: PromotedNotificationContentModel,
        hideTitle: Boolean = false,
    ) {
        val hasAppName = content.appName != null && content.appName.isNotEmpty()
        val hasSubText = content.subText != null && content.subText.isNotEmpty()
        val hasHeader = content.title != null && content.title.isNotEmpty() && !hideTitle
    private fun updateHeaderDividers(content: PromotedNotificationContentModel) {
        val hasAppName = content.appName != null
        val hasSubText = content.subText != null
        // Not setting hasHeader = content.title because the title is always a separate element in
        // the expanded layout used for AOD RONs.
        val hasHeader = false
        val hasTimeOrChronometer = content.time != null

        val hasTextBeforeSubText = hasAppName
@@ -421,7 +412,7 @@ private class AODPromotedNotificationViewUpdater(root: View) {
        updateTitle(conversationText, content)
        updateAppName(content)
        updateTimeAndChronometer(content)
        updateConversationHeaderDividers(content, hideTitle = true)
        updateConversationHeaderDividers(content)

        updateImageView(verificationIcon, content.verificationIcon)
        updateTextView(verificationText, content.verificationText)
@@ -429,15 +420,14 @@ private class AODPromotedNotificationViewUpdater(root: View) {
        updateSmallIcon(conversationIcon, content)
    }

    private fun updateConversationHeaderDividers(
        content: PromotedNotificationContentModel,
        hideTitle: Boolean = false,
    ) {
        val hasTitle = content.title != null && !hideTitle
    private fun updateConversationHeaderDividers(content: PromotedNotificationContentModel) {
        // Not setting hasTitle = content.title because the title is always a separate element in
        // the expanded layout used for AOD RONs.
        val hasTitle = false
        val hasAppName = content.appName != null
        val hasTimeOrChronometer = content.time != null
        val hasVerification =
            !content.verificationIcon.isNullOrEmpty() || !content.verificationText.isNullOrEmpty()
            !content.verificationIcon.isNullOrEmpty() || content.verificationText != null

        val hasTextBeforeAppName = hasTitle
        val hasTextBeforeTime = hasTitle || hasAppName
+19 −9
Original line number Diff line number Diff line
@@ -183,9 +183,10 @@ constructor(
    private fun Notification.smallIconModel(imageModelProvider: ImageModelProvider): ImageModel? =
        imageModelProvider.getImageModel(smallIcon, SmallSquare)

    private fun Notification.title(): CharSequence? = extras?.getCharSequence(EXTRA_TITLE)
    private fun Notification.title(): CharSequence? = getCharSequenceExtraUnlessEmpty(EXTRA_TITLE)

    private fun Notification.bigTitle(): CharSequence? = extras?.getCharSequence(EXTRA_TITLE_BIG)
    private fun Notification.bigTitle(): CharSequence? =
        getCharSequenceExtraUnlessEmpty(EXTRA_TITLE_BIG)

    private fun Notification.callPerson(): Person? =
        extras?.getParcelable(EXTRA_CALL_PERSON, Person::class.java)
@@ -200,9 +201,10 @@ constructor(
        } ?: title()
    }

    private fun Notification.text(): CharSequence? = extras?.getCharSequence(EXTRA_TEXT)
    private fun Notification.text(): CharSequence? = getCharSequenceExtraUnlessEmpty(EXTRA_TEXT)

    private fun Notification.bigText(): CharSequence? = extras?.getCharSequence(EXTRA_BIG_TEXT)
    private fun Notification.bigText(): CharSequence? =
        getCharSequenceExtraUnlessEmpty(EXTRA_BIG_TEXT)

    private fun Notification.text(style: Notification.Style?): CharSequence? {
        return when (style) {
@@ -211,17 +213,17 @@ constructor(
        } ?: text()
    }

    private fun Notification.subText(): String? = extras?.getString(EXTRA_SUB_TEXT)
    private fun Notification.subText(): String? = getStringExtraUnlessEmpty(EXTRA_SUB_TEXT)

    private fun Notification.shortCriticalText(): String? {
        if (!android.app.Flags.apiRichOngoing()) {
            return null
        }
        if (this.shortCriticalText != null) {
            return this.shortCriticalText
        if (shortCriticalText != null) {
            return shortCriticalText
        }
        if (Flags.promoteNotificationsAutomatically()) {
            return this.extras?.getString(EXTRA_AUTOMATICALLY_EXTRACTED_SHORT_CRITICAL_TEXT)
            return getStringExtraUnlessEmpty(EXTRA_AUTOMATICALLY_EXTRACTED_SHORT_CRITICAL_TEXT)
        }
        return null
    }
@@ -277,7 +279,7 @@ constructor(
        }

    private fun Notification.verificationText(): CharSequence? =
        extras.getCharSequence(EXTRA_VERIFICATION_TEXT)
        getCharSequenceExtraUnlessEmpty(EXTRA_VERIFICATION_TEXT)

    private fun Notification.Builder.extractStyleContent(
        notification: Notification,
@@ -344,3 +346,11 @@ constructor(
        contentBuilder.newProgress = createProgressModel(0xffffffff.toInt(), 0xff000000.toInt())
    }
}

private fun Notification.getCharSequenceExtraUnlessEmpty(key: String): CharSequence? =
    extras?.getCharSequence(key)?.takeUnlessEmpty()

private fun Notification.getStringExtraUnlessEmpty(key: String): String? =
    extras?.getString(key)?.takeUnlessEmpty()

private fun <T : CharSequence> T.takeUnlessEmpty(): T? = takeUnless { it.isEmpty() }