DO NOT MERGE Set message notification's title to the conversation title am: 9bde8401de
Change-Id: I32820a4099de3e5486610cdfedaf3a74990cb188
diff --git a/src/com/android/car/notification/template/MessageNotificationViewHolder.java b/src/com/android/car/notification/template/MessageNotificationViewHolder.java
index fcd1052..bd6a94f 100644
--- a/src/com/android/car/notification/template/MessageNotificationViewHolder.java
+++ b/src/com/android/car/notification/template/MessageNotificationViewHolder.java
@@ -29,6 +29,8 @@
import android.widget.ImageButton;
import android.widget.TextView;
+import androidx.core.app.NotificationCompat.MessagingStyle;
+
import com.android.car.notification.NotificationClickHandlerFactory;
import com.android.car.notification.PreprocessingManager;
import com.android.car.notification.R;
@@ -45,7 +47,7 @@
private final CarNotificationBodyView mBodyView;
private final CarNotificationHeaderView mHeaderView;
private final CarNotificationActionsView mActionsView;
- private final TextView mSenderNameView;
+ private final TextView mTitleView;
private final DateTimeView mTimeView;
private final TextView mMessageView;
private final TextView mUnshownCountView;
@@ -59,7 +61,7 @@
mDefaultPrimaryForegroundColor = mContext.getColor(R.color.primary_text_color);
mHeaderView = view.findViewById(R.id.notification_header);
mActionsView = view.findViewById(R.id.notification_actions);
- mSenderNameView = view.findViewById(R.id.notification_body_title);
+ mTitleView = view.findViewById(R.id.notification_body_title);
mTimeView = view.findViewById(R.id.in_group_time_stamp);
if (mTimeView != null) {
// HUN template does not include the time stamp.
@@ -106,10 +108,14 @@
Notification notification = statusBarNotification.getNotification();
CharSequence messageText = null;
- CharSequence senderName = null;
+ CharSequence conversationTitle = null;
Icon avatar = null;
Integer messageCount = null;
+ final MessagingStyle messagingStyle =
+ MessagingStyle.extractMessagingStyleFromNotification(notification);
+ if (messagingStyle != null) conversationTitle = messagingStyle.getConversationTitle();
+
Bundle extras = notification.extras;
Parcelable[] messagesData = extras.getParcelableArray(Notification.EXTRA_MESSAGES);
if (messagesData != null) {
@@ -122,10 +128,10 @@
messageText = message.getText();
Person sender = message.getSenderPerson();
if (sender != null) {
- senderName = sender.getName();
avatar = sender.getIcon();
- } else {
- senderName = message.getSender();
+ }
+ if (conversationTitle == null) {
+ conversationTitle = sender != null ? sender.getName() : message.getSender();
}
}
}
@@ -138,8 +144,8 @@
}
}
- if (TextUtils.isEmpty(senderName)) {
- senderName = extras.getCharSequence(Notification.EXTRA_TITLE);
+ if (TextUtils.isEmpty(conversationTitle)) {
+ conversationTitle = extras.getCharSequence(Notification.EXTRA_TITLE);
}
if (isRestricted) {
messageText = mContext.getResources().getQuantityString(
@@ -152,9 +158,9 @@
avatar = notification.getLargeIcon();
}
- if (!TextUtils.isEmpty(senderName)) {
- mSenderNameView.setVisibility(View.VISIBLE);
- mSenderNameView.setText(senderName);
+ if (!TextUtils.isEmpty(conversationTitle)) {
+ mTitleView.setVisibility(View.VISIBLE);
+ mTitleView.setText(conversationTitle);
}
if (isInGroup && notification.showsTime()) {
@@ -183,15 +189,15 @@
}
if (isHeadsUp) {
- mBodyView.bindTitleAndMessage(senderName, messageText);
+ mBodyView.bindTitleAndMessage(conversationTitle, messageText);
}
}
@Override
void reset() {
super.reset();
- mSenderNameView.setVisibility(View.GONE);
- mSenderNameView.setText(null);
+ mTitleView.setVisibility(View.GONE);
+ mTitleView.setText(null);
if (mTimeView != null) {
mTimeView.setVisibility(View.GONE);
}