Fix message bubble sizing with link previews and quotes.

Previously, quotes could extend beyond the width of the link preview
banner image. Now quotes will be constrained to the size of the link
preview banner image.
This commit is contained in:
Greyson Parrelli 2019-05-28 11:13:40 -04:00
parent 2a644437fb
commit 77e3cc40e0

View File

@ -307,7 +307,7 @@ public class ConversationItem extends LinearLayout
int availableWidth;
if (hasAudio(messageRecord)) {
availableWidth = audioViewStub.get().getMeasuredWidth() + ViewUtil.getLeftMargin(audioViewStub.get()) + ViewUtil.getRightMargin(audioViewStub.get());
} else if (hasThumbnail(messageRecord)) {
} else if (hasThumbnail(messageRecord) || hasBigImageLinkPreview(messageRecord)) {
availableWidth = mediaThumbnailStub.get().getMeasuredWidth();
} else {
availableWidth = bodyBubble.getMeasuredWidth() - bodyBubble.getPaddingLeft() - bodyBubble.getPaddingRight();
@ -440,6 +440,17 @@ public class ConversationItem extends LinearLayout
return messageRecord.isMms() && !((MmsMessageRecord)messageRecord).getLinkPreviews().isEmpty();
}
private boolean hasBigImageLinkPreview(MessageRecord messageRecord) {
if (!hasLinkPreview(messageRecord)) return false;
LinkPreview linkPreview = ((MmsMessageRecord) messageRecord).getLinkPreviews().get(0);
int minWidth = getResources().getDimensionPixelSize(R.dimen.media_bubble_min_width);
return linkPreview.getThumbnail().isPresent() &&
linkPreview.getThumbnail().get().getWidth() >= minWidth &&
!StickerUrl.isValidShareLink(linkPreview.getUrl());
}
private void setBodyText(MessageRecord messageRecord, @Nullable String searchQuery) {
bodyText.setClickable(false);
bodyText.setFocusable(false);
@ -500,7 +511,7 @@ public class ConversationItem extends LinearLayout
//noinspection ConstantConditions
LinkPreview linkPreview = ((MmsMessageRecord) messageRecord).getLinkPreviews().get(0);
if (linkPreview.getThumbnail().isPresent() && shouldPromotePreviewImage(linkPreview.getThumbnail().get(), linkPreview.getUrl())) {
if (hasBigImageLinkPreview(messageRecord)) {
mediaThumbnailStub.get().setVisibility(VISIBLE);
mediaThumbnailStub.get().setImageResource(glideRequests, Collections.singletonList(new ImageSlide(context, linkPreview.getThumbnail().get())), showControls, false);
mediaThumbnailStub.get().setThumbnailClickListener(new LinkPreviewThumbnailClickListener());
@ -722,11 +733,6 @@ public class ConversationItem extends LinearLayout
contactPhoto.setAvatar(glideRequests, recipient, true);
}
private boolean shouldPromotePreviewImage(@NonNull Attachment attachment, @NonNull String url) {
int minWidth = getResources().getDimensionPixelSize(R.dimen.media_bubble_min_width);
return attachment.getWidth() >= minWidth && !StickerUrl.isValidShareLink(url);
}
private SpannableString linkifyMessageBody(SpannableString messageBody, boolean shouldLinkifyAllLinks) {
int linkPattern = Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS;
boolean hasLinks = Linkify.addLinks(messageBody, shouldLinkifyAllLinks ? linkPattern : 0);