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

@@ -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();