Loading packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/row/SingleLineViewInflaterTest.kt +41 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -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) Loading Loading @@ -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) Loading packages/SystemUI/res/drawable/ic_redacted_notification_single_line_icon.xml→packages/SystemUI/res/drawable/ic_public_notification_single_line_icon.xml +0 −0 File moved. View file packages/SystemUI/res/values/strings.xml +4 −4 Original line number Diff line number Diff line Loading @@ -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> Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/row/SingleLineViewInflater.kt +17 −5 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -71,6 +72,7 @@ object SingleLineViewInflater { return SingleLineViewModel(null, null, null) } peopleHelper.init(systemUiContext) var titleText = HybridGroupManager.resolveTitle(notification) var contentText = if (redactText) { Loading @@ -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, Loading Loading @@ -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, Loading @@ -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, ) } Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/row/SingleLineViewInflaterTest.kt +41 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -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) Loading Loading @@ -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) Loading
packages/SystemUI/res/drawable/ic_redacted_notification_single_line_icon.xml→packages/SystemUI/res/drawable/ic_public_notification_single_line_icon.xml +0 −0 File moved. View file
packages/SystemUI/res/values/strings.xml +4 −4 Original line number Diff line number Diff line Loading @@ -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> Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/row/SingleLineViewInflater.kt +17 −5 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -71,6 +72,7 @@ object SingleLineViewInflater { return SingleLineViewModel(null, null, null) } peopleHelper.init(systemUiContext) var titleText = HybridGroupManager.resolveTitle(notification) var contentText = if (redactText) { Loading @@ -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, Loading Loading @@ -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, Loading @@ -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, ) } Loading