feat: option to use telegram official translateAlert in chat

This commit is contained in:
luvletter2333 2023-01-21 19:03:45 +08:00
parent 12bbf436a1
commit adcafbfc6d
No known key found for this signature in database
GPG Key ID: A26A8880836E1978
7 changed files with 25 additions and 1827 deletions

View File

@ -282,6 +282,7 @@ import org.telegram.ui.Components.TextSelectionHint;
import org.telegram.ui.Components.TextStyleSpan;
import org.telegram.ui.Components.ThemeEditorView;
import org.telegram.ui.Components.TranscribeButton;
import org.telegram.ui.Components.TranslateAlert;
import org.telegram.ui.Components.TrendingStickersAlert;
import org.telegram.ui.Components.TypefaceSpan;
import org.telegram.ui.Components.URLSpanBotCommand;
@ -24562,7 +24563,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
processSelectedOption(options.get(i));
});
if (option == OPTION_TRANSLATE) {
// NekoX: Official Translation Removed
// NekoX: Official Translation Move to neko_btn_translate
}
cell.setOnLongClickListener(v1 -> {
if (selectedObject == null || i < 0 || i >= options.size()) {
@ -26009,7 +26010,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
private int processSelectedOptionLongClick(ActionBarMenuSubItem cell, int option) {
switch (option) {
case nkbtn_translate: {
ChatMessageCell messageCell = null;
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
@ -26024,27 +26024,19 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
if (selectedObject.messageOwner.translated) {
return 0;
}
Translator.showTargetLangSelect(cell, (locale) -> {
if (scrimPopupWindow != null) {
scrimPopupWindow.dismiss();
scrimPopupWindow = null;
scrimPopupWindowItems = null;
}
MessageTransKt.translateMessages(this, locale);
return Unit.INSTANCE;
});
return 1;
}
case nkbtn_repeat: {
repeatMessage(true);
@ -32070,7 +32062,21 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
break;
}
case nkbtn_translate: {
MessageTransKt.translateMessages(this);
if (NekoConfig.useTelegramTranslateInChat.Bool()) {
String toLang = LocaleController.getInstance().getCurrentLocale().getLanguage();
int[] messageIdToTranslate = new int[] { selectedObject.getId() };
final CharSequence finalMessageText = getMessageCaption(selectedObject, selectedObjectGroup, messageIdToTranslate);
TranslateAlert.OnLinkPress onLinkPress = (link) -> {
didPressMessageUrl(link, false, selectedObject, null);
return true;
};
TLRPC.InputPeer inputPeer = selectedObject != null && (selectedObject.isPoll() || selectedObject.isVoiceTranscriptionOpen() || selectedObject.isSponsored()) ? null : getMessagesController().getInputPeer(dialog_id);
TranslateAlert alert = TranslateAlert.showAlert(getParentActivity(), this, currentAccount, inputPeer, messageIdToTranslate[0], "und", toLang, finalMessageText, false, onLinkPress, () -> dimBehindView(false));
alert.showDim(false);
closeMenu(false);
} else {
MessageTransKt.translateMessages(this);
}
break;
}
case nkbtn_detail: {

View File

@ -70,7 +70,7 @@ import java.util.ArrayList;
public class TranslateAlert extends Dialog {
public static volatile DispatchQueue translateQueue = new DispatchQueue("translateQueue", false);
// public static volatile DispatchQueue translateQueue = new DispatchQueue("translateQueue", false);
private FrameLayout bulletinContainer;
private FrameLayout contentView;

View File

@ -79,7 +79,6 @@ public class NekoConfig {
public static ConfigItem stickerSize = addConfig("stickerSize", configTypeFloat, 14.0f);
public static ConfigItem unlimitedFavedStickers = addConfig("UnlimitedFavoredStickers", configTypeBool, false);
public static ConfigItem unlimitedPinnedDialogs = addConfig("UnlimitedPinnedDialogs", configTypeBool, false);
public static ConfigItem translationProvider = addConfig("translationProvider", configTypeInt, 1);
public static ConfigItem disablePhotoSideAction = addConfig("DisablePhotoViewerSideAction", configTypeBool, false);
public static ConfigItem openArchiveOnPull = addConfig("OpenArchiveOnPull", configTypeBool, false);
public static ConfigItem hideKeyboardOnChatScroll = addConfig("HideKeyboardOnChatScroll", configTypeBool, false);
@ -117,12 +116,15 @@ public class NekoConfig {
// public static ConfigItem useDefaultTheme = addConfig("UseDefaultTheme", configTypeBool, false);
public static ConfigItem showIdAndDc = addConfig("ShowIdAndDc", configTypeBool, false);
public static ConfigItem googleCloudTranslateKey = addConfig("GoogleCloudTransKey", configTypeString, "");
public static ConfigItem cachePath = addConfig("cache_path", configTypeString, "");
public static ConfigItem customSavePath = addConfig("customSavePath", configTypeString, "NekoX");
public static ConfigItem translationProvider = addConfig("translationProvider", configTypeInt, 1);
public static ConfigItem translateToLang = addConfig("TransToLang", configTypeString, ""); // "" -> translate to current language (MessageTrans.kt & Translator.kt)
public static ConfigItem translateInputLang = addConfig("TransInputToLang", configTypeString, "en");
public static ConfigItem useTelegramTranslateInChat = addConfig("useTelegramTranslateInChat", configTypeBool, false);
public static ConfigItem googleCloudTranslateKey = addConfig("GoogleCloudTransKey", configTypeString, "");
public static ConfigItem disableNotificationBubbles = addConfig("disableNotificationBubbles", configTypeBool, false);

View File

@ -95,6 +95,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
private final AbstractConfigCell headerTranslation = cellGroup.appendCell(new ConfigCellHeader(LocaleController.getString("Translate")));
private final AbstractConfigCell translationProviderRow = cellGroup.appendCell(new ConfigCellCustom(CellGroup.ITEM_TYPE_TEXT_SETTINGS_CELL, true));
private final AbstractConfigCell useTelegramTranslateInChatRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.useTelegramTranslateInChat));
private final AbstractConfigCell translateToLangRow = cellGroup.appendCell(new ConfigCellCustom(CellGroup.ITEM_TYPE_TEXT_SETTINGS_CELL, true));
private final AbstractConfigCell translateInputToLangRow = cellGroup.appendCell(new ConfigCellCustom(CellGroup.ITEM_TYPE_TEXT_SETTINGS_CELL, true));
private final AbstractConfigCell googleCloudTranslateKeyRow = cellGroup.appendCell(new ConfigCellTextDetail(NekoConfig.googleCloudTranslateKey, (view, position) -> {

View File

@ -149,4 +149,5 @@
<string name="enhancedFileLoader">加速下载</string>
<string name="useOSMDroidMap">使用 OSMDroid 地图</string>
<string name="mapDriftingFixForGoogleMaps">修复 Google 地图在中国的漂移问题</string>
<string name="useTelegramTranslateInChat">在聊天中使用 Telegram 官方翻译</string>
</resources>

View File

@ -147,4 +147,5 @@
<string name="enhancedFileLoader">Enhance Download speed</string>
<string name="mapDriftingFixForGoogleMaps">Fix Google Maps drifting in China</string>
<string name="useOSMDroidMap">Use OSMDroid Map</string>
<string name="useTelegramTranslateInChat">Use Telegram Translate in Chat</string>
</resources>