Making sure we display the emoji that was long pressed

This commit is contained in:
ThomasSession 2024-08-27 15:17:53 +10:00
parent 1561295c25
commit 9abe154311
4 changed files with 24 additions and 7 deletions

View File

@ -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) { if (viewModel.recipient?.isGroupRecipient == true) {
val isUserModerator = viewModel.openGroup?.let { openGroup -> val isUserModerator = viewModel.openGroup?.let { openGroup ->
val userPublicKey = textSecurePreferences.getLocalNumber() ?: return@let false val userPublicKey = textSecurePreferences.getLocalNumber() ?: return@let false
OpenGroupManager.isUserModerator(this, openGroup.id, userPublicKey, viewModel.blindedPublicKey) OpenGroupManager.isUserModerator(this, openGroup.id, userPublicKey, viewModel.blindedPublicKey)
} ?: false } ?: false
val fragment = ReactionsDialogFragment.create(messageId, isUserModerator) val fragment = ReactionsDialogFragment.create(messageId, isUserModerator, emoji)
fragment.show(supportFragmentManager, null) fragment.show(supportFragmentManager, null)
} }
} }

View File

@ -84,7 +84,9 @@ class EmojiReactionsView : ConstraintLayout, OnTouchListener {
if (v.tag == null) return false if (v.tag == null) return false
val reaction = v.tag as Reaction val reaction = v.tag as Reaction
val action = event.action 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 return true
} }
@ -216,12 +218,12 @@ class EmojiReactionsView : ConstraintLayout, OnTouchListener {
} }
} }
private fun onDown(messageId: MessageId) { private fun onDown(messageId: MessageId, emoji: String?) {
removeLongPressCallback() removeLongPressCallback()
val newLongPressCallback = Runnable { val newLongPressCallback = Runnable {
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
if (delegate != null) { if (delegate != null) {
delegate!!.onReactionLongClicked(messageId) delegate!!.onReactionLongClicked(messageId, emoji)
} }
} }
longPressCallback = newLongPressCallback longPressCallback = newLongPressCallback

View File

@ -10,6 +10,6 @@ interface VisibleMessageViewDelegate {
fun onReactionClicked(emoji: String, messageId: MessageId, userWasSender: Boolean) fun onReactionClicked(emoji: String, messageId: MessageId, userWasSender: Boolean)
fun onReactionLongClicked(messageId: MessageId) fun onReactionLongClicked(messageId: MessageId, emoji: String?)
} }

View File

@ -21,6 +21,7 @@ import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator; import com.google.android.material.tabs.TabLayoutMediator;
import org.session.libsession.utilities.ThemeUtil; import org.session.libsession.utilities.ThemeUtil;
import org.session.libsignal.utilities.Log;
import org.thoughtcrime.securesms.components.emoji.EmojiImageView; import org.thoughtcrime.securesms.components.emoji.EmojiImageView;
import org.thoughtcrime.securesms.database.model.MessageId; import org.thoughtcrime.securesms.database.model.MessageId;
import org.thoughtcrime.securesms.util.LifecycleDisposable; 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_MESSAGE_ID = "reactions.args.message.id";
private static final String ARGS_IS_MMS = "reactions.args.is.mms"; 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_IS_MODERATOR = "reactions.args.is.moderator";
private static final String ARGS_EMOJI = "reactions.args.emoji";
private ViewPager2 recipientPagerView; private ViewPager2 recipientPagerView;
private ReactionViewPagerAdapter recipientsAdapter; private ReactionViewPagerAdapter recipientsAdapter;
@ -42,13 +44,14 @@ public final class ReactionsDialogFragment extends BottomSheetDialogFragment imp
private final LifecycleDisposable disposables = new LifecycleDisposable(); 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(); Bundle args = new Bundle();
DialogFragment fragment = new ReactionsDialogFragment(); DialogFragment fragment = new ReactionsDialogFragment();
args.putLong(ARGS_MESSAGE_ID, messageId.getId()); args.putLong(ARGS_MESSAGE_ID, messageId.getId());
args.putBoolean(ARGS_IS_MMS, messageId.isMms()); args.putBoolean(ARGS_IS_MMS, messageId.isMms());
args.putBoolean(ARGS_IS_MODERATOR, isUserModerator); args.putBoolean(ARGS_IS_MODERATOR, isUserModerator);
args.putString(ARGS_EMOJI, emoji);
fragment.setArguments(args); fragment.setArguments(args);
@ -168,6 +171,18 @@ public final class ReactionsDialogFragment extends BottomSheetDialogFragment imp
} }
recipientsAdapter.submitList(emojiCounts); 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));
})); }));
} }