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

Commit 2f7f7b88 authored by Selim Cinek's avatar Selim Cinek
Browse files

Fixed various conversation layout appearences

Previously the layout would break if the developer
specified empty names or no avatars. Similarly if
a developer specified a conversationtitle in a
one to one chat, it would break badly as well.

Bug: 150905003
Test: create various edge case chats and observe the layout
Change-Id: If904c85e6d582b4735eb928d66749a7863fbbc06
parent 8baa70f2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -7536,6 +7536,8 @@ public class Notification implements Parcelable
                    nameReplacement);
            contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsOneToOne",
                    isOneToOne);
            contentView.setCharSequence(R.id.status_bar_latest_event_content,
                    "setConversationTitle", conversationTitle);
            contentView.setIcon(R.id.status_bar_latest_event_content, "setLargeIcon",
                    mBuilder.mN.mLargeIcon);
            contentView.setBundle(R.id.status_bar_latest_event_content, "setData",
+36 −11
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ public class ConversationLayout extends FrameLayout
    private boolean mIsCollapsed;
    private ImageResolver mImageResolver;
    private ImageView mConversationIcon;
    private TextView mHeaderText;
    private TextView mConversationText;
    private View mConversationIconBadge;
    private Icon mLargeIcon;
    private View mExpandButtonContainer;
@@ -119,6 +119,9 @@ public class ConversationLayout extends FrameLayout
    private int mExpandButtonExpandedSize;
    private View mConversationFacePile;
    private int mNotificationBackgroundColor;
    private CharSequence mFallbackChatName;
    private CharSequence mFallbackGroupChatName;
    private CharSequence mConversationTitle;

    public ConversationLayout(@NonNull Context context) {
        super(context);
@@ -161,7 +164,7 @@ public class ConversationLayout extends FrameLayout
            // Where the icon is being hidden externally like in group children.
            mConversationIconBadge.setVisibility(visibility);
        });
        mHeaderText = findViewById(R.id.header_text);
        mConversationText = findViewById(R.id.conversation_text);
        mExpandButtonContainer = findViewById(R.id.expand_button_container);
        mExpandButtonAndContentContainer = findViewById(R.id.expand_button_and_content_container);
        mExpandButton = findViewById(R.id.expand_button);
@@ -178,6 +181,10 @@ public class ConversationLayout extends FrameLayout
        mExpandedGroupTopMargin = getResources().getDimensionPixelSize(
                R.dimen.conversation_icon_margin_top_centered);
        mConversationFacePile = findViewById(R.id.conversation_face_pile);
        mFallbackChatName = getResources().getString(
                R.string.conversation_title_fallback_one_to_one);
        mFallbackGroupChatName = getResources().getString(
                R.string.conversation_title_fallback_group_chat);
    }

    @RemotableViewMethod
@@ -295,11 +302,11 @@ public class ConversationLayout extends FrameLayout
    private void updateConversationLayout() {
        // TODO: resolve this from shortcuts
        // Set avatar and name
        CharSequence personOnTop = null;
        CharSequence conversationText = mConversationTitle;
        // TODO: display the secondary text somewhere
        if (mIsOneToOne) {
            // Let's resolve the icon / text from the last sender
            mConversationIcon.setVisibility(VISIBLE);
            mHeaderText.setVisibility(VISIBLE);
            mConversationFacePile.setVisibility(GONE);
            CharSequence userKey = getKey(mUser);
            for (int i = mGroups.size() - 1; i >= 0; i--) {
@@ -307,16 +314,20 @@ public class ConversationLayout extends FrameLayout
                Person messageSender = messagingGroup.getSender();
                if ((messageSender != null && !TextUtils.equals(userKey, getKey(messageSender)))
                        || i == 0) {
                    // Make sure the header is actually visible
                    // TODO: figure out what to do if there's a converationtitle + a Sender
                    mHeaderText.setText(messagingGroup.getSenderName());
                    mConversationIcon.setImageIcon(messagingGroup.getAvatarIcon());
                    personOnTop = messagingGroup.getSenderName();
                    if (TextUtils.isEmpty(conversationText)) {
                        // We use the sendername as header text if no conversation title is provided
                        // (This usually happens for most 1:1 conversations)
                        conversationText = messagingGroup.getSenderName();
                    }
                    Icon avatarIcon = messagingGroup.getAvatarIcon();
                    if (avatarIcon == null) {
                        avatarIcon = createAvatarSymbol(conversationText, "", mLayoutColor);
                    }
                    mConversationIcon.setImageIcon(avatarIcon);
                    break;
                }
            }
        } else {
            mHeaderText.setVisibility(GONE);
            if (mIsCollapsed) {
                if (mLargeIcon != null) {
                    mConversationIcon.setVisibility(VISIBLE);
@@ -334,13 +345,17 @@ public class ConversationLayout extends FrameLayout
                mConversationIcon.setVisibility(GONE);
            }
        }
        if (TextUtils.isEmpty(conversationText)) {
            conversationText = mIsOneToOne ? mFallbackChatName : mFallbackGroupChatName;
        }
        mConversationText.setText(conversationText);
        // Update if the groups can hide the sender if they are first (applies to 1:1 conversations)
        // This needs to happen after all of the above o update all of the groups
        for (int i = mGroups.size() - 1; i >= 0; i--) {
            MessagingGroup messagingGroup = mGroups.get(i);
            CharSequence messageSender = messagingGroup.getSenderName();
            boolean canHide = mIsOneToOne
                    && TextUtils.equals(personOnTop, messageSender);
                    && TextUtils.equals(conversationText, messageSender);
            messagingGroup.setCanHideSenderIfFirst(canHide);
        }
        updateIconPositionAndSize();
@@ -425,6 +440,16 @@ public class ConversationLayout extends FrameLayout
        mLargeIcon = largeIcon;
    }

    /**
     * Sets the conversation title of this conversation.
     *
     * @param conversationTitle the conversation title
     */
    @RemotableViewMethod
    public void setConversationTitle(CharSequence conversationTitle) {
        mConversationTitle = conversationTitle;
    }

    private void removeGroups(ArrayList<MessagingGroup> oldGroups) {
        int size = oldGroups.size();
        for (int i = 0; i < size; i++) {
+10 −0
Original line number Diff line number Diff line
@@ -159,6 +159,16 @@ public class MessagingLayout extends FrameLayout
        // Unused
    }

    /**
     * Sets the conversation title of this conversation.
     *
     * @param conversationTitle the conversation title
     */
    @RemotableViewMethod
    public void setConversationTitle(CharSequence conversationTitle) {
        // Unused
    }

    @RemotableViewMethod
    public void setData(Bundle extras) {
        Parcelable[] messages = extras.getParcelableArray(Notification.EXTRA_MESSAGES);
+1 −22
Original line number Diff line number Diff line
@@ -109,7 +109,7 @@
                    android:paddingStart="@dimen/conversation_content_start"
                >
                    <TextView
                        android:id="@+id/header_text"
                        android:id="@+id/conversation_text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginEnd="@dimen/notification_header_separating_margin"
@@ -117,27 +117,6 @@
                        android:textSize="16sp"
                        android:singleLine="true"
                        />
                    <TextView
                        android:id="@+id/header_text_divider"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?attr/notificationHeaderTextAppearance"
                        android:layout_marginStart="@dimen/notification_header_separating_margin"
                        android:layout_marginEnd="4dp"
                        android:text="@string/notification_header_divider_symbol"
                        android:paddingTop="1sp"
                        android:layout_gravity="center"
                        android:visibility="gone"/>

                    <TextView
                        android:id="@+id/header_text_secondary"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="@style/TextAppearance.DeviceDefault.Notification.Title"
                        android:layout_marginEnd="@dimen/notification_header_separating_margin"
                        android:textSize="16sp"
                        android:visibility="gone"
                        android:singleLine="true"/>

                    <TextView
                        android:id="@+id/time_divider"
+6 −0
Original line number Diff line number Diff line
@@ -5435,6 +5435,12 @@
    <!-- The way a conversation name is displayed when single line. The text will be displayed to the end of this text with some spacing -->
    <string name="conversation_single_line_name_display"><xliff:g id="sender_name" example="Sara">%1$s</xliff:g>:</string>

    <!-- Conversation Title fallback if the there is no name provided in a 1:1 conversation [CHAR LIMIT=40]-->
    <string name="conversation_title_fallback_one_to_one">Conversation</string>

    <!-- Conversation Title fallback if the there is no name provided in a group chat conversation [CHAR LIMIT=40]-->
    <string name="conversation_title_fallback_group_chat">Group Conversation</string>

    <!-- ResolverActivity - profile tabs -->
    <!-- Label of a tab on a screen. A user can tap this tap to switch to the 'Personal' view (that shows their personal content) if they have a work profile on their device. [CHAR LIMIT=NONE] -->
    <string name="resolver_personal_tab">Personal</string>
Loading