From 4b1fa29ade0dc1174683432100f67a556c754a93 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Tue, 30 Dec 2025 20:36:53 +0800 Subject: [PATCH] Refactor backup flow and remove backup summary --- .../java/com/v2ray/ang/ui/AboutActivity.kt | 57 ++++++++++++++----- .../src/main/res/layout/activity_about.xml | 8 --- .../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 - 11 files changed, 42 insertions(+), 32 deletions(-) diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/AboutActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/AboutActivity.kt index 03d72042..32180711 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/AboutActivity.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/AboutActivity.kt @@ -16,7 +16,6 @@ import com.v2ray.ang.databinding.ActivityAboutBinding import com.v2ray.ang.extension.toast import com.v2ray.ang.extension.toastError import com.v2ray.ang.extension.toastSuccess -import com.v2ray.ang.handler.MmkvManager import com.v2ray.ang.handler.SpeedtestManager import com.v2ray.ang.util.Utils import com.v2ray.ang.util.ZipUtil @@ -27,7 +26,6 @@ import java.util.Locale class AboutActivity : BaseActivity() { private val binding by lazy { ActivityAboutBinding.inflate(layoutInflater) } - private val extDir by lazy { File(Utils.backupPath(this)) } private val requestPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted -> @@ -42,25 +40,50 @@ class AboutActivity : BaseActivity() { } } + private val createBackupFile = + registerForActivityResult(ActivityResultContracts.CreateDocument("application/zip")) { uri -> + if (uri != null) { + try { + val ret = backupConfigurationToCache() + if (ret.first) { + // Copy the cached zip file to user-selected location + contentResolver.openOutputStream(uri)?.use { output -> + File(ret.second).inputStream().use { input -> + input.copyTo(output) + } + } + // Clean up cache file + File(ret.second).delete() + toastSuccess(R.string.toast_success) + } else { + toastError(R.string.toast_failure) + } + } catch (e: Exception) { + Log.e(AppConfig.TAG, "Failed to backup configuration", e) + toastError(R.string.toast_failure) + } + } + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(binding.root) title = getString(R.string.title_about) - binding.tvBackupSummary.text = this.getString(R.string.summary_configuration_backup, extDir) - binding.layoutBackup.setOnClickListener { - val ret = backupConfiguration(extDir.absolutePath) - if (ret.first) { - toastSuccess(R.string.toast_success) - } else { - toastError(R.string.toast_failure) - } + val dateFormatted = SimpleDateFormat( + "yyyy-MM-dd-HH-mm-ss", + Locale.getDefault() + ).format(System.currentTimeMillis()) + val defaultFileName = "${getString(R.string.app_name)}_${dateFormatted}.zip" + + // Let user choose where to save the backup file + createBackupFile.launch(defaultFileName) } binding.layoutShare.setOnClickListener { - val ret = backupConfiguration(cacheDir.absolutePath) + val ret = backupConfigurationToCache() if (ret.first) { startActivity( Intent.createChooser( @@ -132,14 +155,18 @@ class AboutActivity : BaseActivity() { } } - private fun backupConfiguration(outputZipFilePos: String): Pair { - val dateFormated = SimpleDateFormat( + /** + * Backup configuration to cache directory + * Returns Pair + */ + private fun backupConfigurationToCache(): Pair { + val dateFormatted = SimpleDateFormat( "yyyy-MM-dd-HH-mm-ss", Locale.getDefault() ).format(System.currentTimeMillis()) - val folderName = "${getString(R.string.app_name)}_${dateFormated}" + val folderName = "${getString(R.string.app_name)}_${dateFormatted}" val backupDir = this.cacheDir.absolutePath + "/$folderName" - val outputZipFilePath = "$outputZipFilePos/$folderName.zip" + val outputZipFilePath = "${this.cacheDir.absolutePath}/$folderName.zip" val count = MMKV.backupAllToDirectory(backupDir) if (count <= 0) { diff --git a/V2rayNG/app/src/main/res/layout/activity_about.xml b/V2rayNG/app/src/main/res/layout/activity_about.xml index 5a6c72bf..2eddfe0e 100644 --- a/V2rayNG/app/src/main/res/layout/activity_about.xml +++ b/V2rayNG/app/src/main/res/layout/activity_about.xml @@ -43,14 +43,6 @@ android:text="@string/title_configuration_backup" android:textAppearance="@style/TextAppearance.AppCompat.Subhead" /> - - diff --git a/V2rayNG/app/src/main/res/values-ar/strings.xml b/V2rayNG/app/src/main/res/values-ar/strings.xml index 909b16d5..6bd3bc8e 100644 --- a/V2rayNG/app/src/main/res/values-ar/strings.xml +++ b/V2rayNG/app/src/main/res/values-ar/strings.xml @@ -234,7 +234,6 @@ Open Source licenses قناة Telegram نسخ التكوين احتياطيًا - موقع التخزين: [%s]، سيتم مسح النسخة الاحتياطية بعد إلغاء تثبيت التطبيق أو مسح التخزين استعادة التكوين مشاركة التكوين diff --git a/V2rayNG/app/src/main/res/values-bn/strings.xml b/V2rayNG/app/src/main/res/values-bn/strings.xml index 7fc1692c..bd8bcf5c 100644 --- a/V2rayNG/app/src/main/res/values-bn/strings.xml +++ b/V2rayNG/app/src/main/res/values-bn/strings.xml @@ -234,7 +234,6 @@ Open Source licenses টেলিগ্রাম চ্যানেল কনফিগারেশন ব্যাকআপ - স্টোরেজ অবস্থান: [%s], অ্যাপ আনইনস্টল বা স্টোরেজ ক্লিয়ার করার পরে ব্যাকআপ মুছে যাবে কনফিগারেশন পুনরুদ্ধার কনফিগারেশন শেয়ার করুন 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 fc922c32..97c3bee6 100644 --- a/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml +++ b/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml @@ -234,7 +234,6 @@ موجوزا کود بونچک تورگه تلگرام لادراری گرؽڌن ز کانفیگ - جاگه زفت کردن: [%s]، بعڌ پاک کردن برنومه یا پاک کردن جاگه زفت کردن، نوسخه لادرار هم پاک ابۊ. وورگندن کانفیگ یک رسۊوی کانفیگ diff --git a/V2rayNG/app/src/main/res/values-fa/strings.xml b/V2rayNG/app/src/main/res/values-fa/strings.xml index 27ecd931..ff3cd1f8 100644 --- a/V2rayNG/app/src/main/res/values-fa/strings.xml +++ b/V2rayNG/app/src/main/res/values-fa/strings.xml @@ -233,7 +233,6 @@ مجوز های منبع باز کانال تلگرام پشتیبان گیری از پیکربندی - محل ذخیره سازی: [%s], پس از حذف نصب برنامه یا پاک کردن فضای ذخیره سازی، نسخه پشتیبان پاک می شود بازیابی پیکربندی اشتراک گذاری پیکربندی تبلیغات diff --git a/V2rayNG/app/src/main/res/values-ru/strings.xml b/V2rayNG/app/src/main/res/values-ru/strings.xml index 84555bd8..de6ecb9d 100644 --- a/V2rayNG/app/src/main/res/values-ru/strings.xml +++ b/V2rayNG/app/src/main/res/values-ru/strings.xml @@ -233,7 +233,6 @@ Лицензии открытого исходного кода Telegram-канал Резервирование конфигурации - Путь: [%s]. Резервная копия будет стёрта при удалении приложения или очистке хранилища. Восстановление конфигурации Поделиться конфигурацией diff --git a/V2rayNG/app/src/main/res/values-vi/strings.xml b/V2rayNG/app/src/main/res/values-vi/strings.xml index f377976f..db6d1493 100644 --- a/V2rayNG/app/src/main/res/values-vi/strings.xml +++ b/V2rayNG/app/src/main/res/values-vi/strings.xml @@ -235,7 +235,6 @@ Open Source licenses Kênh Telegram Sao lưu cấu hình - Nơi lưu trữ: [%s], bản backup sẽ được dọn dẹp sau khi xóa ứng dụng hoặc xóa bộ nhớ. Khôi phục cấu hình Chia sẻ cấu hình Quảng bá server 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 2fb96a25..102d508d 100644 --- a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml @@ -231,7 +231,6 @@ Open Source licenses Telegram 频道 备份配置 - 存储位置: [%s], 卸载 App 或清除存储后备份将被清除 还原配置 分享配置 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 aa14cc09..b603b59d 100644 --- a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml @@ -232,7 +232,6 @@ Open Source licenses Telegram 頻道 備份設定 - 儲存位置: [%s], 卸載App或清除儲存後備份將被清除 還原設定 分享設定 diff --git a/V2rayNG/app/src/main/res/values/strings.xml b/V2rayNG/app/src/main/res/values/strings.xml index e821aecc..29da7c20 100644 --- a/V2rayNG/app/src/main/res/values/strings.xml +++ b/V2rayNG/app/src/main/res/values/strings.xml @@ -237,7 +237,6 @@ Open Source licenses Telegram channel Backup configuration - Storage location: [%s], The backup will be cleared after uninstalling the app or clearing the storage Restore configuration Share configuration