From 896770b6dbee0e6908b24f19fcfd860014b00e35 Mon Sep 17 00:00:00 2001 From: NextAlone <12210746+NextAlone@users.noreply.github.com> Date: Mon, 21 Mar 2022 02:37:29 +0800 Subject: [PATCH] fix: double tap action --- .../java/org/telegram/ui/ChatActivity.java | 190 ++++++++++-------- .../settings/NekoChatSettingsActivity.java | 10 +- .../xyz/nextalone/nagram/helper/DoubleTap.kt | 33 +-- .../src/main/res/values-zh-rCN/strings_na.xml | 2 + .../src/main/res/values/strings_na.xml | 2 + 5 files changed, 136 insertions(+), 101 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index f30644a90..036dc0a51 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -1504,7 +1504,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (NaConfig.INSTANCE.getDoubleTapAction().Int() == DoubleTap.DOUBLE_TAP_ACTION_NONE || !(view instanceof ChatMessageCell)) { return false; } - if (NaConfig.INSTANCE.getDoubleTapAction().Int() == DoubleTap.DOUBLE_TAP_ACTION_REACTION) { + if (NaConfig.INSTANCE.getDoubleTapAction().Int() == DoubleTap.DOUBLE_TAP_ACTION_SEND_REACTIONS || NaConfig.INSTANCE.getDoubleTapAction().Int() == DoubleTap.DOUBLE_TAP_ACTION_SHOW_REACTIONS) { TLRPC.TL_availableReaction reaction = getMediaDataController().getReactionsMap().get(getMediaDataController().getDoubleTapReaction()); if (reaction == null) { return false; @@ -1549,20 +1549,18 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not allowEdit = captionsCount < 2; } switch (NaConfig.INSTANCE.getDoubleTapAction().Int()) { - /*case NekoConfig.DOUBLE_TAP_ACTION_TRANSLATE: - if (NekoConfig.transType != NekoConfig.TRANS_TYPE_EXTERNAL || !noforwards) { - MessageObject messageObject = getMessageHelper().getMessageForTranslate(message, messageGroup); - if (messageObject != null) { - return true; - } - } - break; - - */ +// case DoubleTap.DOUBLE_TAP_ACTION_TRANSLATE: +// if (NekoConfig.transType != NekoConfig.TRANS_TYPE_EXTERNAL || !noforwards) { +// MessageObject messageObject = getMessageHelper().getMessageForTranslate(message, messageGroup); +// if (messageObject != null) { +// return true; +// } +// } +// break; case DoubleTap.DOUBLE_TAP_ACTION_REPLY: return message.getId() > 0 && allowChatActions; case DoubleTap.DOUBLE_TAP_ACTION_SAVE: - return !message.isSponsored() && chatMode != MODE_SCHEDULED && !message.needDrawBluredPreview() && !message.isLiveLocation() && message.type != 16 && !getMessagesController().isChatNoForwards(currentChat) && !UserObject.isUserSelf(currentUser); + return !message.isSponsored() && chatMode != MODE_SCHEDULED && !message.needDrawBluredPreview() && !message.isLiveLocation() && message.type != 16 && !getMessagesController().isChatNoForwardsWithOverride(currentChat) && !UserObject.isUserSelf(currentUser); case DoubleTap.DOUBLE_TAP_ACTION_REPEAT: allowRepeat = allowChatActions && (!isThreadChat() && !noforwards || @@ -1582,34 +1580,62 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not @Override public void onDoubleTap(View view, int position, float x, float y) { - if (!(view instanceof ChatMessageCell) || getParentActivity() == null || isSecretChat() || isInScheduleMode()) { + if (NaConfig.INSTANCE.getDoubleTapAction().Int() == DoubleTap.DOUBLE_TAP_ACTION_NONE || !(view instanceof ChatMessageCell) || getParentActivity() == null) { return; } - if (NekoConfig.reactions.Int() == 2) return; - if (NekoConfig.reactions.Int() == 1) { + if (NaConfig.INSTANCE.getDoubleTapAction().Int() == DoubleTap.DOUBLE_TAP_ACTION_SHOW_REACTIONS) { + if (isSecretChat() || isInScheduleMode()) { + return; + } createMenu(view, true, false, x, y, true, true); return; - } - ChatMessageCell cell = (ChatMessageCell) view; - MessageObject primaryMessage = cell.getPrimaryMessageObject(); - ReactionsEffectOverlay.removeCurrent(false); - TLRPC.TL_availableReaction reaction = getMediaDataController().getReactionsMap().get(getMediaDataController().getDoubleTapReaction()); - if (reaction == null || cell.getMessageObject().isSponsored()) { - return; - } - boolean available = dialog_id >= 0; - if (!available && chatInfo != null) { - for (String s : chatInfo.available_reactions) { - if (s.equals(reaction.reaction)) { - available = true; - break; + } else if (NaConfig.INSTANCE.getDoubleTapAction().Int() == DoubleTap.DOUBLE_TAP_ACTION_SEND_REACTIONS) { + if (isSecretChat() || isInScheduleMode()) { + return; + } + ChatMessageCell cell = (ChatMessageCell) view; + MessageObject primaryMessage = cell.getPrimaryMessageObject(); + ReactionsEffectOverlay.removeCurrent(false); + TLRPC.TL_availableReaction reaction = getMediaDataController().getReactionsMap().get(getMediaDataController().getDoubleTapReaction()); + if (reaction == null || cell.getMessageObject().isSponsored()) { + return; + } + boolean available = dialog_id >= 0; + if (!available && chatInfo != null) { + for (String s : chatInfo.available_reactions) { + if (s.equals(reaction.reaction)) { + available = true; + break; + } } } + if (!available) { + return; + } + selectReaction(primaryMessage, null, x, y, reaction, true, false); + } else { + var cell = (ChatMessageCell) view; + var message = cell.getMessageObject(); + selectedObject = message; + selectedObjectGroup = getValidGroupedMessage(message); + switch (NaConfig.INSTANCE.getDoubleTapAction().Int()) { + case DoubleTap.DOUBLE_TAP_ACTION_REPLY: + processSelectedOption(OPTION_REPLY); + break; + case DoubleTap.DOUBLE_TAP_ACTION_SAVE: + processSelectedOption(nkbtn_savemessage); + break; + case DoubleTap.DOUBLE_TAP_ACTION_REPEAT: + processSelectedOption(nkbtn_repeat); + break; + case DoubleTap.DOUBLE_TAP_ACTION_REPEAT_AS_COPY: + processSelectedOption(nkbtn_repeatascopy); + break; + case DoubleTap.DOUBLE_TAP_ACTION_EDIT: + processSelectedOption(OPTION_EDIT); + break; + } } - if (!available) { - return; - } - selectReaction(primaryMessage, null, x, y, reaction, true, false); } }; @@ -22101,19 +22127,15 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } boolean allowRepeat = currentUser != null || (currentChat != null && ChatObject.canSendMessages(currentChat)); - if (allowRepeat && NekoConfig.showRepeat.Bool()) { - if (!noforward) { + if (allowRepeat && NekoConfig.showRepeat.Bool() && !noforwardOverride) { items.add(LocaleController.getString("Repeat", R.string.Repeat)); options.add(nkbtn_repeat); icons.add(R.drawable.msg_repeat); - items.add(LocaleController.getString("RepeatAsCopy", R.string.RepeatAsCopy)); - options.add(nkbtn_repeatascopy); - icons.add(R.drawable.msg_repeat); - } else { - items.add(LocaleController.getString("RepeatAsCopy", R.string.RepeatAsCopy)); - options.add(nkbtn_repeatascopy); - icons.add(R.drawable.msg_repeat); - } + } + if (NaConfig.INSTANCE.getShowRepeatAsCopy().Bool()){ + items.add(LocaleController.getString("RepeatAsCopy", R.string.RepeatAsCopy)); + options.add(nkbtn_repeatascopy); + icons.add(R.drawable.msg_repeat); } if (NaConfig.INSTANCE.getShowInvertReply().Bool()) { items.add(LocaleController.getString("InvertReply", R.string.InvertReply)); @@ -24136,11 +24158,11 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } case nkbtn_repeat: { - repeatMessage(true,false); + repeatMessage(true, false); return 2; } case nkbtn_repeatascopy: { - repeatMessage(true,true); + repeatMessage(true, true); return 2; } case nkbtn_invertReply: { @@ -29334,10 +29356,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not return; presentFragment(new ChatActivity(args), true); } else if (id == nkbtn_repeat) { - repeatMessage(false,false); + repeatMessage(false, false); clearSelectionMode(); - }else if (id == nkbtn_repeatascopy){ - repeatMessage(false,true); + } else if (id == nkbtn_repeatascopy) { + repeatMessage(false, true); clearSelectionMode(); } else if (id == nkbtn_invertReply) { invertReplyMessage(false); @@ -29355,8 +29377,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not repeatMessage(false,false); break; } - case nkbtn_repeatascopy:{ - repeatMessage(false,true); + case nkbtn_repeatascopy: { + repeatMessage(false, true); break; } case nkbtn_invertReply: { @@ -29627,10 +29649,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } } - private void repeatMessage(boolean isLongClick,boolean isRepeatasCopy) { - if (checkSlowMode(chatActivityEnterView.getSendButton())) { - return; - } + private void repeatMessage(boolean isLongClick, boolean isRepeatasCopy) { + if (checkSlowMode(chatActivityEnterView.getSendButton())) { + return; + } final ArrayList messages = new ArrayList<>(); if (selectedObject != null) messages.add(selectedObject); @@ -29653,47 +29675,47 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not builder.setTitle(LocaleController.getString("Repeat", R.string.Repeat)); builder.setMessage(LocaleController.getString("repeatConfirmText", R.string.repeatConfirmText)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> { - if (isRepeatasCopy){ - doRepeatMessage(isLongClick, messages,true); - }else{ - doRepeatMessage(isLongClick, messages,false); + if (isRepeatasCopy) { + doRepeatMessage(isLongClick, messages, true); + } else { + doRepeatMessage(isLongClick, messages, false); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } - private void doRepeatMessage(boolean isLongClick, ArrayList messages,boolean isRepeatasCopy) { - if (selectedObject != null && selectedObject.messageOwner != null && (isLongClick || isThreadChat() || getMessagesController().isChatNoForwards(currentChat) )) { - // If selected message contains `replyTo`: - // When longClick it will reply to the `replyMessage` of selectedMessage - // When not LongClick but in a threadchat: reply to the Thread - MessageObject replyTo = selectedObject.replyMessageObject != null ? isLongClick ? selectedObject.replyMessageObject : getThreadMessage() : getThreadMessage(); - if (selectedObject.type == 0 || selectedObject.isAnimatedEmoji() || getMessageCaption(selectedObject, selectedObjectGroup) != null) { - CharSequence caption = getMessageCaption(selectedObject, selectedObjectGroup); - if (caption == null) { - caption = getMessageContent(selectedObject, 0, false); - } - if (!TextUtils.isEmpty(caption)) { + private void doRepeatMessage(boolean isLongClick, ArrayList messages, boolean isRepeatAsCopy) { + if (selectedObject != null && selectedObject.messageOwner != null && (isLongClick || isThreadChat() || getMessagesController().isChatNoForwards(currentChat))) { + // If selected message contains `replyTo`: + // When longClick it will reply to the `replyMessage` of selectedMessage + // When not LongClick but in a threadchat: reply to the Thread + MessageObject replyTo = selectedObject.replyMessageObject != null ? isLongClick ? selectedObject.replyMessageObject : getThreadMessage() : getThreadMessage(); + if (selectedObject.type == 0 || selectedObject.isAnimatedEmoji() || getMessageCaption(selectedObject, selectedObjectGroup) != null) { + CharSequence caption = getMessageCaption(selectedObject, selectedObjectGroup); + if (caption == null) { + caption = getMessageContent(selectedObject, 0, false); + } + if (!TextUtils.isEmpty(caption)) { + SendMessagesHelper.getInstance(currentAccount) + .sendMessage(caption.toString(), dialog_id, replyTo, + getThreadMessage(), null, + false, selectedObject.messageOwner.entities, null, null, + true, 0, null); + } + } else if ((selectedObject.isSticker() || selectedObject.isAnimatedSticker()) && selectedObject.getDocument() != null) { SendMessagesHelper.getInstance(currentAccount) - .sendMessage(caption.toString(), dialog_id, replyTo, - getThreadMessage(), null, - false, selectedObject.messageOwner.entities, null, null, - true, 0, null); + .sendSticker(selectedObject.getDocument(), null, dialog_id, replyTo, getThreadMessage(), null, null, true, 0); } - } else if ((selectedObject.isSticker() || selectedObject.isAnimatedSticker()) && selectedObject.getDocument() != null) { - SendMessagesHelper.getInstance(currentAccount) - .sendSticker(selectedObject.getDocument(), null, dialog_id, replyTo, getThreadMessage(), null, null, true, 0); + return; } - return; - } - if (isRepeatasCopy){ - forwardMessages(messages, true, false, true, 0); - }else { - forwardMessages(messages, false, false, true, 0); + if (isRepeatAsCopy) { + forwardMessages(messages, true, false, true, 0); + } else { + forwardMessages(messages, false, false, true, 0); + } } - } public void invertReplyMessage(boolean isLongClick){ if (checkSlowMode(chatActivityEnterView.getSendButton())) { diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java index 11311752f..a8e046304 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java @@ -243,10 +243,12 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati ArrayList types = new ArrayList<>(); arrayList.add(LocaleController.getString("Disable", R.string.Disable)); types.add(DoubleTap.DOUBLE_TAP_ACTION_NONE); - arrayList.add(LocaleController.getString("Reactions", R.string.Reactions)); - types.add(DoubleTap.DOUBLE_TAP_ACTION_REACTION); - //arrayList.add(LocaleController.getString("TranslateMessage", R.string.TranslateMessage)); - //types.add(DoubleTapConfig.DOUBLE_TAP_ACTION_TRANSLATE); + arrayList.add(LocaleController.getString("SendReactions", R.string.SendReactions)); + types.add(DoubleTap.DOUBLE_TAP_ACTION_SEND_REACTIONS); + arrayList.add(LocaleController.getString("ShowReactions", R.string.ShowReactions)); + types.add(DoubleTap.DOUBLE_TAP_ACTION_SHOW_REACTIONS); + // arrayList.add(LocaleController.getString("TranslateMessage", R.string.TranslateMessage)); + // types.add(DoubleTap.DOUBLE_TAP_ACTION_TRANSLATE); arrayList.add(LocaleController.getString("Reply", R.string.Reply)); types.add(DoubleTap.DOUBLE_TAP_ACTION_REPLY); arrayList.add(LocaleController.getString("AddToSavedMessages", R.string.AddToSavedMessages)); diff --git a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/DoubleTap.kt b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/DoubleTap.kt index 934da37c4..a031079d7 100644 --- a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/DoubleTap.kt +++ b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/DoubleTap.kt @@ -9,20 +9,22 @@ object DoubleTap { HashMap() const val DOUBLE_TAP_ACTION_NONE = 0 - const val DOUBLE_TAP_ACTION_REACTION = + const val DOUBLE_TAP_ACTION_SEND_REACTIONS = 1 -// const val DOUBLE_TAP_ACTION_TRANSLATE = -// 2 - const val DOUBLE_TAP_ACTION_REPLY = + const val DOUBLE_TAP_ACTION_SHOW_REACTIONS = 2 - const val DOUBLE_TAP_ACTION_SAVE = +// const val DOUBLE_TAP_ACTION_TRANSLATE = +// 3 + const val DOUBLE_TAP_ACTION_REPLY = 3 - const val DOUBLE_TAP_ACTION_REPEAT = + const val DOUBLE_TAP_ACTION_SAVE = 4 - const val DOUBLE_TAP_ACTION_REPEAT_AS_COPY = + const val DOUBLE_TAP_ACTION_REPEAT = 5 - const val DOUBLE_TAP_ACTION_EDIT = + const val DOUBLE_TAP_ACTION_REPEAT_AS_COPY = 6 + const val DOUBLE_TAP_ACTION_EDIT = + 7 init { doubleTapActionMap[DOUBLE_TAP_ACTION_NONE] = @@ -30,10 +32,15 @@ object DoubleTap { "Disable", R.string.Disable ) - doubleTapActionMap[DOUBLE_TAP_ACTION_REACTION] = + doubleTapActionMap[DOUBLE_TAP_ACTION_SEND_REACTIONS] = LocaleController.getString( - "Reactions", - R.string.Reactions + "SendReactions", + R.string.SendReactions + ) + doubleTapActionMap[DOUBLE_TAP_ACTION_SHOW_REACTIONS] = + LocaleController.getString( + "ShowReactions", + R.string.ShowReactions ) // doubleTapActionMap[DOUBLE_TAP_ACTION_TRANSLATE] = // LocaleController.getString( @@ -47,8 +54,8 @@ object DoubleTap { ) doubleTapActionMap[DOUBLE_TAP_ACTION_SAVE] = LocaleController.getString( - "Save", - R.string.Save + "AddToSavedMessages", + R.string.AddToSavedMessages ) doubleTapActionMap[DOUBLE_TAP_ACTION_REPEAT] = LocaleController.getString( diff --git a/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml b/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml index 7e264fc07..19cbfac46 100644 --- a/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml +++ b/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml @@ -16,4 +16,6 @@ 噪音抑制和语音增强 无引用复读 双击操作 + 表情回应 + 显示表情回应菜单 diff --git a/TMessagesProj/src/main/res/values/strings_na.xml b/TMessagesProj/src/main/res/values/strings_na.xml index fbc7a0800..05a306ecd 100644 --- a/TMessagesProj/src/main/res/values/strings_na.xml +++ b/TMessagesProj/src/main/res/values/strings_na.xml @@ -16,4 +16,6 @@ Noise Suppress And Voice Enhance Repeat as Copy Double Tap Action + Send Reactions + Show Reactions