From 8e9b78b66aa1cfbdc1f946c908bbd5963690ec67 Mon Sep 17 00:00:00 2001 From: NextAlone <12210746+NextAlone@users.noreply.github.com> Date: Mon, 21 Mar 2022 00:46:37 +0800 Subject: [PATCH] fix: repeat as copy --- .../java/org/telegram/ui/ChatActivity.java | 43 ++++++------ .../java/tw/nekomimi/nekogram/NekoConfig.java | 3 - .../settings/NekoChatSettingsActivity.java | 36 +++++----- .../xyz/nextalone/nagram/DoubleTapConfig.java | 31 --------- .../kotlin/xyz/nextalone/nagram/NaConfig.kt | 8 ++- .../xyz/nextalone/nagram/helper/DoubleTap.kt | 69 +++++++++++++++++++ .../src/main/res/values-zh-rCN/strings_na.xml | 4 +- .../src/main/res/values/strings_na.xml | 2 +- 8 files changed, 119 insertions(+), 77 deletions(-) delete mode 100644 TMessagesProj/src/main/java/xyz/nextalone/nagram/DoubleTapConfig.java create mode 100644 TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/DoubleTap.kt diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 7bc7265ff..f30644a90 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -128,7 +128,6 @@ import org.telegram.messenger.FileLog; import org.telegram.messenger.ForwardingMessagesParams; import org.telegram.messenger.ImageLocation; import org.telegram.messenger.ImageReceiver; -//import org.telegram.messenger.LanguageDetector; import org.telegram.messenger.LocaleController; import org.telegram.messenger.MediaController; import org.telegram.messenger.MediaDataController; @@ -287,21 +286,21 @@ import java.util.regex.Pattern; import cn.hutool.core.util.StrUtil; import kotlin.Unit; -import tw.nekomimi.nekogram.ui.BottomBuilder; -import tw.nekomimi.nekogram.ui.MessageDetailsActivity; -import tw.nekomimi.nekogram.utils.EnvUtil; import tw.nekomimi.nekogram.NekoConfig; import tw.nekomimi.nekogram.NekoXConfig; import tw.nekomimi.nekogram.parts.MessageTransKt; import tw.nekomimi.nekogram.parts.PollTransUpdatesKt; import tw.nekomimi.nekogram.settings.NekoSettingsActivity; import tw.nekomimi.nekogram.transtale.Translator; +import tw.nekomimi.nekogram.ui.BottomBuilder; +import tw.nekomimi.nekogram.ui.MessageDetailsActivity; import tw.nekomimi.nekogram.utils.AlertUtil; +import tw.nekomimi.nekogram.utils.EnvUtil; import tw.nekomimi.nekogram.utils.PGPUtil; import tw.nekomimi.nekogram.utils.ProxyUtil; import tw.nekomimi.nekogram.utils.TelegramUtil; -import xyz.nextalone.nagram.DoubleTapConfig; import xyz.nextalone.nagram.NaConfig; +import xyz.nextalone.nagram.helper.DoubleTap; @SuppressWarnings("unchecked") public class ChatActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate, LocationActivity.LocationActivityDelegate, ChatAttachAlertDocumentLayout.DocumentSelectActivityDelegate { @@ -330,7 +329,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not private final static int nkbtn_deldlcache = 2013; private final static int nkbtn_view_history = 2014; private final static int nkbtn_repeat = 2015; - private final static int nkbtn_repeatascopy = 2025; + private final static int nkbtn_repeatascopy = 2027; private final static int nkbtn_stickerdl = 2016; private final static int nkbtn_unpin = 2017; private final static int nkbtn_view_in_chat = 2018; @@ -1502,10 +1501,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not public boolean hasDoubleTap(View view, int position) { boolean allowRepeat; - if (NaConfig.INSTANCE.getDoubleTapAction().Int() == DoubleTapConifig.DOUBLE_TAP_ACTION_NONE || !(view instanceof ChatMessageCell)) { + if (NaConfig.INSTANCE.getDoubleTapAction().Int() == DoubleTap.DOUBLE_TAP_ACTION_NONE || !(view instanceof ChatMessageCell)) { return false; } - if (NaConfig.INSTANCE.getDoubleTapAction().Int() == DoubleTapConfig.DOUBLE_TAP_ACTION_REACTION) { + if (NaConfig.INSTANCE.getDoubleTapAction().Int() == DoubleTap.DOUBLE_TAP_ACTION_REACTION) { TLRPC.TL_availableReaction reaction = getMediaDataController().getReactionsMap().get(getMediaDataController().getDoubleTapReaction()); if (reaction == null) { return false; @@ -1560,21 +1559,21 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not break; */ - case DoubleTapConfig.DOUBLE_TAP_ACTION_REPLY: + case DoubleTap.DOUBLE_TAP_ACTION_REPLY: return message.getId() > 0 && allowChatActions; - case DoubleTapConfig.DOUBLE_TAP_ACTION_SAVE: + 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); - case DoubleTapConfig.DOUBLE_TAP_ACTION_REPEAT: + case DoubleTap.DOUBLE_TAP_ACTION_REPEAT: allowRepeat = allowChatActions && (!isThreadChat() && !noforwards || getMessageHelper().getMessageForRepeat(message, messageGroup) != null); return allowRepeat && !message.isSponsored() && chatMode != MODE_SCHEDULED && !message.needDrawBluredPreview() && !message.isLiveLocation() && message.type != 16; - case DoubleTapConfig.DOUBLE_TAP_ACTION_REPEATASCOPY: + case DoubleTap.DOUBLE_TAP_ACTION_REPEAT_AS_COPY: allowRepeat = allowChatActions && (!isThreadChat() && !noforwards || getMessageHelper().getMessageForRepeat(message, messageGroup) != null); return allowRepeat && !message.isSponsored() && chatMode != MODE_SCHEDULED && !message.needDrawBluredPreview() && !message.isLiveLocation() && message.type != 16; - case DoubleTapConfig.DOUBLE_TAP_ACTION_EDIT: + case DoubleTap.DOUBLE_TAP_ACTION_EDIT: return allowEdit; } } @@ -3185,10 +3184,12 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not actionModeOtherItem.addSubItem(nkbtn_unpin, R.drawable.msg_unpin, LocaleController.getString("UnpinMessage", R.string.UnpinMessage)); if (!noforward) actionModeOtherItem.addSubItem(nkbtn_savemessage, R.drawable.menu_saved, LocaleController.getString("AddToSavedMessages", R.string.AddToSavedMessages)); - if (NekoConfig.showRepeat.Bool() && !noforward) + if (NekoConfig.showRepeat.Bool() && !noforward) { actionModeOtherItem.addSubItem(nkbtn_repeat, R.drawable.msg_repeat, LocaleController.getString("Repeat", R.string.Repeat)); - if(NekoConfig.showRepeatasCopy.Bool() && !noforward) - actionModeOtherItem.addSubItem(nkbtn_repeat, R.drawable.msg_repeat, LocaleController.getString("RepeatasCopy", R.string.Repeat)); + } + if (NaConfig.INSTANCE.getShowRepeatAsCopy().Bool() && !noforward) { + actionModeOtherItem.addSubItem(nkbtn_repeatascopy, R.drawable.msg_repeat, LocaleController.getString("RepeatAsCopy", R.string.RepeatAsCopy)); + } if (NekoConfig.showMessageHide.Bool()) { actionModeOtherItem.addSubItem(nkbtn_hide, R.drawable.baseline_remove_circle_24, LocaleController.getString("Hide", R.string.Hide)); } @@ -22100,16 +22101,16 @@ 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()) { + if (!noforward) { 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)); + 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)); + } else { + items.add(LocaleController.getString("RepeatAsCopy", R.string.RepeatAsCopy)); options.add(nkbtn_repeatascopy); icons.add(R.drawable.msg_repeat); } diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java index 5de04296a..33db67530 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java @@ -69,7 +69,6 @@ public class NekoConfig { public static ConfigItem showMessageDetails = addConfig("showMessageDetails", configTypeBool, false); public static ConfigItem showTranslate = addConfig("showTranslate", configTypeBool, true); public static ConfigItem showRepeat = addConfig("showRepeat", configTypeBool, false); - public static ConfigItem showRepeatasCopy = addConfig("showRepeatasCopy",configTypeBool,false); public static ConfigItem showShareMessages = addConfig("showShareMessages", configTypeBool, false); public static ConfigItem showMessageHide = addConfig("showMessageHide", configTypeBool, false); @@ -290,8 +289,6 @@ public class NekoConfig { showTranslate.setConfigBool(preferences.getBoolean("showTranslate", true)); if (preferences.contains("showRepeat")) showRepeat.setConfigBool(preferences.getBoolean("showRepeat", false)); - if (preferences.contains("showRepeatasCopy")) - showRepeatasCopy.setConfigBool(preferences.getBoolean("showRepeatasCopy",false)); if (preferences.contains("showShareMessages")) showShareMessages.setConfigBool(preferences.getBoolean("showShareMessages", false)); if (preferences.contains("showMessageHide")) 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 893fb827a..11311752f 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java @@ -45,10 +45,9 @@ import java.util.List; import java.util.stream.Collectors; import kotlin.Unit; -import tw.nekomimi.nekogram.NekoXConfig; -import tw.nekomimi.nekogram.ui.PopupBuilder; -import tw.nekomimi.nekogram.config.CellGroup; import tw.nekomimi.nekogram.NekoConfig; +import tw.nekomimi.nekogram.NekoXConfig; +import tw.nekomimi.nekogram.config.CellGroup; import tw.nekomimi.nekogram.config.cell.AbstractConfigCell; import tw.nekomimi.nekogram.config.cell.ConfigCellCustom; import tw.nekomimi.nekogram.config.cell.ConfigCellDivider; @@ -57,8 +56,9 @@ import tw.nekomimi.nekogram.config.cell.ConfigCellSelectBox; import tw.nekomimi.nekogram.config.cell.ConfigCellTextCheck; import tw.nekomimi.nekogram.config.cell.ConfigCellTextDetail; import tw.nekomimi.nekogram.config.cell.ConfigCellTextInput; -import xyz.nextalone.nagram.DoubleTapConfig; +import tw.nekomimi.nekogram.ui.PopupBuilder; import xyz.nextalone.nagram.NaConfig; +import xyz.nextalone.nagram.helper.DoubleTap; @SuppressLint("RtlHardcoded") public class NekoChatSettingsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate { @@ -238,27 +238,27 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati return Unit.INSTANCE; }); builder.show(); - }else if (position == cellGroup.rows.indexOf(DoubleTapActionRow)) { + } else if (position == cellGroup.rows.indexOf(DoubleTapActionRow)) { ArrayList arrayList = new ArrayList<>(); ArrayList types = new ArrayList<>(); arrayList.add(LocaleController.getString("Disable", R.string.Disable)); - types.add(DoubleTapConfig.DOUBLE_TAP_ACTION_NONE); + types.add(DoubleTap.DOUBLE_TAP_ACTION_NONE); arrayList.add(LocaleController.getString("Reactions", R.string.Reactions)); - types.add(DoubleTapConfig.DOUBLE_TAP_ACTION_REACTION); + 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("Reply", R.string.Reply)); - types.add(DoubleTapConfig.DOUBLE_TAP_ACTION_REPLY); + types.add(DoubleTap.DOUBLE_TAP_ACTION_REPLY); arrayList.add(LocaleController.getString("AddToSavedMessages", R.string.AddToSavedMessages)); - types.add(DoubleTapConfig.DOUBLE_TAP_ACTION_SAVE); + types.add(DoubleTap.DOUBLE_TAP_ACTION_SAVE); arrayList.add(LocaleController.getString("Repeat", R.string.Repeat)); - types.add(DoubleTapConfig.DOUBLE_TAP_ACTION_REPEAT); - arrayList.add(LocaleController.getString("RepeatasCopy", R.string.RepeatasCopy)); - types.add(DoubleTapConfig.DOUBLE_TAP_ACTION_REPEATASCOPY); + types.add(DoubleTap.DOUBLE_TAP_ACTION_REPEAT); + arrayList.add(LocaleController.getString("RepeatAsCopy", R.string.RepeatAsCopy)); + types.add(DoubleTap.DOUBLE_TAP_ACTION_REPEAT_AS_COPY); arrayList.add(LocaleController.getString("Edit", R.string.Edit)); - types.add(DoubleTapConfig.DOUBLE_TAP_ACTION_EDIT); + types.add(DoubleTap.DOUBLE_TAP_ACTION_EDIT); PopupBuilder builder = new PopupBuilder(view); - builder.setItems(arrayList, (i,str) -> { + builder.setItems(arrayList, (i, str) -> { NaConfig.INSTANCE.getDoubleTapAction().setConfigInt(types.get(i)); listAdapter.notifyItemChanged(position); return Unit.INSTANCE; @@ -379,7 +379,7 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati break; } case 3: { - textCell.setChecked(NekoConfig.showRepeatasCopy.toggleConfigBool()); + textCell.setTextAndCheck(LocaleController.getString("RepeatAsCopy", R.string.RepeatAsCopy), NaConfig.INSTANCE.getShowRepeatAsCopy().Bool(), false); break; } case 4: { @@ -442,7 +442,7 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati break; } case 3: { - textCell.setChecked(NekoConfig.showRepeatasCopy.toggleConfigBool()); + textCell.setChecked(NaConfig.INSTANCE.getShowRepeatAsCopy().toggleConfigBool()); break; } case 4: { @@ -723,8 +723,8 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati TextSettingsCell textCell = (TextSettingsCell) holder.itemView; if (position == cellGroup.rows.indexOf(maxRecentStickerCountRow)) { textCell.setTextAndValue(LocaleController.getString("maxRecentStickerCount", R.string.maxRecentStickerCount), String.valueOf(NekoConfig.maxRecentStickerCount.Int()), true); - }else if ( position == cellGroup.rows.indexOf(DoubleTapActionRow)) { - textCell.setTextAndValue(LocaleController.getString("DoubleTapAction", R.string.DoubleTapAction), new DoubleTapConfig().doubleTapActionMap.get(NaConfig.INSTANCE.getDoubleTapAction().Int()), true); + } else if (position == cellGroup.rows.indexOf(DoubleTapActionRow)) { + textCell.setTextAndValue(LocaleController.getString("DoubleTapAction", R.string.DoubleTapAction), DoubleTap.doubleTapActionMap.get(NaConfig.INSTANCE.getDoubleTapAction().Int()), true); } } } else { diff --git a/TMessagesProj/src/main/java/xyz/nextalone/nagram/DoubleTapConfig.java b/TMessagesProj/src/main/java/xyz/nextalone/nagram/DoubleTapConfig.java deleted file mode 100644 index 0bfc2483b..000000000 --- a/TMessagesProj/src/main/java/xyz/nextalone/nagram/DoubleTapConfig.java +++ /dev/null @@ -1,31 +0,0 @@ -package xyz.nextalone.nagram; - -import org.telegram.messenger.LocaleController; -import org.telegram.messenger.R; - -import java.util.HashMap; -import java.util.Map; - -public class DoubleTapConfig { - public static final int DOUBLE_TAP_ACTION_NONE = 0; - public static final int DOUBLE_TAP_ACTION_REACTION = 1; - //public static final int DOUBLE_TAP_ACTION_TRANSLATE = 2; - public static final int DOUBLE_TAP_ACTION_REPLY = 2; - public static final int DOUBLE_TAP_ACTION_SAVE = 3; - public static final int DOUBLE_TAP_ACTION_REPEAT = 4; - public static final int DOUBLE_TAP_ACTION_REPEATASCOPY = 5; - public static final int DOUBLE_TAP_ACTION_EDIT = 6; - - public Map doubleTapActionMap = new HashMap<>(); - - public DoubleTapConfig() { - doubleTapActionMap.put(DOUBLE_TAP_ACTION_NONE, LocaleController.getString("Disable", R.string.Disable)); - doubleTapActionMap.put(DOUBLE_TAP_ACTION_REACTION, LocaleController.getString("Reactions", R.string.Reactions)); - //doubleTapActionMap.put(DOUBLE_TAP_ACTION_TRANSLATE, LocaleController.getString("Translate", R.string.Translate)); - doubleTapActionMap.put(DOUBLE_TAP_ACTION_REPLY, LocaleController.getString("Reply", R.string.Reply)); - doubleTapActionMap.put(DOUBLE_TAP_ACTION_SAVE, LocaleController.getString("Save", R.string.Save)); - doubleTapActionMap.put(DOUBLE_TAP_ACTION_REPEAT, LocaleController.getString("Repeat", R.string.Repeat)); - doubleTapActionMap.put(DOUBLE_TAP_ACTION_REPEATASCOPY, LocaleController.getString("RepeatasCopy", R.string.RepeatasCopy)); - doubleTapActionMap.put(DOUBLE_TAP_ACTION_EDIT, LocaleController.getString("Edit", R.string.Edit)); - } -} diff --git a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt index 55d1ba3e7..b552c9efb 100644 --- a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt +++ b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt @@ -115,7 +115,13 @@ object NaConfig { ConfigItem.configTypeBool, false ) - var DoubleTapAction = + val showRepeatAsCopy = + addConfig( + "RepeatAsCopy", + ConfigItem.configTypeBool, + false + ) + var doubleTapAction = addConfig( "DoubleTapAction", ConfigItem.configTypeInt, diff --git a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/DoubleTap.kt b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/DoubleTap.kt new file mode 100644 index 000000000..934da37c4 --- /dev/null +++ b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/DoubleTap.kt @@ -0,0 +1,69 @@ +package xyz.nextalone.nagram.helper + +import org.telegram.messenger.LocaleController +import org.telegram.messenger.R + +object DoubleTap { + @JvmField + var doubleTapActionMap: MutableMap = + HashMap() + const val DOUBLE_TAP_ACTION_NONE = + 0 + const val DOUBLE_TAP_ACTION_REACTION = + 1 +// const val DOUBLE_TAP_ACTION_TRANSLATE = +// 2 + const val DOUBLE_TAP_ACTION_REPLY = + 2 + const val DOUBLE_TAP_ACTION_SAVE = + 3 + const val DOUBLE_TAP_ACTION_REPEAT = + 4 + const val DOUBLE_TAP_ACTION_REPEAT_AS_COPY = + 5 + const val DOUBLE_TAP_ACTION_EDIT = + 6 + + init { + doubleTapActionMap[DOUBLE_TAP_ACTION_NONE] = + LocaleController.getString( + "Disable", + R.string.Disable + ) + doubleTapActionMap[DOUBLE_TAP_ACTION_REACTION] = + LocaleController.getString( + "Reactions", + R.string.Reactions + ) +// doubleTapActionMap[DOUBLE_TAP_ACTION_TRANSLATE] = +// LocaleController.getString( +// "Translate", +// R.string.Translate +// ) + doubleTapActionMap[DOUBLE_TAP_ACTION_REPLY] = + LocaleController.getString( + "Reply", + R.string.Reply + ) + doubleTapActionMap[DOUBLE_TAP_ACTION_SAVE] = + LocaleController.getString( + "Save", + R.string.Save + ) + doubleTapActionMap[DOUBLE_TAP_ACTION_REPEAT] = + LocaleController.getString( + "Repeat", + R.string.Repeat + ) + doubleTapActionMap[DOUBLE_TAP_ACTION_REPEAT_AS_COPY] = + LocaleController.getString( + "RepeatAsCopy", + R.string.RepeatAsCopy + ) + doubleTapActionMap[DOUBLE_TAP_ACTION_EDIT] = + LocaleController.getString( + "Edit", + R.string.Edit + ) + } +} \ No newline at end of file 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 b6065bfd6..7e264fc07 100644 --- a/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml +++ b/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml @@ -14,6 +14,6 @@ 撤销 重做 噪音抑制和语音增强 - 无引用复读 - + 无引用复读 + 双击操作 diff --git a/TMessagesProj/src/main/res/values/strings_na.xml b/TMessagesProj/src/main/res/values/strings_na.xml index 87538258d..fbc7a0800 100644 --- a/TMessagesProj/src/main/res/values/strings_na.xml +++ b/TMessagesProj/src/main/res/values/strings_na.xml @@ -14,6 +14,6 @@ Undo Redo Noise Suppress And Voice Enhance - Repeat as Copy + Repeat as Copy Double Tap Action