Fix layout issues with reaction badges.

master
Greyson Parrelli 2020-02-04 13:17:44 -05:00
parent eaa1760511
commit 28e2f22550
3 changed files with 36 additions and 12 deletions

View File

@ -905,22 +905,22 @@ public class ConversationItem extends LinearLayout implements BindableConversati
}
private void setReactions(@NonNull MessageRecord current) {
bodyBubble.setOnSizeChangedListener(null);
if (current.getReactions().isEmpty()) {
reactionsView.clear();
return;
}
bodyBubble.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
setReactionsWithWidth(current);
bodyBubble.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
if (bodyBubble.getWidth() != 0) {
setReactionsWithWidth(current, bodyBubble.getWidth());
}
bodyBubble.setOnSizeChangedListener((width, height) -> setReactionsWithWidth(current, width));
}
private void setReactionsWithWidth(@NonNull MessageRecord current) {
reactionsView.setReactions(current.getReactions(), bodyBubble.getWidth());
private void setReactionsWithWidth(@NonNull MessageRecord current, int width) {
reactionsView.setReactions(current.getReactions(), width);
reactionsView.setOnClickListener(v -> {
if (eventListener == null) return;

View File

@ -11,7 +11,8 @@ import org.thoughtcrime.securesms.components.Outliner;
public class ConversationItemBodyBubble extends LinearLayout {
private @Nullable Outliner outliner;
@Nullable private Outliner outliner;
@Nullable private OnSizeChangedListener sizeChangedListener;
public ConversationItemBodyBubble(Context context) {
super(context);
@ -29,6 +30,10 @@ public class ConversationItemBodyBubble extends LinearLayout {
this.outliner = outliner;
}
public void setOnSizeChangedListener(@Nullable OnSizeChangedListener listener) {
this.sizeChangedListener = listener;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
@ -37,5 +42,20 @@ public class ConversationItemBodyBubble extends LinearLayout {
outliner.draw(canvas, 0, getMeasuredWidth(), getMeasuredHeight(), 0);
}
@Override
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
if (sizeChangedListener != null) {
post(() -> {
if (sizeChangedListener != null) {
sizeChangedListener.onSizeChanged(width, height);
}
});
}
}
public interface OnSizeChangedListener {
void onSizeChanged(int width, int height);
}
}

View File

@ -16,7 +16,6 @@ import com.annimon.stream.Stream;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.database.model.ReactionRecord;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.util.ThemeUtil;
@ -34,6 +33,7 @@ public class ReactionsConversationView extends LinearLayout {
private boolean outgoing;
private List<ReactionRecord> records;
private int bubbleWidth;
public ReactionsConversationView(Context context) {
super(context);
@ -54,18 +54,22 @@ public class ReactionsConversationView extends LinearLayout {
}
}
public void clear() {
removeAllViews();
}
public void setReactions(@NonNull List<ReactionRecord> records, int bubbleWidth) {
if (records.equals(this.records)) {
if (records.equals(this.records) && this.bubbleWidth == bubbleWidth) {
return;
}
this.records.clear();
this.records.addAll(records);
this.bubbleWidth = bubbleWidth;
List<Reaction> reactions = buildSortedReactionsList(records);
removeAllViews();