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

Commit bf0507b0 authored by Flavio Fiszman's avatar Flavio Fiszman Committed by Android (Google) Code Review
Browse files

Merge "Handling group chat sender" into sc-dev

parents a095d6b2 47b06875
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ public class PeopleSpaceTile implements Parcelable {
    private boolean mIsImportantConversation;
    private String mNotificationKey;
    private CharSequence mNotificationContent;
    private CharSequence mNotificationSender;
    private String mNotificationCategory;
    private Uri mNotificationDataUri;
    private int mMessagesCount;
@@ -73,6 +74,7 @@ public class PeopleSpaceTile implements Parcelable {
        mIsImportantConversation = b.mIsImportantConversation;
        mNotificationKey = b.mNotificationKey;
        mNotificationContent = b.mNotificationContent;
        mNotificationSender = b.mNotificationSender;
        mNotificationCategory = b.mNotificationCategory;
        mNotificationDataUri = b.mNotificationDataUri;
        mMessagesCount = b.mMessagesCount;
@@ -134,6 +136,10 @@ public class PeopleSpaceTile implements Parcelable {
        return mNotificationContent;
    }

    public CharSequence getNotificationSender() {
        return mNotificationSender;
    }

    public String getNotificationCategory() {
        return mNotificationCategory;
    }
@@ -179,6 +185,7 @@ public class PeopleSpaceTile implements Parcelable {
        builder.setIsImportantConversation(mIsImportantConversation);
        builder.setNotificationKey(mNotificationKey);
        builder.setNotificationContent(mNotificationContent);
        builder.setNotificationSender(mNotificationSender);
        builder.setNotificationCategory(mNotificationCategory);
        builder.setNotificationDataUri(mNotificationDataUri);
        builder.setMessagesCount(mMessagesCount);
@@ -201,6 +208,7 @@ public class PeopleSpaceTile implements Parcelable {
        private boolean mIsImportantConversation;
        private String mNotificationKey;
        private CharSequence mNotificationContent;
        private CharSequence mNotificationSender;
        private String mNotificationCategory;
        private Uri mNotificationDataUri;
        private int mMessagesCount;
@@ -316,6 +324,12 @@ public class PeopleSpaceTile implements Parcelable {
            return this;
        }

        /** Sets the associated notification's sender. */
        public Builder setNotificationSender(CharSequence notificationSender) {
            mNotificationSender = notificationSender;
            return this;
        }

        /** Sets the associated notification's category. */
        public Builder setNotificationCategory(String notificationCategory) {
            mNotificationCategory = notificationCategory;
@@ -371,6 +385,7 @@ public class PeopleSpaceTile implements Parcelable {
        mIsImportantConversation = in.readBoolean();
        mNotificationKey = in.readString();
        mNotificationContent = in.readCharSequence();
        mNotificationSender = in.readCharSequence();
        mNotificationCategory = in.readString();
        mNotificationDataUri = in.readParcelable(Uri.class.getClassLoader());
        mMessagesCount = in.readInt();
@@ -398,6 +413,7 @@ public class PeopleSpaceTile implements Parcelable {
        dest.writeBoolean(mIsImportantConversation);
        dest.writeString(mNotificationKey);
        dest.writeCharSequence(mNotificationContent);
        dest.writeCharSequence(mNotificationSender);
        dest.writeString(mNotificationCategory);
        dest.writeParcelable(mNotificationDataUri, flags);
        dest.writeInt(mMessagesCount);
+12 −0
Original line number Diff line number Diff line
@@ -234,6 +234,7 @@ public class PeopleSpaceTileTest {
                .setIsImportantConversation(true)
                .setStatuses(statusList).setNotificationKey("key")
                .setNotificationContent("content")
                .setNotificationSender("sender")
                .setNotificationDataUri(Uri.parse("data"))
                .setMessagesCount(2)
                .setIntent(new Intent())
@@ -256,6 +257,7 @@ public class PeopleSpaceTileTest {
        assertThat(readTile.getStatuses()).isEqualTo(tile.getStatuses());
        assertThat(readTile.getNotificationKey()).isEqualTo(tile.getNotificationKey());
        assertThat(readTile.getNotificationContent()).isEqualTo(tile.getNotificationContent());
        assertThat(readTile.getNotificationSender()).isEqualTo(tile.getNotificationSender());
        assertThat(readTile.getNotificationDataUri()).isEqualTo(tile.getNotificationDataUri());
        assertThat(readTile.getMessagesCount()).isEqualTo(tile.getMessagesCount());
        assertThat(readTile.getIntent().toString()).isEqualTo(tile.getIntent().toString());
@@ -281,6 +283,16 @@ public class PeopleSpaceTileTest {
        assertThat(tile.getNotificationContent()).isEqualTo("test");
    }

    @Test
    public void testNotificationSender() {
        PeopleSpaceTile tile = new PeopleSpaceTile
                .Builder(new ShortcutInfo.Builder(mContext, "123").build(), mLauncherApps)
                .setNotificationSender("test")
                .build();

        assertThat(tile.getNotificationSender()).isEqualTo("test");
    }

    @Test
    public void testNotificationDataUri() {
        PeopleSpaceTile tile =
+26 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ import java.util.Set;
/** Helper functions to handle notifications in People Tiles. */
public class NotificationHelper {
    private static final boolean DEBUG = PeopleSpaceUtils.DEBUG;
    private static final String TAG = "PeopleNotificationHelper";
    private static final String TAG = "PeopleNotifHelper";

    /** Returns the notification with highest priority to be shown in People Tiles. */
    public static NotificationEntry getHighestPriorityNotification(
@@ -209,5 +209,30 @@ public class NotificationHelper {
        }
        return null;
    }

    /** Returns whether {@code notification} is a group conversation. */
    private static boolean isGroupConversation(Notification notification) {
        return notification.extras.getBoolean(Notification.EXTRA_IS_GROUP_CONVERSATION, false);
    }

    /**
     * Returns {@code message}'s sender's name if {@code notification} is from a group conversation.
     */
    public static CharSequence getSenderIfGroupConversation(Notification notification,
            Notification.MessagingStyle.Message message) {
        if (!isGroupConversation(notification)) {
            if (DEBUG) {
                Log.d(TAG, "Notification is not from a group conversation, not checking sender.");
            }
            return null;
        }
        Person person = message.getSenderPerson();
        if (person == null) {
            if (DEBUG) Log.d(TAG, "Notification from group conversation doesn't include sender.");
            return null;
        }
        if (DEBUG) Log.d(TAG, "Returning sender from group conversation notification.");
        return person.getName();
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.people;

import static com.android.systemui.people.NotificationHelper.getContactUri;
import static com.android.systemui.people.NotificationHelper.getMessagingStyleMessages;
import static com.android.systemui.people.NotificationHelper.getSenderIfGroupConversation;
import static com.android.systemui.people.NotificationHelper.hasReadContactsPermission;
import static com.android.systemui.people.NotificationHelper.isMissedCall;
import static com.android.systemui.people.NotificationHelper.shouldMatchNotificationByUri;
@@ -233,6 +234,7 @@ public class PeopleSpaceUtils {
                // Reset notification content.
                .setNotificationKey(null)
                .setNotificationContent(null)
                .setNotificationSender(null)
                .setNotificationDataUri(null)
                .setMessagesCount(0)
                // Reset missed calls category.
@@ -272,12 +274,14 @@ public class PeopleSpaceUtils {
            Log.d(TAG, "Tile key: " + key.toString() + ". Notification message has text: "
                    + hasMessageText);
        }
        CharSequence sender = getSenderIfGroupConversation(notification, message);

        return tile
                .toBuilder()
                .setNotificationKey(notificationEntry.getSbn().getKey())
                .setNotificationCategory(notification.category)
                .setNotificationContent(content)
                .setNotificationSender(sender)
                .setNotificationDataUri(dataUri)
                .setMessagesCount(messagesCount)
                .build();
+14 −7
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ public class PeopleTileViewHelper {
        return createLastInteractionRemoteViews();
    }

    private void setMaxLines(RemoteViews views) {
    private void setMaxLines(RemoteViews views, boolean showSender) {
        int textSize = mLayoutSize == LAYOUT_LARGE ? getSizeInDp(
                R.dimen.content_text_size_for_medium)
                : getSizeInDp(R.dimen.content_text_size_for_medium);
@@ -190,6 +190,9 @@ public class PeopleTileViewHelper {
        int notificationContentHeight = getContentHeightForLayout(lineHeight);
        int maxAdaptiveLines = Math.floorDiv(notificationContentHeight, lineHeight);
        int maxLines = Math.max(MIN_CONTENT_MAX_LINES, maxAdaptiveLines);

        // Save a line for sender's name, if present.
        if (showSender) maxLines--;
        views.setInt(R.id.text_content, "setMaxLines", maxLines);
    }

@@ -353,7 +356,7 @@ public class PeopleTileViewHelper {
        RemoteViews views = getViewForContentLayout();
        views.setViewVisibility(R.id.predefined_icon, View.VISIBLE);
        views.setViewVisibility(R.id.messages_count, View.GONE);
        setMaxLines(views);
        setMaxLines(views, false);
        views.setTextViewText(R.id.text_content, mTile.getNotificationContent());
        views.setImageViewResource(R.id.predefined_icon, R.drawable.ic_phone_missed);
        return views;
@@ -361,6 +364,7 @@ public class PeopleTileViewHelper {

    private RemoteViews createNotificationRemoteViews() {
        RemoteViews views = getViewForContentLayout();
        CharSequence sender = mTile.getNotificationSender();
        Uri image = mTile.getNotificationDataUri();
        if (image != null) {
            // TODO: Use NotificationInlineImageCache
@@ -369,7 +373,7 @@ public class PeopleTileViewHelper {
            views.setViewVisibility(R.id.text_content, View.GONE);
            views.setImageViewResource(R.id.predefined_icon, R.drawable.ic_photo_camera);
        } else {
            setMaxLines(views);
            setMaxLines(views, !TextUtils.isEmpty(sender));
            CharSequence content = mTile.getNotificationContent();
            views = setPunctuationRemoteViewsFields(views, content);
            views.setColorAttr(R.id.text_content, "setTextColor", android.R.attr.textColorPrimary);
@@ -385,9 +389,12 @@ public class PeopleTileViewHelper {
                views.setViewVisibility(R.id.predefined_icon, View.GONE);
            }
        }
        // TODO: Set subtext as Group Sender name once storing the name in PeopleSpaceTile and
        //  subtract 1 from maxLines when present.
        if (!TextUtils.isEmpty(sender)) {
            views.setViewVisibility(R.id.subtext, View.VISIBLE);
            views.setTextViewText(R.id.subtext, sender);
        } else {
            views.setViewVisibility(R.id.subtext, View.GONE);
        }
        return views;
    }

@@ -417,7 +424,7 @@ public class PeopleTileViewHelper {
        }
        views.setViewVisibility(R.id.predefined_icon, View.VISIBLE);
        views.setViewVisibility(R.id.messages_count, View.GONE);
        setMaxLines(views);
        setMaxLines(views, false);
        // Secondary text color for statuses.
        views.setColorAttr(R.id.text_content, "setTextColor", android.R.attr.textColorSecondary);
        views.setTextViewText(R.id.text_content, statusText);
Loading