From 61c4a3f242907d0bd566c6ad87329aaaf32f1ea8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 23:57:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/config/BackupRestoreUi.kt | 47 ++++++++++++------- app/src/main/res/values/arrays.xml | 6 +++ app/src/main/res/values/strings.xml | 3 ++ 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt index 773a7ceb3..15731b226 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt @@ -67,7 +67,7 @@ object BackupRestoreUi { fun selectBackupFolder(fragment: Fragment) { fragment.alert { titleResource = R.string.select_folder - items(arrayListOf("默认路径", "系统文件夹选择器", "自带文件夹选择器")) { _, index -> + items(fragment.resources.getStringArray(R.array.select_folder).toList()) { _, index -> when (index) { 0 -> PermissionsCompat.Builder(fragment) .addPermissions(*Permissions.Group.STORAGE) @@ -118,23 +118,38 @@ object BackupRestoreUi { } private fun selectRestoreFolder(fragment: Fragment) { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - fragment.startActivityForResult(intent, restoreSelectRequestCode) - } catch (e: java.lang.Exception) { - PermissionsCompat.Builder(fragment) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - Coroutine.async { - Restore.restore(Backup.legadoPath) - }.onSuccess { - fragment.toast(R.string.restore_success) + fragment.alert { + titleResource = R.string.select_folder + items(fragment.resources.getStringArray(R.array.select_folder).toList()) { _, index -> + when (index) { + 0 -> PermissionsCompat.Builder(fragment) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + Coroutine.async { + AppConfig.backupPath = Backup.legadoPath + Restore.restore(Backup.legadoPath) + }.onSuccess { + fragment.toast(R.string.restore_success) + } + } + .request() + 1 -> { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + fragment.startActivityForResult(intent, restoreSelectRequestCode) + } catch (e: java.lang.Exception) { + e.printStackTrace() + fragment.toast(e.localizedMessage ?: "ERROR") + } + } + 2 -> { + } } - .request() - } + } + }.show() } fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index b8cea9e3b..64a83e78a 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -98,6 +98,12 @@ -1 + + @string/default_path + @string/sys_folder_picker + @string/app_folder_picker + + @string/screen_unspecified @string/screen_portrait diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 14787a449..584ac698a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -599,5 +599,8 @@ 显示订阅 服务已停止 正在启动服务\n具体信息查看通知栏 + 默认路径 + 系统文件夹选择器 + 自带选择器(Android10以上可能会失效)