From b89be7f504f2aed432a0732fc52218864737d945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Tue, 9 Mar 2021 18:32:48 +0800 Subject: [PATCH] Split auto download settings --- .../messenger/DownloadController.java | 10 +++++-- .../java/tw/nekomimi/nekogram/NekoConfig.java | 18 +++++++++-- .../settings/NekoChatSettingsActivity.java | 30 +++++++++++++++++-- .../src/main/res/values/strings_nekox.xml | 5 ++++ 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/DownloadController.java b/TMessagesProj/src/main/java/org/telegram/messenger/DownloadController.java index 2b3fa3359..11ded715b 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/DownloadController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/DownloadController.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.HashMap; import cn.hutool.core.util.StrUtil; +import tw.nekomimi.nekogram.NekoConfig; public class DownloadController extends BaseController implements NotificationCenter.NotificationCenterDelegate { @@ -576,8 +577,13 @@ public class DownloadController extends BaseController implements NotificationCe public boolean canDownloadMedia(MessageObject messageObject) { if (messageObject.getDocument() != null) { String documentName = messageObject.getDocument().file_name; - if (StrUtil.endWithAny(documentName, ".cmd", ".bat", ".exe", ".lha", ".lzh", ".apk", ".zip", ".7z")) { - return false; + if (StrUtil.isNotBlank(documentName)) { + if ((NekoConfig.disableAutoDownloadingWin32Executable && + documentName.toLowerCase().matches(".*\\.(cmd|bat|com|exe|lnk|msi|ps1|reg|vb|vbe|vbs|vbscript)") + ) || (NekoConfig.disableAutoDownloadingArchive && + documentName.toLowerCase().matches(".*\\.(apk|zip|7z|tar|gz|zst|iso|xz|lha|lzh)") + ) + ) return false; } } return canDownloadMedia(messageObject.messageOwner) == 1; diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java index c9335c899..1b8b3d6de 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java @@ -137,6 +137,9 @@ public class NekoConfig { public static boolean avatarBackgroundDarken; public static boolean disableTrending; + public static boolean disableAutoDownloadingWin32Executable; + public static boolean disableAutoDownloadingArchive; + public static String getOpenPGPAppName() { if (StrUtil.isNotBlank(openPGPApp)) { @@ -222,8 +225,8 @@ public class NekoConfig { hideKeyboardOnChatScroll = preferences.getBoolean("hideKeyboardOnChatScroll", false); avatarAsDrawerBackground = preferences.getBoolean("avatarAsDrawerBackground", true); avatarBackgroundBlur = preferences.getBoolean("avatarBackgroundBlur", false); - avatarBackgroundDarken = preferences.getBoolean("avatarBackgroundDarken", false); - useSystemEmoji = preferences.getBoolean("useSystemEmoji", false); + avatarBackgroundDarken = preferences.getBoolean("avatarBackgroundDarken", false); + useSystemEmoji = preferences.getBoolean("useSystemEmoji", false); showTabsOnForward = preferences.getBoolean("showTabsOnForward", false); rearVideoMessages = preferences.getBoolean("rearVideoMessages", false); hideAllTab = preferences.getBoolean("hideAllTab", false); @@ -291,6 +294,9 @@ public class NekoConfig { acceptSecretChat = preferences.getBoolean("acceptSecretChat", true); disableTrending = preferences.getBoolean("disableTrending", true); + disableAutoDownloadingWin32Executable = preferences.getBoolean("disableAutoDownloadingWin32Executable", true); + disableAutoDownloadingArchive = preferences.getBoolean("disableAutoDownloadingArchive", true); + } public static void toggleShowAddToSavedMessages() { @@ -743,6 +749,14 @@ public class NekoConfig { preferences.edit().putBoolean("disableTrending", disableTrending = !disableTrending).apply(); } + public static void toggleDisableAutoDownloadingWin32Executable() { + preferences.edit().putBoolean("disableAutoDownloadingWin32Executable", disableAutoDownloadingWin32Executable = !disableAutoDownloadingWin32Executable).apply(); + } + + public static void toggleDisableAutoDownloadingArchive() { + preferences.edit().putBoolean("disableAutoDownloadingArchive", disableAutoDownloadingArchive = !disableAutoDownloadingArchive).apply(); + } + private static final String EMOJI_FONT_AOSP = "NotoColorEmoji.ttf"; public static Typeface getSystemEmojiTypeface() { 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 e8e562956..4853fd985 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java @@ -79,6 +79,11 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati private int messageMenuRow; private int chat2Row; + private int downloadRow; + private int win32Row; + private int archiveRow; + private int download2Row; + private int foldersRow; private int showTabsOnForwardRow; private int hideAllTabRow; @@ -257,6 +262,16 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati if (view instanceof TextCheckCell) { ((TextCheckCell) view).setChecked(NekoConfig.disableTrending); } + } else if (position == win32Row) { + NekoConfig.toggleDisableAutoDownloadingWin32Executable(); + if (view instanceof TextCheckCell) { + ((TextCheckCell) view).setChecked(!NekoConfig.disableAutoDownloadingWin32Executable); + } + } else if (position == archiveRow) { + NekoConfig.toggleDisableAutoDownloadingArchive(); + if (view instanceof TextCheckCell) { + ((TextCheckCell) view).setChecked(!NekoConfig.disableAutoDownloadingArchive); + } } }); @@ -299,6 +314,11 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati messageMenuRow = rowCount++; chat2Row = rowCount++; + downloadRow = rowCount++; + win32Row = rowCount++; + archiveRow = rowCount++; + download2Row = rowCount++; + foldersRow = rowCount++; showTabsOnForwardRow = rowCount++; hideAllTabRow = rowCount++; @@ -636,6 +656,10 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati textCell.setTextAndCheck(LocaleController.getString("DisableProximityEvents", R.string.DisableProximityEvents), NekoConfig.disableProximityEvents, true); } else if (position == disableTrendingRow) { textCell.setTextAndCheck(LocaleController.getString("DisableTrending", R.string.DisableTrending), NekoConfig.disableTrending, true); + } else if (position == win32Row) { + textCell.setTextAndCheck(LocaleController.getString("Win32ExecutableFiles", R.string.Win32ExecutableFiles), !NekoConfig.disableAutoDownloadingWin32Executable, true); + } else if (position == archiveRow) { + textCell.setTextAndCheck(LocaleController.getString("ArchiveFiles", R.string.ArchiveFiles), !NekoConfig.disableAutoDownloadingArchive, false); } break; } @@ -645,6 +669,8 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati headerCell.setText(LocaleController.getString("Chat", R.string.Chat)); } else if (position == foldersRow) { headerCell.setText(LocaleController.getString("Folder", R.string.Folder)); + } else if (position == downloadRow) { + headerCell.setText(LocaleController.getString("AutoDownload", R.string.AutoDownload)); } else if (position == stickerSizeHeaderRow) { headerCell.setText(LocaleController.getString("StickerSize", R.string.StickerSize)); } @@ -702,11 +728,11 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati @Override public int getItemViewType(int position) { - if (position == chat2Row || position == folders2Row || position == stickerSize2Row) { + if (position == chat2Row || position == folders2Row || position == download2Row || position == stickerSize2Row) { return 1; } else if (position == mapPreviewRow || position == messageMenuRow || position == tabsTitleTypeRow) { return 2; - } else if (position == chatRow || position == foldersRow || position == stickerSizeHeaderRow) { + } else if (position == chatRow || position == foldersRow || position == downloadRow || position == stickerSizeHeaderRow) { return 4; } else if (position == stickerSizeRow) { return 8; diff --git a/TMessagesProj/src/main/res/values/strings_nekox.xml b/TMessagesProj/src/main/res/values/strings_nekox.xml index 57026cef2..83f4ad7e6 100644 --- a/TMessagesProj/src/main/res/values/strings_nekox.xml +++ b/TMessagesProj/src/main/res/values/strings_nekox.xml @@ -274,9 +274,14 @@ Origin Replace Use regex + Disable Trending Hide device model Device model will be uploaded the second time the app starts after logging in. You can change this in the settings later. + AutoDownload + Win32 executable files + Archive files + \ No newline at end of file