Split reaction view updates to separate width from adding views.

This commit is contained in:
Alex Hart
2023-09-05 15:30:19 -03:00
committed by Nicholas Tinsley
parent f37568b050
commit c45e79c588
3 changed files with 28 additions and 19 deletions

View File

@@ -1676,7 +1676,8 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
}
private void setReactionsWithWidth(@NonNull MessageRecord current, int width) {
reactionsView.setReactions(current.getReactions(), width);
reactionsView.setReactions(current.getReactions());
reactionsView.setBubbleWidth(width);
reactionsView.setOnClickListener(v -> {
if (eventListener == null) return;

View File

@@ -537,7 +537,7 @@ open class V2ConversationItemTextOnlyViewHolder<Model : MappingModel<Model>>(
binding.conversationItemReactions.clear()
binding.root.removeOnMeasureListener(reactionMeasureListener)
} else {
reactionMeasureListener.onPostMeasure()
binding.conversationItemReactions.setReactions(conversationMessage.messageRecord.reactions)
binding.root.addOnMeasureListener(reactionMeasureListener)
}
}
@@ -655,11 +655,7 @@ open class V2ConversationItemTextOnlyViewHolder<Model : MappingModel<Model>>(
override fun onPreMeasure() = Unit
override fun onPostMeasure(): Boolean {
if (binding.conversationItemReactions.setReactions(conversationMessage.messageRecord.reactions, binding.conversationItemBodyWrapper.width)) {
binding.conversationItemReactions.post(binding.conversationItemReactions::requestLayout)
}
return false
return binding.conversationItemReactions.setBubbleWidth(binding.conversationItemBodyWrapper.measuredWidth)
}
}

View File

@@ -63,24 +63,16 @@ public class ReactionsConversationView extends LinearLayout {
removeAllViews();
}
public boolean setReactions(@NonNull List<ReactionRecord> records, int bubbleWidth) {
if (records.equals(this.records) && this.bubbleWidth == bubbleWidth) {
public boolean setBubbleWidth(int bubbleWidth) {
if (bubbleWidth == this.bubbleWidth) {
return false;
}
this.records.clear();
this.records.addAll(records);
this.bubbleWidth = bubbleWidth;
List<Reaction> reactions = buildSortedReactionsList(records);
removeAllViews();
for (Reaction reaction : reactions) {
View pill = buildPill(getContext(), this, reaction);
for (int i = 0; i < getChildCount(); i++) {
View pill = getChildAt(i);
pill.setVisibility(bubbleWidth == 0 ? INVISIBLE : VISIBLE);
addView(pill);
}
measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
@@ -106,6 +98,26 @@ public class ReactionsConversationView extends LinearLayout {
return true;
}
public boolean setReactions(@NonNull List<ReactionRecord> records) {
if (records.equals(this.records)) {
return false;
}
this.records.clear();
this.records.addAll(records);
List<Reaction> reactions = buildSortedReactionsList(records);
removeAllViews();
for (Reaction reaction : reactions) {
View pill = buildPill(getContext(), this, reaction);
addView(pill);
}
return true;
}
private static @NonNull List<Reaction> buildSortedReactionsList(@NonNull List<ReactionRecord> records) {
Map<String, Reaction> counters = new LinkedHashMap<>();
RecipientId selfId = Recipient.self().getId();