diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 9151c7b86..593707e89 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -34083,8 +34083,14 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } final int finalTimestamp = timestamp; // boolean noforwards = getMessagesController().isChatNoForwards(currentChat) || (messageObject != null && messageObject.messageOwner != null && messageObject.messageOwner.noforwards); - boolean noforwards = false; - builder.setItems(noforwards ? new CharSequence[] {LocaleController.getString("Open", R.string.Open)} : new CharSequence[]{LocaleController.getString("Open", R.string.Open), LocaleController.getString("Copy", R.string.Copy)}, (dialog, which) -> { + CharSequence[] items = new CharSequence[]{ + LocaleController.getString("Open", R.string.Open), + LocaleController.getString("Copy", R.string.Copy), + LocaleController.getString("ShareQRCode", R.string.ShareQRCode), + LocaleController.getString("ShareMessages", R.string.ShareMessages) + }; +// builder.setItems(noforwards ? new CharSequence[] {LocaleController.getString("Open", R.string.Open)} : new CharSequence[]{LocaleController.getString("Open", R.string.Open), LocaleController.getString("Copy", R.string.Copy)}, (dialog, which) -> { + builder.setItems(items, (dialog, which) -> { if (which == 0) { if (str.startsWith("video?")) { didPressMessageUrl(url, false, messageObject, cell); @@ -34092,7 +34098,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not logSponsoredClicked(messageObject); openClickableLink(url, str, false, cell, messageObject, true); } - } else if (which == 1) { + } else if (which == 1 || which == 3) { + String urlFinal = str; if (str.startsWith("video?") && messageObject != null && !messageObject.scheduled) { MessageObject messageObject1 = messageObject; boolean isMedia = messageObject.isVideo() || messageObject.isRoundVideo() || messageObject.isVoice() || messageObject.isMusic(); @@ -34129,21 +34136,36 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (link == null) { return; } - AndroidUtilities.addToClipboard(link); + urlFinal = link; +// AndroidUtilities.addToClipboard(link); } else { - AndroidUtilities.addToClipboard(str); +// AndroidUtilities.addToClipboard(str); } - createUndoView(); - if (undoView == null) { - return; - } - if (str.startsWith("@")) { - undoView.showWithAction(0, UndoView.ACTION_USERNAME_COPIED, null); - } else if (str.startsWith("#") || str.startsWith("$")) { - undoView.showWithAction(0, UndoView.ACTION_HASHTAG_COPIED, null); + if (which == 1) { + AndroidUtilities.addToClipboard(urlFinal); + createUndoView(); + if (undoView == null) { + return; + } + if (str.startsWith("@")) { + undoView.showWithAction(0, UndoView.ACTION_USERNAME_COPIED, null); + } else if (str.startsWith("#") || str.startsWith("$")) { + undoView.showWithAction(0, UndoView.ACTION_HASHTAG_COPIED, null); + } else { + undoView.showWithAction(0, UndoView.ACTION_LINK_COPIED, null); + } } else { - undoView.showWithAction(0, UndoView.ACTION_LINK_COPIED, null); + // ShareMessage + Intent shareIntent = new Intent(Intent.ACTION_SEND); + shareIntent.setType("text/plain"); + shareIntent.putExtra(Intent.EXTRA_TEXT, urlFinal); + Intent chooserIntent = Intent.createChooser(shareIntent, LocaleController.getString("ShareFile", R.string.ShareFile)); + chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + ApplicationLoader.applicationContext.startActivity(chooserIntent); } + } else if (which == 2) { + // QRCode + ProxyUtil.showQrDialog(getParentActivity(), str); } }); builder.setOnPreDismissListener(di -> { @@ -41643,6 +41665,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not ).setDuration(8000).show(true); } + interface NagramCopyMesage { + void run(boolean isCopy); + } + public void didLongPressLink(ChatMessageCell cell, MessageObject messageObject, CharacterStyle span, String str) { final ItemOptions options = ItemOptions.makeOptions(ChatActivity.this, cell, true); final ScrimOptions dialog = new ScrimOptions(getContext(), themeDelegate); @@ -41667,7 +41693,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not }); } - options.add(R.drawable.msg_copy, getString(R.string.CopyLink), () -> { + NagramCopyMesage run1 = (boolean isCopy) -> { + String urlFinal = str; if (str.startsWith("video?") && messageObject != null && !messageObject.scheduled) { MessageObject messageObject1 = messageObject; boolean isMedia = messageObject.isVideo() || messageObject.isRoundVideo() || messageObject.isVoice() || messageObject.isMusic(); @@ -41707,22 +41734,47 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (link == null) { return; } - AndroidUtilities.addToClipboard(link); + urlFinal = link; +// AndroidUtilities.addToClipboard(link); } else { - AndroidUtilities.addToClipboard(str); +// AndroidUtilities.addToClipboard(str); } - createUndoView(); - if (undoView == null) { - return; - } - if (str.startsWith("@")) { - undoView.showWithAction(0, UndoView.ACTION_USERNAME_COPIED, null); - } else if (str.startsWith("#") || str.startsWith("$")) { - undoView.showWithAction(0, UndoView.ACTION_HASHTAG_COPIED, null); + if (isCopy) { + AndroidUtilities.addToClipboard(urlFinal); + createUndoView(); + if (undoView == null) { + return; + } + if (str.startsWith("@")) { + undoView.showWithAction(0, UndoView.ACTION_USERNAME_COPIED, null); + } else if (str.startsWith("#") || str.startsWith("$")) { + undoView.showWithAction(0, UndoView.ACTION_HASHTAG_COPIED, null); + } else { + undoView.showWithAction(0, UndoView.ACTION_LINK_COPIED, null); + } } else { - undoView.showWithAction(0, UndoView.ACTION_LINK_COPIED, null); + // ShareMessage + Intent shareIntent = new Intent(Intent.ACTION_SEND); + shareIntent.setType("text/plain"); + shareIntent.putExtra(Intent.EXTRA_TEXT, urlFinal); + Intent chooserIntent = Intent.createChooser(shareIntent, LocaleController.getString("ShareFile", R.string.ShareFile)); + chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + ApplicationLoader.applicationContext.startActivity(chooserIntent); } + }; + options.add(R.drawable.msg_copy, getString(R.string.CopyLink), () -> { + run1.run(true); }); +// ----- Nagram Hook start ----- + options.add(R.drawable.wallet_qr, getString("ShareQRCode", R.string.ShareQRCode), () -> { + // QRCode + ProxyUtil.showQrDialog(getParentActivity(), str); + }); + options.add(R.drawable.msg_shareout, getString("ShareMessages", R.string.ShareMessages), () -> { + // ShareMessage + run1.run(false); + }); +// ----- Nagram Hook end ----- dialog.setItemOptions(options); if (span instanceof URLSpanReplacement) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index b3a9262d6..5e68f7c49 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -10076,8 +10076,11 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. getFileLoader().loadFile(imageLocation, chat, null, FileLoader.PRIORITY_LOW, 1); } avatarImage.getImageReceiver().setVisible(!PhotoViewer.isShowingImage(photoBig) && (getLastStoryViewer() == null || getLastStoryViewer().transitionViewHolder.view != avatarImage), storyView != null); - if (chat.photo != null && chat.photo.dc_id != 0) { + dc = chatInfo != null ? chatInfo.stats_dc != 0 ? chatInfo.stats_dc : 0 : 0; + if (dc == 0 && chat.photo != null && chat.photo.dc_id != 0) { dc = chat.photo.dc_id; + } + if (dc != 0) { idTextView.setText("ID: " + chatId + ", DC: " + dc); } else { idTextView.setText("ID: " + chatId); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/bots/BotWebViewContainer.java b/TMessagesProj/src/main/java/org/telegram/ui/bots/BotWebViewContainer.java index 4cf055d8d..4f70c14bf 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/bots/BotWebViewContainer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/bots/BotWebViewContainer.java @@ -100,6 +100,9 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.regex.Pattern; + +import xyz.nextalone.nagram.NaConfig; public abstract class BotWebViewContainer extends FrameLayout implements NotificationCenter.NotificationCenterDelegate { private final static String DURGER_KING_USERNAME = "DurgerKingBot"; @@ -1983,6 +1986,19 @@ public abstract class BotWebViewContainer extends FrameLayout implements Notific @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Uri uriNew = Uri.parse(url); + + // ----- Nagram Hook start ----- + String urlPatternStr = NaConfig.INSTANCE.getOpenUrlOutBotWebViewRegex().String(); + if (botWebViewContainer != null && !urlPatternStr.isEmpty()) { + Pattern urlPattern = Pattern.compile(urlPatternStr, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); + if (urlPattern.matcher(url).find()) { + botWebViewContainer.onOpenUri(uriNew); + d("shouldOverrideUrlLoading("+url+") = true"); + return true; + } + } + // ----- Nagram Hook end ----- + if (botWebViewContainer != null && Browser.isInternalUri(uriNew, null)) { if (MessagesController.getInstance(botWebViewContainer.currentAccount).webAppAllowedProtocols != null && MessagesController.getInstance(botWebViewContainer.currentAccount).webAppAllowedProtocols.contains(uriNew.getScheme())) { diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java index e7182eaa0..831108900 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java @@ -45,6 +45,7 @@ import org.telegram.ui.Components.UndoView; import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; +import java.util.regex.Pattern; import kotlin.Unit; @@ -108,6 +109,16 @@ public class NekoExperimentalSettingsActivity extends BaseNekoXSettingsActivity private final AbstractConfigCell regexFiltersEnableInChatsRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getRegexFiltersEnableInChats())); private final AbstractConfigCell disableChatActionRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disableChatAction)); private final AbstractConfigCell disableChoosingStickerRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disableChoosingSticker)); + private final AbstractConfigCell openUrlOutBotWebViewRegexRow = cellGroup.appendCell(new ConfigCellTextInput(null, NaConfig.INSTANCE.getOpenUrlOutBotWebViewRegex(), + null, null, + (input) -> { + try { + Pattern.compile(input, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); + return input; + } catch (Exception ignored) { + return ""; + } + })); private final AbstractConfigCell divider1 = cellGroup.appendCell(new ConfigCellDivider()); // Story diff --git a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt index 23e6e9494..1dae2d16d 100644 --- a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt +++ b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt @@ -638,6 +638,12 @@ object NaConfig { ConfigItem.configTypeInt, 0 ) + val openUrlOutBotWebViewRegex = + addConfig( + "OpenUrlOutBotWebViewRegex", + ConfigItem.configTypeString, + "" + ) private fun addConfig( k: String, 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 b1e4506a1..7a8dfbcc1 100644 --- a/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml +++ b/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml @@ -158,4 +158,5 @@ 点击消息时间显示详细信息 在频道点击标签默认搜索页面 在其他对话点击标签默认搜索页面 + 指定 URL Regex 跳出 bot webview diff --git a/TMessagesProj/src/main/res/values/strings_na.xml b/TMessagesProj/src/main/res/values/strings_na.xml index 75e83dff0..ff20d0c52 100644 --- a/TMessagesProj/src/main/res/values/strings_na.xml +++ b/TMessagesProj/src/main/res/values/strings_na.xml @@ -158,4 +158,5 @@ Click message time to display details Channel Click Hashtag Default Search Page Chat Click Hashtag Default Search Page + Url regex to jump out of bot webview