Fix alignment issues for single line timestamps.

This commit is contained in:
Lucio Maciel
2021-08-16 18:56:06 -03:00
committed by Greyson Parrelli
parent 31e0f3edfb
commit 0599f76ed5
7 changed files with 43 additions and 30 deletions

View File

@@ -24,6 +24,7 @@ import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.Typeface;
@@ -387,40 +388,46 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
}
}
int defaultMargin = readDimen(R.dimen.message_bubble_default_footer_bottom_margin);
if (!updatingFooter &&
!isCaptionlessMms(messageRecord) &&
!isViewOnceMessage(messageRecord) &&
isFooterVisible(messageRecord, nextMessageRecord, groupThread) &&
bodyText.getLastLineWidth() > 0)
{
int footerWidth = footer.getMeasuredWidth();
int availableWidth = getAvailableMessageBubbleWidth(bodyText);
TextView dateView = footer.getDateView();
int footerWidth = footer.getMeasuredWidth();
int availableWidth = getAvailableMessageBubbleWidth(bodyText);
int bottomDiff = (int) (bodyText.getPaint().getFontMetrics().bottom - dateView.getPaint().getFontMetrics().bottom);
int topMargin = -1 * (dateView.getMeasuredHeight() + ViewUtil.dpToPx(7) + bottomDiff) + 1;
if (bodyText.isSingleLine()) {
int maxBubbleWidth = hasBigImageLinkPreview(messageRecord) || hasThumbnail(messageRecord) ? readDimen(R.dimen.media_bubble_max_width) : getMaxBubbleWidth();
int bodyMargins = ViewUtil.getLeftMargin(bodyText) + ViewUtil.getRightMargin(bodyText);
int sizeWithMargins = bodyText.getMeasuredWidth() + ViewUtil.dpToPx(6) + footerWidth + bodyMargins;
int minSize = Math.min(maxBubbleWidth, Math.max(bodyText.getMeasuredWidth() + ViewUtil.dpToPx(6) + footerWidth + bodyMargins, bodyBubble.getMeasuredWidth()));
if (hasQuote(messageRecord) && sizeWithMargins < availableWidth) {
ViewUtil.setTopMargin(footer, readDimen(R.dimen.message_bubble_same_line_footer_bottom_margin));
ViewUtil.setTopMargin(footer, topMargin);
needsMeasure = true;
updatingFooter = true;
} else if (sizeWithMargins != bodyText.getMeasuredWidth() && sizeWithMargins <= minSize) {
bodyBubble.getLayoutParams().width = minSize;
ViewUtil.setTopMargin(footer, readDimen(R.dimen.message_bubble_same_line_footer_bottom_margin));
ViewUtil.setTopMargin(footer, topMargin);
needsMeasure = true;
updatingFooter = true;
}
}
if (!updatingFooter && bodyText.getLastLineWidth() + ViewUtil.dpToPx(6) + footerWidth <= bodyText.getMeasuredWidth()) {
ViewUtil.setTopMargin(footer, readDimen(R.dimen.message_bubble_same_line_footer_bottom_margin));
ViewUtil.setTopMargin(footer, topMargin);
updatingFooter = true;
needsMeasure = true;
} else if (!updatingFooter && ViewUtil.getTopMargin(footer) == readDimen(R.dimen.message_bubble_same_line_footer_bottom_margin)) {
ViewUtil.setTopMargin(footer, readDimen(R.dimen.message_bubble_default_footer_bottom_margin));
needsMeasure = true;
}
}
if (!updatingFooter && ViewUtil.getTopMargin(footer) != defaultMargin) {
ViewUtil.setTopMargin(footer, defaultMargin);
needsMeasure = true;
}
if (hasSharedContact(messageRecord)) {
int contactWidth = sharedContactStub.get().getMeasuredWidth();
int availableWidth = getAvailableMessageBubbleWidth(sharedContactStub.get());