mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 14:38:33 +00:00
Fix layout issues with reaction badges.
This commit is contained in:
parent
eaa1760511
commit
28e2f22550
@ -905,22 +905,22 @@ public class ConversationItem extends LinearLayout implements BindableConversati
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setReactions(@NonNull MessageRecord current) {
|
private void setReactions(@NonNull MessageRecord current) {
|
||||||
|
bodyBubble.setOnSizeChangedListener(null);
|
||||||
|
|
||||||
if (current.getReactions().isEmpty()) {
|
if (current.getReactions().isEmpty()) {
|
||||||
reactionsView.clear();
|
reactionsView.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bodyBubble.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
if (bodyBubble.getWidth() != 0) {
|
||||||
@Override
|
setReactionsWithWidth(current, bodyBubble.getWidth());
|
||||||
public void onGlobalLayout() {
|
}
|
||||||
setReactionsWithWidth(current);
|
|
||||||
bodyBubble.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
bodyBubble.setOnSizeChangedListener((width, height) -> setReactionsWithWidth(current, width));
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setReactionsWithWidth(@NonNull MessageRecord current) {
|
private void setReactionsWithWidth(@NonNull MessageRecord current, int width) {
|
||||||
reactionsView.setReactions(current.getReactions(), bodyBubble.getWidth());
|
reactionsView.setReactions(current.getReactions(), width);
|
||||||
reactionsView.setOnClickListener(v -> {
|
reactionsView.setOnClickListener(v -> {
|
||||||
if (eventListener == null) return;
|
if (eventListener == null) return;
|
||||||
|
|
||||||
|
@ -11,7 +11,8 @@ import org.thoughtcrime.securesms.components.Outliner;
|
|||||||
|
|
||||||
public class ConversationItemBodyBubble extends LinearLayout {
|
public class ConversationItemBodyBubble extends LinearLayout {
|
||||||
|
|
||||||
private @Nullable Outliner outliner;
|
@Nullable private Outliner outliner;
|
||||||
|
@Nullable private OnSizeChangedListener sizeChangedListener;
|
||||||
|
|
||||||
public ConversationItemBodyBubble(Context context) {
|
public ConversationItemBodyBubble(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@ -29,6 +30,10 @@ public class ConversationItemBodyBubble extends LinearLayout {
|
|||||||
this.outliner = outliner;
|
this.outliner = outliner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setOnSizeChangedListener(@Nullable OnSizeChangedListener listener) {
|
||||||
|
this.sizeChangedListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
@ -37,5 +42,20 @@ public class ConversationItemBodyBubble extends LinearLayout {
|
|||||||
|
|
||||||
outliner.draw(canvas, 0, getMeasuredWidth(), getMeasuredHeight(), 0);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import com.annimon.stream.Stream;
|
|||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.database.model.ReactionRecord;
|
import org.thoughtcrime.securesms.database.model.ReactionRecord;
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||||
@ -34,6 +33,7 @@ public class ReactionsConversationView extends LinearLayout {
|
|||||||
|
|
||||||
private boolean outgoing;
|
private boolean outgoing;
|
||||||
private List<ReactionRecord> records;
|
private List<ReactionRecord> records;
|
||||||
|
private int bubbleWidth;
|
||||||
|
|
||||||
public ReactionsConversationView(Context context) {
|
public ReactionsConversationView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@ -54,18 +54,22 @@ public class ReactionsConversationView extends LinearLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
removeAllViews();
|
removeAllViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReactions(@NonNull List<ReactionRecord> records, int bubbleWidth) {
|
public void setReactions(@NonNull List<ReactionRecord> records, int bubbleWidth) {
|
||||||
if (records.equals(this.records)) {
|
if (records.equals(this.records) && this.bubbleWidth == bubbleWidth) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.records.clear();
|
this.records.clear();
|
||||||
this.records.addAll(records);
|
this.records.addAll(records);
|
||||||
|
|
||||||
|
this.bubbleWidth = bubbleWidth;
|
||||||
|
|
||||||
List<Reaction> reactions = buildSortedReactionsList(records);
|
List<Reaction> reactions = buildSortedReactionsList(records);
|
||||||
|
|
||||||
removeAllViews();
|
removeAllViews();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user