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

Commit 859512e3 authored by Ioana Alexandru's avatar Ioana Alexandru Committed by Android (Google) Code Review
Browse files

Merge changes I4d0df56c,I783cd952 into main

* changes:
  Don't show "Redacted" text for public notifs
  Show placeholder when single line view is empty
parents 9f25ea09 2b45d38b
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import com.android.systemui.statusbar.notification.row.ui.viewmodel.SingleLineVi
import kotlin.test.assertEquals
import kotlin.test.assertIs
import kotlin.test.assertIsNot
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue
import org.junit.Before
@@ -100,6 +101,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
@@ -295,10 +312,33 @@ class SingleLineViewInflaterTest : SysuiTestCase() {
        assertEquals("summary", singleLineViewModel.conversationData?.summarization)
    }

    @Test
    fun createViewModelForPublicConversationNotification() {
        // When: a public conversation notification is inflated
        val singleLineViewModel =
            SingleLineViewInflater.inflatePublicSingleLineViewModel(context, isConversation = true)

        // Then: the view model should be populated with the correct data
        val expectedIcon = context.getDrawable(R.drawable.ic_public_notification_single_line_icon)
        assertTrue(
            (singleLineViewModel.conversationData?.avatar as? SingleIcon)
                ?.iconDrawable
                ?.equalsTo(expectedIcon) == true
        )

        val expectedTitle = context.getString(R.string.public_notification_single_line_title)
        assertEquals(expectedTitle, singleLineViewModel.titleText)

        assertNull(singleLineViewModel.contentText)
        assertNotNull(singleLineViewModel.conversationData)
    }

    sealed class NotificationType(val largeIcon: Icon? = null)

    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 +368,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)
+4 −4
Original line number Diff line number Diff line
@@ -4334,12 +4334,12 @@
    <!-- Education toast text for All Apps [CHAR_LIMIT=100] -->
    <string name="all_apps_edu_toast_content">To view all your apps, press the action key on your keyboard</string>

    <!-- Title of the one line view of a redacted notification -->
    <string name="redacted_notification_single_line_title">Redacted</string>
    <!-- Main text of the one line view of a public notification -->
    <string name="public_notification_single_line_text">Unlock to view</string>
    <!-- Placeholder title for the one line view of a public notification -->
    <string name="public_notification_single_line_title">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>
+17 −5
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
@@ -71,6 +72,7 @@ object SingleLineViewInflater {
            return SingleLineViewModel(null, null, null)
        }
        peopleHelper.init(systemUiContext)

        var titleText = HybridGroupManager.resolveTitle(notification)
        var contentText =
            if (redactText) {
@@ -82,6 +84,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,
@@ -135,7 +149,7 @@ object SingleLineViewInflater {
                    SingleIcon(
                        context.getDrawable(
                            com.android.systemui.res.R.drawable
                                .ic_redacted_notification_single_line_icon
                                .ic_public_notification_single_line_icon
                        )
                    ),
                    null,
@@ -145,11 +159,9 @@ object SingleLineViewInflater {
            }
        return SingleLineViewModel(
            context.getString(
                com.android.systemui.res.R.string.redacted_notification_single_line_title
            ),
            context.getString(
                com.android.systemui.res.R.string.public_notification_single_line_text
                com.android.systemui.res.R.string.public_notification_single_line_title
            ),
            null,
            conversationData,
        )
    }