From 63db0d19a192da97c027b894daeb0d1174699768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E5=A4=A9=E5=A4=A9?= <61044187+ruattd@users.noreply.github.com> Date: Fri, 9 Feb 2024 08:14:42 +0800 Subject: [PATCH] feat: option for disabling markdown (#34) --- .../ui/Components/ChatActivityEnterView.java | 19 ++++++++++++++----- .../settings/NekoChatSettingsActivity.java | 1 + .../kotlin/xyz/nextalone/nagram/NaConfig.kt | 6 ++++++ .../main/res/drawable/round_code_white.xml | 5 +++++ .../src/main/res/values-zh-rCN/strings_na.xml | 2 ++ .../src/main/res/values/strings_na.xml | 2 ++ 6 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 TMessagesProj/src/main/res/drawable/round_code_white.xml diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java index 8e43bb7441..50305ff8b4 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java @@ -4607,14 +4607,19 @@ public void didSelectDate(boolean notify, int scheduleDate) { } if (sendWithoutSoundButtonValue) { if (containsMarkdown(messageEditText.getText())) { + boolean withoutMarkdown = NaConfig.INSTANCE.getDisableMarkdown().Bool(); ActionBarMenuSubItem sendWithoutMarkdownButton = new ActionBarMenuSubItem(getContext(), false, false, resourcesProvider); - sendWithoutMarkdownButton.setTextAndIcon(LocaleController.getString("SendWithoutMarkdown", R.string.SendWithoutMarkdown), R.drawable.round_code_off_white); + if (withoutMarkdown) { + sendWithoutMarkdownButton.setTextAndIcon(LocaleController.getString("SendWithMarkdown", R.string.SendWithMarkdown), R.drawable.round_code_white); + } else { + sendWithoutMarkdownButton.setTextAndIcon(LocaleController.getString("SendWithoutMarkdown", R.string.SendWithoutMarkdown), R.drawable.round_code_off_white); + } sendWithoutMarkdownButton.setMinimumWidth(AndroidUtilities.dp(196)); sendWithoutMarkdownButton.setOnClickListener(v -> { if (sendPopupWindow != null && sendPopupWindow.isShowing()) { sendPopupWindow.dismiss(); } - sendMessageInternal(true, 0, true, false, true); + sendMessageInternal(true, 0, true, withoutMarkdown, true); }); sendPopupLayout.addView(sendWithoutMarkdownButton, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48)); } else if (canSendAsDice(messageEditText.getText().toString(), parentFragment, dialog_id)) { @@ -4625,7 +4630,7 @@ public void didSelectDate(boolean notify, int scheduleDate) { if (sendPopupWindow != null && sendPopupWindow.isShowing()) { sendPopupWindow.dismiss(); } - sendMessageInternal(true, 0, true, true, false); + sendMessageInternal(true, 0, true, null, false); }); sendPopupLayout.addView(sendWithoutMarkdownButton, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48)); } @@ -7024,10 +7029,14 @@ public void didSelectDate(boolean notify, int scheduleDate) { private boolean premiumEmojiBulletin = true; private void sendMessageInternal(boolean notify, int scheduleDate, boolean allowConfirm) { - sendMessageInternal(notify, scheduleDate, allowConfirm, true, true); + sendMessageInternal(notify, scheduleDate, allowConfirm, null, true); } - private void sendMessageInternal(boolean notify, int scheduleDate, boolean allowConfirm, boolean withMarkdown, boolean withGame) { + private void sendMessageInternal(boolean notify, int scheduleDate, boolean allowConfirm, Boolean withMarkdown, boolean withGame) { + boolean disableMarkdown = NaConfig.INSTANCE.getDisableMarkdown().Bool(); + if (withMarkdown == null) { + withMarkdown = !disableMarkdown; + } if (slowModeTimer == Integer.MAX_VALUE && !isInScheduleMode()) { if (delegate != null) { delegate.scrollToSendingMessage(); 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 3f54197c1f..b5d46eb803 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java @@ -150,6 +150,7 @@ public class NekoChatSettingsActivity extends BaseNekoXSettingsActivity implemen private final AbstractConfigCell showSendAsUnderMessageHintRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowSendAsUnderMessageHint())); private final AbstractConfigCell hideBotButtonInInputFieldRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getHideBotButtonInInputField())); private final AbstractConfigCell doNotUnarchiveBySwipeRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getDoNotUnarchiveBySwipe())); + private final AbstractConfigCell disableMarkdownRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisableMarkdown())); private final AbstractConfigCell dividerInteractions = cellGroup.appendCell(new ConfigCellDivider()); // Sticker diff --git a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt index 7388aa6c84..f2ee0653d3 100644 --- a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt +++ b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt @@ -500,6 +500,12 @@ object NaConfig { ConfigItem.configTypeInt, 0 ) + val disableMarkdown = + addConfig( + "DisableMarkdown", + ConfigItem.configTypeBool, + false + ) private fun addConfig( k: String, diff --git a/TMessagesProj/src/main/res/drawable/round_code_white.xml b/TMessagesProj/src/main/res/drawable/round_code_white.xml new file mode 100644 index 0000000000..f6ae313d91 --- /dev/null +++ b/TMessagesProj/src/main/res/drawable/round_code_white.xml @@ -0,0 +1,5 @@ + + + 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 aa13a45d46..9d460f60c3 100644 --- a/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml +++ b/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml @@ -107,4 +107,6 @@ 删除所有缓存 目录命名方式 腾讯交互翻译 + 禁用 Markdown + 启用 Markdown diff --git a/TMessagesProj/src/main/res/values/strings_na.xml b/TMessagesProj/src/main/res/values/strings_na.xml index af9437dbe1..0ff5349b81 100644 --- a/TMessagesProj/src/main/res/values/strings_na.xml +++ b/TMessagesProj/src/main/res/values/strings_na.xml @@ -110,4 +110,6 @@ Delete all caches Directory naming TranSmart Translator + Disable Markdown + Send with markdown