From c1bcea6964b5b1f603f855da45f98e250d1d5b17 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 17:32:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/config/BackupRestoreUi.kt | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 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 ddc41afce..f314b5f1b 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 @@ -49,21 +49,30 @@ object BackupRestoreUi { selectBackupFolder(fragment, backupSelectRequestCode) } } else { - backupUsePermission(fragment) + backupUsePermission(fragment, requestCode = backupSelectRequestCode) } } } - private fun backupUsePermission(fragment: Fragment, path: String = Backup.legadoPath) { + private fun backupUsePermission( + fragment: Fragment, + path: String = Backup.legadoPath, + requestCode: Int = selectFolderRequestCode + ) { PermissionsCompat.Builder(fragment) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) .onGranted { - Coroutine.async { - AppConfig.backupPath = Backup.legadoPath - Backup.backup(fragment.requireContext(), path) - }.onSuccess { - fragment.toast(R.string.backup_success) + when (requestCode) { + selectFolderRequestCode -> AppConfig.backupPath = Backup.legadoPath + else -> { + Coroutine.async { + AppConfig.backupPath = Backup.legadoPath + Backup.backup(fragment.requireContext(), path) + }.onSuccess { + fragment.toast(R.string.backup_success) + } + } } } .request() @@ -74,7 +83,7 @@ object BackupRestoreUi { titleResource = R.string.select_folder items(fragment.resources.getStringArray(R.array.select_folder).toList()) { _, index -> when (index) { - 0 -> backupUsePermission(fragment) + 0 -> backupUsePermission(fragment, requestCode = requestCode) 1 -> { try { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) @@ -231,6 +240,9 @@ object BackupRestoreUi { App.INSTANCE.toast(R.string.restore_success) } } + selectFolderRequestCode -> { + AppConfig.backupPath = currentPath + } } } @@ -240,7 +252,8 @@ object BackupRestoreUi { data?.data?.let { uri -> App.INSTANCE.contentResolver.takePersistableUriPermission( uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + Intent.FLAG_GRANT_READ_URI_PERMISSION + or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) AppConfig.backupPath = uri.toString() Coroutine.async { @@ -254,7 +267,8 @@ object BackupRestoreUi { data?.data?.let { uri -> App.INSTANCE.contentResolver.takePersistableUriPermission( uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + Intent.FLAG_GRANT_READ_URI_PERMISSION + or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) AppConfig.backupPath = uri.toString() Coroutine.async { @@ -268,7 +282,8 @@ object BackupRestoreUi { data?.data?.let { uri -> App.INSTANCE.contentResolver.takePersistableUriPermission( uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + Intent.FLAG_GRANT_READ_URI_PERMISSION + or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) AppConfig.backupPath = uri.toString() }