From 6d92106f9de7e06f278eda60584b0e198e6a3872 Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Wed, 4 Dec 2024 16:07:43 +0800
Subject: [PATCH] Shows how many configurations have been deleted
https://github.com/2dust/v2rayNG/issues/4078
---
.../java/com/v2ray/ang/handler/MmkvManager.kt | 12 ++++++--
.../java/com/v2ray/ang/ui/MainActivity.kt | 6 ++--
.../com/v2ray/ang/viewmodel/MainViewModel.kt | 28 +++++++++++--------
.../app/src/main/res/values-ar/strings.xml | 1 +
.../app/src/main/res/values-bn/strings.xml | 1 +
.../src/main/res/values-bqi-rIR/strings.xml | 1 +
.../app/src/main/res/values-fa/strings.xml | 1 +
.../app/src/main/res/values-ru/strings.xml | 1 +
.../app/src/main/res/values-vi/strings.xml | 1 +
.../src/main/res/values-zh-rCN/strings.xml | 1 +
.../src/main/res/values-zh-rTW/strings.xml | 1 +
V2rayNG/app/src/main/res/values/strings.xml | 1 +
12 files changed, 38 insertions(+), 17 deletions(-)
diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/MmkvManager.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/MmkvManager.kt
index d6fa289f9..e8cc78fe8 100644
--- a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/MmkvManager.kt
+++ b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/MmkvManager.kt
@@ -164,18 +164,22 @@ object MmkvManager {
}
}
- fun removeAllServer() {
+ fun removeAllServer(): Int {
+ val count = profileFullStorage.allKeys()?.count() ?: 0
mainStorage.clearAll()
profileFullStorage.clearAll()
//profileStorage.clearAll()
serverAffStorage.clearAll()
+ return count
}
- fun removeInvalidServer(guid: String) {
+ fun removeInvalidServer(guid: String): Int {
+ var count = 0
if (guid.isNotEmpty()) {
decodeServerAffiliationInfo(guid)?.let { aff ->
if (aff.testDelayMillis < 0L) {
removeServer(guid)
+ count++
}
}
} else {
@@ -183,10 +187,12 @@ object MmkvManager {
decodeServerAffiliationInfo(key)?.let { aff ->
if (aff.testDelayMillis < 0L) {
removeServer(key)
+ count++
}
}
}
}
+ return count
}
fun encodeServerRaw(guid: String, config: String) {
@@ -336,7 +342,7 @@ object MmkvManager {
}
fun decodeSettingsBool(key: String): Boolean {
- return settingsStorage.decodeBool(key,false)
+ return settingsStorage.decodeBool(key, false)
}
fun decodeSettingsBool(key: String, defaultValue: Boolean): Boolean {
diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt
index 5c64b4093..20dabaf09 100644
--- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt
+++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/MainActivity.kt
@@ -379,9 +379,10 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
.setPositiveButton(android.R.string.ok) { _, _ ->
binding.pbWaiting.show()
lifecycleScope.launch(Dispatchers.IO) {
- mainViewModel.removeAllServer()
+ val ret = mainViewModel.removeAllServer()
launch(Dispatchers.Main) {
mainViewModel.reloadServerList()
+ toast(getString(R.string.title_del_config_count, ret))
binding.pbWaiting.hide()
}
}
@@ -418,9 +419,10 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
.setPositiveButton(android.R.string.ok) { _, _ ->
binding.pbWaiting.show()
lifecycleScope.launch(Dispatchers.IO) {
- mainViewModel.removeInvalidServer()
+ val ret = mainViewModel.removeInvalidServer()
launch(Dispatchers.Main) {
mainViewModel.reloadServerList()
+ toast(getString(R.string.title_del_config_count, ret))
binding.pbWaiting.hide()
}
}
diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/MainViewModel.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/MainViewModel.kt
index cf70c2f08..74752a43f 100644
--- a/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/MainViewModel.kt
+++ b/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/MainViewModel.kt
@@ -6,7 +6,6 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.res.AssetManager
-import android.os.Build
import android.util.Log
import androidx.core.content.ContextCompat
import androidx.lifecycle.AndroidViewModel
@@ -274,26 +273,31 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
return deleteServer.count()
}
- fun removeAllServer() {
- if (subscriptionId.isEmpty() && keywordFilter.isEmpty()) {
- MmkvManager.removeAllServer()
- } else {
- val serversCopy = serversCache.toList()
- for (item in serversCopy) {
- MmkvManager.removeServer(item.guid)
+ fun removeAllServer(): Int {
+ val count =
+ if (subscriptionId.isEmpty() && keywordFilter.isEmpty()) {
+ MmkvManager.removeAllServer()
+ } else {
+ val serversCopy = serversCache.toList()
+ for (item in serversCopy) {
+ MmkvManager.removeServer(item.guid)
+ }
+ serversCache.toList().count()
}
- }
+ return count
}
- fun removeInvalidServer() {
+ fun removeInvalidServer(): Int {
+ var count = 0
if (subscriptionId.isEmpty() && keywordFilter.isEmpty()) {
- MmkvManager.removeInvalidServer("")
+ count += MmkvManager.removeInvalidServer("")
} else {
val serversCopy = serversCache.toList()
for (item in serversCopy) {
- MmkvManager.removeInvalidServer(item.guid)
+ count += MmkvManager.removeInvalidServer(item.guid)
}
}
+ return count
}
fun sortByTestResults() {
diff --git a/V2rayNG/app/src/main/res/values-ar/strings.xml b/V2rayNG/app/src/main/res/values-ar/strings.xml
index a200418ff..635c6caf2 100644
--- a/V2rayNG/app/src/main/res/values-ar/strings.xml
+++ b/V2rayNG/app/src/main/res/values-ar/strings.xml
@@ -257,6 +257,7 @@
جميع مجموعات الاشتراك
حذف %d من الإعدادات المكررة
+ Delete %d configurations
بدء الخدمة
تأكيد
diff --git a/V2rayNG/app/src/main/res/values-bn/strings.xml b/V2rayNG/app/src/main/res/values-bn/strings.xml
index fd7a0c89a..e53f51734 100644
--- a/V2rayNG/app/src/main/res/values-bn/strings.xml
+++ b/V2rayNG/app/src/main/res/values-bn/strings.xml
@@ -256,6 +256,7 @@
কনফিগারেশন ফাইল ফিল্টার করুন
সব সাবস্ক্রিপশন গ্রুপ
%d ডুপ্লিকেট কনফিগারেশন মুছে ফেলুন
+ Delete %d configurations
সার্ভিস শুরু করুন
নিশ্চিত করুন
diff --git a/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml b/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml
index b8b81da05..f55197fa2 100644
--- a/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml
+++ b/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml
@@ -258,6 +258,7 @@
پوی جرگیل
پاک کردن %d کانفیگ تکراری
+ Delete %d configurations
ره وندن خدمات
قوۊل
diff --git a/V2rayNG/app/src/main/res/values-fa/strings.xml b/V2rayNG/app/src/main/res/values-fa/strings.xml
index 764485d97..efd8fb078 100644
--- a/V2rayNG/app/src/main/res/values-fa/strings.xml
+++ b/V2rayNG/app/src/main/res/values-fa/strings.xml
@@ -256,6 +256,7 @@
همه گروههای اشتراک
حذف %d کانفیگ تکراری
+ Delete %d configurations
شروع خدمات
تایید
diff --git a/V2rayNG/app/src/main/res/values-ru/strings.xml b/V2rayNG/app/src/main/res/values-ru/strings.xml
index 6a7e576f9..e0f21c88a 100644
--- a/V2rayNG/app/src/main/res/values-ru/strings.xml
+++ b/V2rayNG/app/src/main/res/values-ru/strings.xml
@@ -258,6 +258,7 @@
Все группы
Удалено дубликатов профилей: %d
+ Delete %d configurations
Запуск службы
Подтвердить
diff --git a/V2rayNG/app/src/main/res/values-vi/strings.xml b/V2rayNG/app/src/main/res/values-vi/strings.xml
index a25149826..1ba912345 100644
--- a/V2rayNG/app/src/main/res/values-vi/strings.xml
+++ b/V2rayNG/app/src/main/res/values-vi/strings.xml
@@ -256,6 +256,7 @@
Hiển thị tất cả các gói đăng ký
Xoá %d cấu hình trùng lặp
+ Delete %d configurations
Khởi động 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 ac92e14f5..8e64e8822 100644
--- a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml
+++ b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml
@@ -253,6 +253,7 @@
所有分组
删除 %d 个重复配置
+ 删除 %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 265d5d901..b9335d6e9 100644
--- a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml
+++ b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml
@@ -255,6 +255,7 @@
所有分組
Delete %d duplicate configurations
+ Delete %d configurations
啟動服務
確定
diff --git a/V2rayNG/app/src/main/res/values/strings.xml b/V2rayNG/app/src/main/res/values/strings.xml
index 862b1e084..69d5d83bb 100644
--- a/V2rayNG/app/src/main/res/values/strings.xml
+++ b/V2rayNG/app/src/main/res/values/strings.xml
@@ -260,6 +260,7 @@
Filter configuration file
All groups
Delete %d duplicate configurations
+ Delete %d configurations
Start Service
Confirm