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

Commit dccbf21b authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

Show placeholder when single line view is empty

Fix: 429118181
Flag: EXEMPT trivial bugfix
Test: SingleLineViewInflaterTest
Test: manual using a timer & stopwatch notification from the Clock app
Change-Id: I783cd9520f04f5e5c7572b2f2f8f61d8d892ead6
parent 91cfff6e
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -100,6 +100,22 @@ class SingleLineViewInflaterTest : SysuiTestCase() {
        assertEquals(SingleLineViewModel(CONTENT_TITLE, CONTENT_TEXT, null), singleLineViewModel)
    }

    @Test
    fun createViewModelForEmptyNotification() {
        // Given: a non-conversation notification with no title and no text
        val notificationType = Empty()
        val notification = getNotification(notificationType)

        // When: inflate the SingleLineViewModel
        val singleLineViewModel = notification.makeSingleLineViewModel(notificationType)

        // Then: the view model should show the placeholder title
        val expectedTitle = context.getString(R.string.empty_notification_single_line_title)
        assertEquals(expectedTitle, singleLineViewModel.titleText)
        assertNull(singleLineViewModel.contentText)
        assertNull(singleLineViewModel.conversationData)
    }

    @Test
    fun createViewModelForNonGroupConversationNotification() {
        // Given: a non-group conversation notification
@@ -299,6 +315,8 @@ class SingleLineViewInflaterTest : SysuiTestCase() {

    class NonMessaging(largeIcon: Icon? = null) : NotificationType(largeIcon)

    class Empty(largeIcon: Icon? = null) : NotificationType(largeIcon)

    class LegacyMessaging(largeIcon: Icon? = null) : NotificationType(largeIcon)

    class LegacyMessagingGroup(largeIcon: Icon? = null) : NotificationType(largeIcon)
@@ -328,6 +346,7 @@ class SingleLineViewInflaterTest : SysuiTestCase() {
                notificationBuilder
                    .setStyle(Notification.BigTextStyle().bigText("Big Text"))
                    .build()
            is Empty -> notificationBuilder.setContentTitle(null).setContentText(null).build()
            is LegacyMessaging -> {
                buildMessagingStyle
                    .addMessage("What's up?", 0, firstSender)
+2 −0
Original line number Diff line number Diff line
@@ -4336,6 +4336,8 @@
    <string name="public_notification_single_line_text">Unlock to view</string>
    <!-- Main text of the one line view of a redacted OTP notification -->
    <string name="redacted_otp_notification_single_line_text">Unlock to view code</string>
    <!-- Placeholder title for the one line view of a notification with no title or text set -->
    <string name="empty_notification_single_line_title">Expand to view</string>

    <!-- Content description for contextual education dialog [CHAR LIMIT=NONE] -->
    <string name="contextual_education_dialog_title">Contextual education</string>
+13 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.app.Notification.MessagingStyle
import android.app.Person
import android.content.Context
import android.graphics.drawable.Icon
import android.text.TextUtils
import android.util.Log
import android.view.LayoutInflater
import androidx.annotation.VisibleForTesting
@@ -82,6 +83,18 @@ object SingleLineViewInflater {
            }

        if (messagingStyle == null) {
            // If we have no title AND no text (e.g. for some custom view notifications), show a
            // placeholder string
            if (TextUtils.isEmpty(titleText) && TextUtils.isEmpty(contentText)) {
                return SingleLineViewModel(
                    titleText =
                        systemUiContext.getString(
                            com.android.systemui.res.R.string.empty_notification_single_line_title
                        ),
                    contentText = null,
                    conversationData = null,
                )
            }
            return SingleLineViewModel(
                titleText = titleText,
                contentText = contentText,