From 9abe1543114c303115513c9ffdae91264284d37f Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Tue, 27 Aug 2024 15:17:53 +1000 Subject: [PATCH] Making sure we display the emoji that was long pressed --- .../conversation/v2/ConversationActivityV2.kt | 4 ++-- .../v2/messages/EmojiReactionsView.kt | 8 +++++--- .../v2/messages/VisibleMessageViewDelegate.kt | 2 +- .../reactions/ReactionsDialogFragment.java | 17 ++++++++++++++++- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index 69844e33b6..306b1699ae 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -1529,13 +1529,13 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe } } - override fun onReactionLongClicked(messageId: MessageId) { + override fun onReactionLongClicked(messageId: MessageId, emoji: String?) { if (viewModel.recipient?.isGroupRecipient == true) { val isUserModerator = viewModel.openGroup?.let { openGroup -> val userPublicKey = textSecurePreferences.getLocalNumber() ?: return@let false OpenGroupManager.isUserModerator(this, openGroup.id, userPublicKey, viewModel.blindedPublicKey) } ?: false - val fragment = ReactionsDialogFragment.create(messageId, isUserModerator) + val fragment = ReactionsDialogFragment.create(messageId, isUserModerator, emoji) fragment.show(supportFragmentManager, null) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/EmojiReactionsView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/EmojiReactionsView.kt index 2234e657bb..9f4ce88879 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/EmojiReactionsView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/EmojiReactionsView.kt @@ -84,7 +84,9 @@ class EmojiReactionsView : ConstraintLayout, OnTouchListener { if (v.tag == null) return false val reaction = v.tag as Reaction val action = event.action - if (action == MotionEvent.ACTION_DOWN) onDown(MessageId(reaction.messageId, reaction.isMms)) else if (action == MotionEvent.ACTION_CANCEL) removeLongPressCallback() else if (action == MotionEvent.ACTION_UP) onUp(reaction) + if (action == MotionEvent.ACTION_DOWN) onDown(MessageId(reaction.messageId, reaction.isMms), reaction.emoji) + else if (action == MotionEvent.ACTION_CANCEL) removeLongPressCallback() + else if (action == MotionEvent.ACTION_UP) onUp(reaction) return true } @@ -216,12 +218,12 @@ class EmojiReactionsView : ConstraintLayout, OnTouchListener { } } - private fun onDown(messageId: MessageId) { + private fun onDown(messageId: MessageId, emoji: String?) { removeLongPressCallback() val newLongPressCallback = Runnable { performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) if (delegate != null) { - delegate!!.onReactionLongClicked(messageId) + delegate!!.onReactionLongClicked(messageId, emoji) } } longPressCallback = newLongPressCallback diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageViewDelegate.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageViewDelegate.kt index 6788dd3f38..69797b8848 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageViewDelegate.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageViewDelegate.kt @@ -10,6 +10,6 @@ interface VisibleMessageViewDelegate { fun onReactionClicked(emoji: String, messageId: MessageId, userWasSender: Boolean) - fun onReactionLongClicked(messageId: MessageId) + fun onReactionLongClicked(messageId: MessageId, emoji: String?) } \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/reactions/ReactionsDialogFragment.java b/app/src/main/java/org/thoughtcrime/securesms/reactions/ReactionsDialogFragment.java index 928d9adc96..f871be0010 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/reactions/ReactionsDialogFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/reactions/ReactionsDialogFragment.java @@ -21,6 +21,7 @@ import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayoutMediator; import org.session.libsession.utilities.ThemeUtil; +import org.session.libsignal.utilities.Log; import org.thoughtcrime.securesms.components.emoji.EmojiImageView; import org.thoughtcrime.securesms.database.model.MessageId; import org.thoughtcrime.securesms.util.LifecycleDisposable; @@ -35,6 +36,7 @@ public final class ReactionsDialogFragment extends BottomSheetDialogFragment imp private static final String ARGS_MESSAGE_ID = "reactions.args.message.id"; private static final String ARGS_IS_MMS = "reactions.args.is.mms"; private static final String ARGS_IS_MODERATOR = "reactions.args.is.moderator"; + private static final String ARGS_EMOJI = "reactions.args.emoji"; private ViewPager2 recipientPagerView; private ReactionViewPagerAdapter recipientsAdapter; @@ -42,13 +44,14 @@ public final class ReactionsDialogFragment extends BottomSheetDialogFragment imp private final LifecycleDisposable disposables = new LifecycleDisposable(); - public static DialogFragment create(MessageId messageId, boolean isUserModerator) { + public static DialogFragment create(MessageId messageId, boolean isUserModerator, @Nullable String emoji) { Bundle args = new Bundle(); DialogFragment fragment = new ReactionsDialogFragment(); args.putLong(ARGS_MESSAGE_ID, messageId.getId()); args.putBoolean(ARGS_IS_MMS, messageId.isMms()); args.putBoolean(ARGS_IS_MODERATOR, isUserModerator); + args.putString(ARGS_EMOJI, emoji); fragment.setArguments(args); @@ -168,6 +171,18 @@ public final class ReactionsDialogFragment extends BottomSheetDialogFragment imp } recipientsAdapter.submitList(emojiCounts); + + // select the tab based on which emoji the user long pressed on + TabLayout emojiTabs = requireDialog().findViewById(R.id.emoji_tabs); + String emoji = requireArguments().getString(ARGS_EMOJI); + int tabIndex = 0; + for (int i = 0; i < emojiCounts.size(); i++) { + if(emojiCounts.get(i).getBaseEmoji().equals(emoji)){ + tabIndex = i; + break; + } + } + emojiTabs.selectTab(emojiTabs.getTabAt(tabIndex)); })); }