From 52c4e0ccacd15f7e8ef973d3d5faea4d9e381467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 18 Dec 2020 02:29:42 +0800 Subject: [PATCH] Fix convert --- .../ui/Components/ChatActivityEnterView.java | 18 +++++++++++++----- .../java/tw/nekomimi/nekogram/NekoConfig.java | 4 ++-- .../java/tw/nekomimi/nekogram/PopupBuilder.kt | 11 +++++------ .../nekomimi/nekogram/transtale/Translator.kt | 5 +++-- 4 files changed, 23 insertions(+), 15 deletions(-) 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 98cc39617..55b0bd728 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java @@ -150,6 +150,7 @@ import tw.nekomimi.nekogram.transtale.Translator; import tw.nekomimi.nekogram.transtale.TranslatorKt; import tw.nekomimi.nekogram.utils.AlertUtil; import tw.nekomimi.nekogram.utils.PGPUtil; +import tw.nekomimi.nekogram.utils.UIUtil; public class ChatActivityEnterView extends FrameLayout implements NotificationCenter.NotificationCenterDelegate, SizeNotifierFrameLayout.SizeNotifierFrameLayoutDelegate, StickersAlert.StickersAlertDelegate { @@ -3252,9 +3253,6 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe cell.setTextAndIcon(LocaleController.getString("Translate", R.string.OpenCC), R.drawable.ic_translate); ActionBarMenuSubItem finalCell1 = cell; cell.setOnClickListener(v -> { - if (menuPopupWindow != null && menuPopupWindow.isShowing()) { - menuPopupWindow.dismiss(); - } String ccTarget = TranslateDb.getChatCCTarget(chatId, NekoConfig.ccInputLang); if (ccTarget == null || StringsKt.isBlank(ccTarget)) { Translator.showCCTargetSelect(finalCell1, (target) -> { @@ -3267,6 +3265,9 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe }); return; } + if (menuPopupWindow != null && menuPopupWindow.isShowing()) { + menuPopupWindow.dismiss(); + } ccComment(ccTarget); }); cell.setOnLongClickListener(v -> { @@ -3602,8 +3603,15 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe private void ccComment(String target) { String text = messageEditText.getText().toString(); - text = CCConverter.get(CCTarget.valueOf(target)).convert(text); - messageEditText.setText(text); + AlertDialog progress = AlertUtil.showProgress(parentActivity); + progress.show(); + UIUtil.runOnIoDispatcher(() -> { + String ccText = CCConverter.get(CCTarget.valueOf(target)).convert(text); + UIUtil.runOnUIThread(() -> { + progress.dismiss(); + messageEditText.setText(ccText); + }); + }); } public boolean isSendButtonVisible() { diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java index ac9d89ff9..e960cfa2c 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java @@ -235,8 +235,8 @@ public class NekoConfig { translateToLang = preferences.getString("trans_to_lang", null); translateInputLang = preferences.getString("trans_input_to_lang", "en"); - translateToLang = preferences.getString("opencc_to_lang", null); - translateInputLang = preferences.getString("opencc_input_to_lang", null); + ccToLang = preferences.getString("opencc_to_lang", null); + ccInputLang = preferences.getString("opencc_input_to_lang", null); tabsTitleType = preferences.getInt("tabsTitleType", TITLE_TYPE_TEXT); confirmAVMessage = preferences.getBoolean("confirmAVMessage", false); diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/PopupBuilder.kt b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/PopupBuilder.kt index df69f80bd..54a1bd7c6 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/PopupBuilder.kt +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/PopupBuilder.kt @@ -18,19 +18,18 @@ class PopupBuilder @JvmOverloads constructor(anchor: View, dialog: Boolean = fal } - fun setItems(items: Array, listener: (Int,CharSequence) -> Unit) { + fun setItems(items: Array, listener: (Int, CharSequence) -> Unit) { removeAllSubItems() - items.forEachIndexed { i, v -> - - addSubItem(i, v) - + for (item in items) { + if (item == null) continue + addSubItem(items.indexOf(item), item) } setDelegate { - listener(it,items[it]) + listener(it, items[it]!!) } diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/Translator.kt b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/Translator.kt index 129ae63bb..dc3f1dbb5 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/Translator.kt +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/Translator.kt @@ -172,12 +172,13 @@ interface Translator { } @JvmStatic - fun showCCTargetSelect(anchor: View, callback: (String) -> Unit) { + @JvmOverloads + fun showCCTargetSelect(anchor: View, input: Boolean = true, callback: (String) -> Unit) { val builder = PopupBuilder(anchor) builder.setItems(arrayOf( - LocaleController.getString("CCNo", R.string.CCNo), + if (!input) LocaleController.getString("CCNo", R.string.CCNo) else null, LocaleController.getString("CCSC", R.string.CCSC), LocaleController.getString("CCSP", R.string.CCSP), LocaleController.getString("CCTC", R.string.CCTC),