fix: double tap action

This commit is contained in:
NextAlone 2022-03-21 02:37:29 +08:00
parent 8e9b78b66a
commit 896770b6db
No known key found for this signature in database
GPG Key ID: DBA7B0AEF8C1CD2C
5 changed files with 136 additions and 101 deletions

View File

@ -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<MessageObject> 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<MessageObject> 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<MessageObject> 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())) {

View File

@ -243,10 +243,12 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati
ArrayList<Integer> 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));

View File

@ -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(

View File

@ -16,4 +16,6 @@
<string name="NoiseSuppressAndVoiceEnhance">噪音抑制和语音增强</string>
<string name="RepeatAsCopy">无引用复读</string>
<string name="DoubleTapAction">双击操作</string>
<string name="SendReactions">表情回应</string>
<string name="ShowReactions">显示表情回应菜单</string>
</resources>

View File

@ -16,4 +16,6 @@
<string name="NoiseSuppressAndVoiceEnhance">Noise Suppress And Voice Enhance</string>
<string name="RepeatAsCopy">Repeat as Copy</string>
<string name="DoubleTapAction">Double Tap Action</string>
<string name="SendReactions">Send Reactions</string>
<string name="ShowReactions">Show Reactions</string>
</resources>