mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 04:58:45 +00:00
Split reaction view updates to separate width from adding views.
This commit is contained in:
committed by
Nicholas Tinsley
parent
f37568b050
commit
c45e79c588
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user