From 3d7ed12d4b257ebd84c0ac94eeba635dc9160e14 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 25 Mar 2023 21:16:21 +0800 Subject: [PATCH] Added the function of deleting duplicate configurations --- .../kotlin/com/v2ray/ang/ui/MainActivity.kt | 9 +++++++- .../com/v2ray/ang/viewmodel/MainViewModel.kt | 21 +++++++++++++++++++ V2rayNG/app/src/main/res/menu/menu_main.xml | 5 +++++ .../app/src/main/res/values-fa/strings.xml | 2 ++ .../app/src/main/res/values-ru/strings.xml | 2 ++ .../app/src/main/res/values-vi/strings.xml | 2 ++ .../src/main/res/values-zh-rCN/strings.xml | 2 ++ .../src/main/res/values-zh-rTW/strings.xml | 2 ++ V2rayNG/app/src/main/res/values/strings.xml | 2 ++ 9 files changed, 46 insertions(+), 1 deletion(-) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt index d7caf53e..703bac40 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt @@ -297,7 +297,14 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList .show() true } - + R.id.del_duplicate_config-> { + AlertDialog.Builder(this).setMessage(R.string.del_config_comfirm) + .setPositiveButton(android.R.string.ok) { _, _ -> + mainViewModel.removeDuplicateServer() + } + .show() + true + } R.id.del_invalid_config -> { AlertDialog.Builder(this).setMessage(R.string.del_config_comfirm) .setPositiveButton(android.R.string.ok) { _, _ -> diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/MainViewModel.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/MainViewModel.kt index 30673162..6c6ddc62 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/MainViewModel.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/MainViewModel.kt @@ -201,6 +201,27 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { return -1 } + fun removeDuplicateServer() { + val deleteServer = mutableListOf() + serversCache.forEachIndexed { index, it -> + val outbound = it.config.getProxyOutbound() + serversCache.forEachIndexed { index2, it2 -> + if(index2 > index){ + val outbound2 = it2.config.getProxyOutbound() + if( outbound == outbound2 && !deleteServer.contains(it2.guid)) + { + deleteServer.add(it2.guid) + } + } + } + } + for(it in deleteServer){ + MmkvManager.removeServer(it) + } + reloadServerList() + getApplication().toast(getApplication().getString(R.string.title_del_duplicate_config_count, deleteServer.count())) + } + private val mMsgReceiver = object : BroadcastReceiver() { override fun onReceive(ctx: Context?, intent: Intent?) { when (intent?.getIntExtra("key", 0)) { diff --git a/V2rayNG/app/src/main/res/menu/menu_main.xml b/V2rayNG/app/src/main/res/menu/menu_main.xml index 538074cf..14ea10e8 100644 --- a/V2rayNG/app/src/main/res/menu/menu_main.xml +++ b/V2rayNG/app/src/main/res/menu/menu_main.xml @@ -73,6 +73,11 @@ android:icon="@drawable/ic_delete_white_24dp" android:title="@string/title_del_all_config" app:showAsAction="never" /> + پاک کردن راه‌اندازی مجدد خدمات حذف تمام پیکربندی + Delete duplicate config تنظیمات نامعتبر را حذف کنید (ابتدا آزمایش کنید) خروجی گرفتن پیکربندی‌های غیرسفارشی در کلیپ‌بورد تنظیمات گروه‌ی اشتراک @@ -178,6 +179,7 @@ مرتب‌سازی بر اساس نتایج آزمایش فیلتر پرونده پیکربندی همه گروه‌های اشتراک + Delete %d duplicate configurations شروع خدمات تایید diff --git a/V2rayNG/app/src/main/res/values-ru/strings.xml b/V2rayNG/app/src/main/res/values-ru/strings.xml index 8f28ebe6..ef852674 100644 --- a/V2rayNG/app/src/main/res/values-ru/strings.xml +++ b/V2rayNG/app/src/main/res/values-ru/strings.xml @@ -165,6 +165,7 @@ Очистить Перезапуск службы Удалить все профили + Delete duplicate config Удалить сбойные профили (после проверки) Экспорт всех профилей в буфер обмена Группы @@ -178,6 +179,7 @@ Сортировка по результатам теста Фильтр профилей Все группы + Delete %d duplicate configurations Запуск службы Подтвердить diff --git a/V2rayNG/app/src/main/res/values-vi/strings.xml b/V2rayNG/app/src/main/res/values-vi/strings.xml index d584966d..46d5f515 100644 --- a/V2rayNG/app/src/main/res/values-vi/strings.xml +++ b/V2rayNG/app/src/main/res/values-vi/strings.xml @@ -164,6 +164,7 @@ Xoá nhật ký Kết nối lại v2rayNG Xoá tất cả cấu hình + Delete duplicate config Xoá cấu hình lỗi (Kiểm tra trước) Xuất và sao chép tất cả cấu hình Các gói đăng ký @@ -177,6 +178,7 @@ Sắp xếp lại theo lần kiểm tra cuối cùng Lọc cấu hình theo các gói đăng ký Hiển thị tất cả các gói đăng ký + Delete %d duplicate configurations Bắt đầu v2rayNG Xác nhận diff --git a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml index 6e5bc190..984caa79 100644 --- a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml @@ -164,6 +164,7 @@ 清除 服务重启 删除全部配置 + 删除重复配置 删除无效配置(先测试) 导出全部(非自定义)配置至剪贴板 订阅分组设置 @@ -177,6 +178,7 @@ 按测试结果排序 过滤配置文件 所有订阅分组 + 删除 %d 个重复配置 启动服务 确定 diff --git a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml index 59ac201b..968913b1 100644 --- a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml @@ -164,6 +164,7 @@ 清除 服務重啟 刪除全部組態 + 刪除重複組態 刪除無效組態 (先偵測) 匯出全部 (非自訂) 組態至剪貼簿 訂閱分組設定 @@ -177,6 +178,7 @@ 依偵測結果排序 過濾組態 所有訂閱分組 + Delete %d duplicate configurations 啟動服務 確定 diff --git a/V2rayNG/app/src/main/res/values/strings.xml b/V2rayNG/app/src/main/res/values/strings.xml index 8a846943..4108aee4 100644 --- a/V2rayNG/app/src/main/res/values/strings.xml +++ b/V2rayNG/app/src/main/res/values/strings.xml @@ -172,6 +172,7 @@ Clear Service restart Delete all config + Delete duplicate config Delete invalid config(Test first) Export non-custom configs to clipboard Subscription group setting @@ -185,6 +186,7 @@ Sorting by test results Filter configuration file All subscription groups + Delete %d duplicate configurations Start Service Confirm