Prevent several re-layout calls in ConversationItem.
This commit is contained in:
parent
d21254ac02
commit
24cd11152b
3 changed files with 51 additions and 19 deletions
|
@ -27,6 +27,7 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class TransferControlView extends FrameLayout {
|
||||
|
||||
|
@ -126,7 +127,11 @@ public final class TransferControlView extends FrameLayout {
|
|||
break;
|
||||
case AttachmentTable.TRANSFER_PROGRESS_PENDING:
|
||||
case AttachmentTable.TRANSFER_PROGRESS_FAILED:
|
||||
downloadDetailsText.setText(getDownloadText(this.slides));
|
||||
String downloadText = getDownloadText(this.slides);
|
||||
if (!Objects.equals(downloadText, downloadDetailsText.getText().toString())) {
|
||||
downloadDetailsText.setText(getDownloadText(this.slides));
|
||||
}
|
||||
|
||||
display(downloadDetails);
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -556,22 +556,22 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
|
|||
int minSize = Math.min(maxBubbleWidth, Math.max(bodyText.getMeasuredWidth() + ViewUtil.dpToPx(6) + footerWidth + bodyMargins, bodyBubble.getMeasuredWidth()));
|
||||
|
||||
if (hasQuote(messageRecord) && sizeWithMargins < availableWidth) {
|
||||
ViewUtil.setTopMargin(footer, collapsedTopMargin);
|
||||
ViewUtil.setBottomMargin(footer, collapsedBottomMargin);
|
||||
ViewUtil.setTopMargin(footer, collapsedTopMargin, false);
|
||||
ViewUtil.setBottomMargin(footer, collapsedBottomMargin, false);
|
||||
needsMeasure = true;
|
||||
updatingFooter = true;
|
||||
} else if (sizeWithMargins != bodyText.getMeasuredWidth() && sizeWithMargins <= minSize) {
|
||||
bodyBubble.getLayoutParams().width = minSize;
|
||||
ViewUtil.setTopMargin(footer, collapsedTopMargin);
|
||||
ViewUtil.setBottomMargin(footer, collapsedBottomMargin);
|
||||
ViewUtil.setTopMargin(footer, collapsedTopMargin, false);
|
||||
ViewUtil.setBottomMargin(footer, collapsedBottomMargin, false);
|
||||
needsMeasure = true;
|
||||
updatingFooter = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!updatingFooter && !messageRecord.isFailed() && bodyText.getLastLineWidth() + ViewUtil.dpToPx(6) + footerWidth <= bodyText.getMeasuredWidth()) {
|
||||
ViewUtil.setTopMargin(footer, collapsedTopMargin);
|
||||
ViewUtil.setBottomMargin(footer, collapsedBottomMargin);
|
||||
ViewUtil.setTopMargin(footer, collapsedTopMargin, false);
|
||||
ViewUtil.setBottomMargin(footer, collapsedBottomMargin, false);
|
||||
updatingFooter = true;
|
||||
needsMeasure = true;
|
||||
}
|
||||
|
@ -579,8 +579,8 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
|
|||
|
||||
int defaultTopMarginForRecord = getDefaultTopMarginForRecord(messageRecord, defaultTopMargin, defaultBottomMargin);
|
||||
if (!updatingFooter && ViewUtil.getTopMargin(footer) != defaultTopMarginForRecord) {
|
||||
ViewUtil.setTopMargin(footer, defaultTopMarginForRecord);
|
||||
ViewUtil.setBottomMargin(footer, defaultBottomMargin);
|
||||
ViewUtil.setTopMargin(footer, defaultTopMarginForRecord, false);
|
||||
ViewUtil.setBottomMargin(footer, defaultBottomMargin, false);
|
||||
needsMeasure = true;
|
||||
}
|
||||
|
||||
|
@ -1626,17 +1626,17 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
|
|||
}
|
||||
|
||||
if (!isFooterVisible(current, next, isGroupThread) && isStoryReaction(current)) {
|
||||
ViewUtil.setBottomMargin(quoteView, (int) DimensionUnit.DP.toPixels(8));
|
||||
ViewUtil.setBottomMargin(quoteView, (int) DimensionUnit.DP.toPixels(8), false);
|
||||
} else {
|
||||
ViewUtil.setBottomMargin(quoteView, 0);
|
||||
ViewUtil.setBottomMargin(quoteView, 0, false);
|
||||
}
|
||||
|
||||
if (mediaThumbnailStub.resolved()) {
|
||||
ViewUtil.setTopMargin(mediaThumbnailStub.require(), readDimen(R.dimen.message_bubble_top_padding));
|
||||
ViewUtil.setTopMargin(mediaThumbnailStub.require(), readDimen(R.dimen.message_bubble_top_padding), false);
|
||||
}
|
||||
|
||||
if (linkPreviewStub.resolved() && !hasBigImageLinkPreview(current)) {
|
||||
ViewUtil.setTopMargin(linkPreviewStub.get(), readDimen(R.dimen.message_bubble_top_padding));
|
||||
ViewUtil.setTopMargin(linkPreviewStub.get(), readDimen(R.dimen.message_bubble_top_padding), false);
|
||||
}
|
||||
} else {
|
||||
if (quoteView != null) {
|
||||
|
@ -1645,7 +1645,7 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
|
|||
|
||||
int topMargin = (current.isOutgoing() || !startOfCluster || !groupThread) ? 0 : readDimen(R.dimen.message_bubble_top_image_margin);
|
||||
if (mediaThumbnailStub.resolved()) {
|
||||
ViewUtil.setTopMargin(mediaThumbnailStub.require(), topMargin);
|
||||
ViewUtil.setTopMargin(mediaThumbnailStub.require(), topMargin, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -285,14 +285,41 @@ public final class ViewUtil {
|
|||
view.requestLayout();
|
||||
}
|
||||
|
||||
public static void setTopMargin(@NonNull View view, int margin) {
|
||||
((ViewGroup.MarginLayoutParams) view.getLayoutParams()).topMargin = margin;
|
||||
view.requestLayout();
|
||||
public static void setTopMargin(@NonNull View view, @Px int margin) {
|
||||
setTopMargin(view, margin, true);
|
||||
}
|
||||
|
||||
public static void setBottomMargin(@NonNull View view, int margin) {
|
||||
/**
|
||||
* Sets the top margin of the view and optionally requests a new layout pass.
|
||||
*
|
||||
* @param view The view to set the margin on
|
||||
* @param margin The margin to set
|
||||
* @param requestLayout Whether requestLayout should be invoked on the view
|
||||
*/
|
||||
public static void setTopMargin(@NonNull View view, @Px int margin, boolean requestLayout) {
|
||||
((ViewGroup.MarginLayoutParams) view.getLayoutParams()).topMargin = margin;
|
||||
|
||||
if (requestLayout) {
|
||||
view.requestLayout();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBottomMargin(@NonNull View view, @Px int margin) {
|
||||
setBottomMargin(view, margin, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bottom margin of the view and optionally requests a new layout pass.
|
||||
*
|
||||
* @param view The view to set the margin on
|
||||
* @param margin The margin to set
|
||||
* @param requestLayout Whether requestLayout should be invoked on the view
|
||||
*/
|
||||
public static void setBottomMargin(@NonNull View view, @Px int margin, boolean requestLayout) {
|
||||
((ViewGroup.MarginLayoutParams) view.getLayoutParams()).bottomMargin = margin;
|
||||
view.requestLayout();
|
||||
if (requestLayout) {
|
||||
view.requestLayout();
|
||||
}
|
||||
}
|
||||
|
||||
public static int getWidth(@NonNull View view) {
|
||||
|
|
Loading…
Add table
Reference in a new issue