Skip to content

Commit

Permalink
Update reactions UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Feb 3, 2020
1 parent 1dd2a4e commit 73160d4
Show file tree
Hide file tree
Showing 18 changed files with 339 additions and 277 deletions.
Expand Up @@ -42,6 +42,7 @@
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
Expand Down Expand Up @@ -97,6 +98,7 @@
import org.thoughtcrime.securesms.mms.SlideClickListener;
import org.thoughtcrime.securesms.mms.SlidesClickedListener;
import org.thoughtcrime.securesms.mms.TextSlide;
import org.thoughtcrime.securesms.reactions.ReactionsConversationView;
import org.thoughtcrime.securesms.recipients.LiveRecipient;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientForeverObserver;
Expand Down Expand Up @@ -158,7 +160,7 @@ public class ConversationItem extends LinearLayout implements BindableConversati
private AvatarImageView contactPhoto;
private AlertView alertView;
private ViewGroup container;
protected ViewGroup reactionsContainer;
protected ReactionsConversationView reactionsView;

private @NonNull Set<MessageRecord> batchSelected = new HashSet<>();
private @NonNull Outliner outliner = new Outliner();
Expand All @@ -171,7 +173,6 @@ public class ConversationItem extends LinearLayout implements BindableConversati
private Stub<StickerView> stickerStub;
private Stub<ViewOnceMessageView> revealableStub;
private @Nullable EventListener eventListener;
private ConversationItemReactionBubbles conversationItemReactionBubbles;

private int defaultBubbleColor;
private int measureCalls;
Expand Down Expand Up @@ -226,9 +227,7 @@ protected void onFinishInflate() {
this.quoteView = findViewById(R.id.quote_view);
this.container = findViewById(R.id.container);
this.reply = findViewById(R.id.reply_icon);
this.reactionsContainer = findViewById(R.id.reactions_bubbles_container);

this.conversationItemReactionBubbles = new ConversationItemReactionBubbles(this.reactionsContainer);
this.reactionsView = findViewById(R.id.reactions_view);

setOnClickListener(new ClickListener(null));

Expand Down Expand Up @@ -906,8 +905,23 @@ private void setGutterSizes(@NonNull MessageRecord current, boolean isGroupThrea
}

private void setReactions(@NonNull MessageRecord current) {
conversationItemReactionBubbles.setReactions(current.getReactions());
reactionsContainer.setOnClickListener(v -> {
if (current.getReactions().isEmpty()) {
reactionsView.clear();
return;
}

bodyBubble.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
setReactionsWithWidth(current);
bodyBubble.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}

private void setReactionsWithWidth(@NonNull MessageRecord current) {
reactionsView.setReactions(current.getReactions(), bodyBubble.getWidth());
reactionsView.setOnClickListener(v -> {
if (eventListener == null) return;

eventListener.onReactionClicked(current.getId(), current.isMms());
Expand Down

This file was deleted.

Expand Up @@ -33,7 +33,7 @@ public static void update(@NonNull ConversationItem conversationItem, float dx,
float progress = dx / TRIGGER_DX;

updateBodyBubbleTransition(conversationItem.bodyBubble, dx, sign);
updateReactionsTransition(conversationItem.reactionsContainer, dx, sign);
updateReactionsTransition(conversationItem.reactionsView, dx, sign);
updateReplyIconTransition(conversationItem.reply, dx, progress, sign);
updateContactPhotoHolderTransition(conversationItem.contactPhotoHolder, progress, sign);
}
Expand Down
Expand Up @@ -4,6 +4,8 @@

import org.thoughtcrime.securesms.recipients.RecipientId;

import java.util.Objects;

public class ReactionRecord {
private final String emoji;
private final RecipientId author;
Expand Down Expand Up @@ -36,4 +38,20 @@ public long getDateSent() {
public long getDateReceived() {
return dateReceived;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ReactionRecord that = (ReactionRecord) o;
return dateSent == that.dateSent &&
dateReceived == that.dateReceived &&
Objects.equals(emoji, that.emoji) &&
Objects.equals(author, that.author);
}

@Override
public int hashCode() {
return Objects.hash(emoji, author, dateSent, dateReceived);
}
}
Expand Up @@ -49,7 +49,8 @@ public MegaphoneRepository(@NonNull Context context) {
@MainThread
public void onFirstEverAppLaunch() {
executor.execute(() -> {
// Future megaphones we don't want to show to new users should get marked as finished here.
database.markFinished(Event.REACTIONS);
resetDatabaseCache();
});
}

Expand Down

0 comments on commit 73160d4

Please sign in to comment.