mirror of https://github.com/NekoX-Dev/NekoX.git
feat: option to use telegram official translateAlert in chat
This commit is contained in:
parent
12bbf436a1
commit
adcafbfc6d
|
@ -282,6 +282,7 @@ import org.telegram.ui.Components.TextSelectionHint;
|
||||||
import org.telegram.ui.Components.TextStyleSpan;
|
import org.telegram.ui.Components.TextStyleSpan;
|
||||||
import org.telegram.ui.Components.ThemeEditorView;
|
import org.telegram.ui.Components.ThemeEditorView;
|
||||||
import org.telegram.ui.Components.TranscribeButton;
|
import org.telegram.ui.Components.TranscribeButton;
|
||||||
|
import org.telegram.ui.Components.TranslateAlert;
|
||||||
import org.telegram.ui.Components.TrendingStickersAlert;
|
import org.telegram.ui.Components.TrendingStickersAlert;
|
||||||
import org.telegram.ui.Components.TypefaceSpan;
|
import org.telegram.ui.Components.TypefaceSpan;
|
||||||
import org.telegram.ui.Components.URLSpanBotCommand;
|
import org.telegram.ui.Components.URLSpanBotCommand;
|
||||||
|
@ -24562,7 +24563,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||||
processSelectedOption(options.get(i));
|
processSelectedOption(options.get(i));
|
||||||
});
|
});
|
||||||
if (option == OPTION_TRANSLATE) {
|
if (option == OPTION_TRANSLATE) {
|
||||||
// NekoX: Official Translation Removed
|
// NekoX: Official Translation Move to neko_btn_translate
|
||||||
}
|
}
|
||||||
cell.setOnLongClickListener(v1 -> {
|
cell.setOnLongClickListener(v1 -> {
|
||||||
if (selectedObject == null || i < 0 || i >= options.size()) {
|
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) {
|
private int processSelectedOptionLongClick(ActionBarMenuSubItem cell, int option) {
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case nkbtn_translate: {
|
case nkbtn_translate: {
|
||||||
|
|
||||||
ChatMessageCell messageCell = null;
|
ChatMessageCell messageCell = null;
|
||||||
int count = chatListView.getChildCount();
|
int count = chatListView.getChildCount();
|
||||||
for (int a = 0; a < count; a++) {
|
for (int a = 0; a < count; a++) {
|
||||||
|
@ -26024,27 +26024,19 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedObject.messageOwner.translated) {
|
if (selectedObject.messageOwner.translated) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Translator.showTargetLangSelect(cell, (locale) -> {
|
Translator.showTargetLangSelect(cell, (locale) -> {
|
||||||
|
|
||||||
if (scrimPopupWindow != null) {
|
if (scrimPopupWindow != null) {
|
||||||
scrimPopupWindow.dismiss();
|
scrimPopupWindow.dismiss();
|
||||||
scrimPopupWindow = null;
|
scrimPopupWindow = null;
|
||||||
scrimPopupWindowItems = null;
|
scrimPopupWindowItems = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageTransKt.translateMessages(this, locale);
|
MessageTransKt.translateMessages(this, locale);
|
||||||
|
|
||||||
return Unit.INSTANCE;
|
return Unit.INSTANCE;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
case nkbtn_repeat: {
|
case nkbtn_repeat: {
|
||||||
repeatMessage(true);
|
repeatMessage(true);
|
||||||
|
@ -32070,7 +32062,21 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case nkbtn_translate: {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case nkbtn_detail: {
|
case nkbtn_detail: {
|
||||||
|
|
|
@ -70,7 +70,7 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
public class TranslateAlert extends Dialog {
|
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 bulletinContainer;
|
||||||
private FrameLayout contentView;
|
private FrameLayout contentView;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -79,7 +79,6 @@ public class NekoConfig {
|
||||||
public static ConfigItem stickerSize = addConfig("stickerSize", configTypeFloat, 14.0f);
|
public static ConfigItem stickerSize = addConfig("stickerSize", configTypeFloat, 14.0f);
|
||||||
public static ConfigItem unlimitedFavedStickers = addConfig("UnlimitedFavoredStickers", configTypeBool, false);
|
public static ConfigItem unlimitedFavedStickers = addConfig("UnlimitedFavoredStickers", configTypeBool, false);
|
||||||
public static ConfigItem unlimitedPinnedDialogs = addConfig("UnlimitedPinnedDialogs", 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 disablePhotoSideAction = addConfig("DisablePhotoViewerSideAction", configTypeBool, false);
|
||||||
public static ConfigItem openArchiveOnPull = addConfig("OpenArchiveOnPull", configTypeBool, false);
|
public static ConfigItem openArchiveOnPull = addConfig("OpenArchiveOnPull", configTypeBool, false);
|
||||||
public static ConfigItem hideKeyboardOnChatScroll = addConfig("HideKeyboardOnChatScroll", 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 useDefaultTheme = addConfig("UseDefaultTheme", configTypeBool, false);
|
||||||
public static ConfigItem showIdAndDc = addConfig("ShowIdAndDc", 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 cachePath = addConfig("cache_path", configTypeString, "");
|
||||||
public static ConfigItem customSavePath = addConfig("customSavePath", configTypeString, "NekoX");
|
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 translateToLang = addConfig("TransToLang", configTypeString, ""); // "" -> translate to current language (MessageTrans.kt & Translator.kt)
|
||||||
public static ConfigItem translateInputLang = addConfig("TransInputToLang", configTypeString, "en");
|
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);
|
public static ConfigItem disableNotificationBubbles = addConfig("disableNotificationBubbles", configTypeBool, false);
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
|
||||||
|
|
||||||
private final AbstractConfigCell headerTranslation = cellGroup.appendCell(new ConfigCellHeader(LocaleController.getString("Translate")));
|
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 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 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 translateInputToLangRow = cellGroup.appendCell(new ConfigCellCustom(CellGroup.ITEM_TYPE_TEXT_SETTINGS_CELL, true));
|
||||||
private final AbstractConfigCell googleCloudTranslateKeyRow = cellGroup.appendCell(new ConfigCellTextDetail(NekoConfig.googleCloudTranslateKey, (view, position) -> {
|
private final AbstractConfigCell googleCloudTranslateKeyRow = cellGroup.appendCell(new ConfigCellTextDetail(NekoConfig.googleCloudTranslateKey, (view, position) -> {
|
||||||
|
|
|
@ -149,4 +149,5 @@
|
||||||
<string name="enhancedFileLoader">加速下载</string>
|
<string name="enhancedFileLoader">加速下载</string>
|
||||||
<string name="useOSMDroidMap">使用 OSMDroid 地图</string>
|
<string name="useOSMDroidMap">使用 OSMDroid 地图</string>
|
||||||
<string name="mapDriftingFixForGoogleMaps">修复 Google 地图在中国的漂移问题</string>
|
<string name="mapDriftingFixForGoogleMaps">修复 Google 地图在中国的漂移问题</string>
|
||||||
|
<string name="useTelegramTranslateInChat">在聊天中使用 Telegram 官方翻译</string>
|
||||||
</resources>
|
</resources>
|
|
@ -147,4 +147,5 @@
|
||||||
<string name="enhancedFileLoader">Enhance Download speed</string>
|
<string name="enhancedFileLoader">Enhance Download speed</string>
|
||||||
<string name="mapDriftingFixForGoogleMaps">Fix Google Maps drifting in China</string>
|
<string name="mapDriftingFixForGoogleMaps">Fix Google Maps drifting in China</string>
|
||||||
<string name="useOSMDroidMap">Use OSMDroid Map</string>
|
<string name="useOSMDroidMap">Use OSMDroid Map</string>
|
||||||
|
<string name="useTelegramTranslateInChat">Use Telegram Translate in Chat</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue