diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index 4963fe860..ee0e50d23 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -118,13 +118,22 @@ class BookInfoEditActivity : } } else { registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { - RealPathUtil.getPath(this, uri)?.let { path -> - val imgFile = File(path) - if (imgFile.exists()) { - var file = this.externalFilesDir - file = FileUtils.createFileIfNotExist(file, "covers", imgFile.name) - file.writeBytes(imgFile.readBytes()) - coverChangeTo(file.absolutePath) + var hasPermission = true + it.forEach { (t, u) -> + if (!u) { + hasPermission = false + toastOnUi(t) + } + } + if (hasPermission) { + RealPathUtil.getPath(this, uri)?.let { path -> + val imgFile = File(path) + if (imgFile.exists()) { + var file = this.externalFilesDir + file = FileUtils.createFileIfNotExist(file, "covers", imgFile.name) + file.writeBytes(imgFile.readBytes()) + coverChangeTo(file.absolutePath) + } } } }.launch(Permissions.Group.STORAGE) diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt index 9cb291e96..5c5de45e5 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt @@ -149,10 +149,19 @@ class ImportBookActivity : VMBaseActivity { binding.tvEmptyMsg.visible() registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { - rootDoc = null - subDocs.clear() - path = lastPath - upPath() + var hasPermission = true + it.forEach { (t, u) -> + if (!u) { + hasPermission = false + toastOnUi(t) + } + } + if (hasPermission) { + rootDoc = null + subDocs.clear() + path = lastPath + upPath() + } }.launch(Permissions.Group.STORAGE) } } 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 17c067fd3..85cb3cb82 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 @@ -57,11 +57,20 @@ object BackupRestoreUi { path: String ) { fragment.registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { - Coroutine.async { - AppConfig.backupPath = path - Backup.backup(fragment.requireContext(), path) - }.onSuccess { - fragment.toastOnUi(R.string.backup_success) + var hasPermission = true + it.forEach { (t, u) -> + if (!u) { + hasPermission = false + fragment.toastOnUi(t) + } + } + if (hasPermission) { + Coroutine.async { + AppConfig.backupPath = path + Backup.backup(fragment.requireContext(), path) + }.onSuccess { + fragment.toastOnUi(R.string.backup_success) + } } }.launch(Permissions.Group.STORAGE) } diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 4f30f23a0..18eee75ae 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -280,15 +280,24 @@ class ThemeConfigFragment : BasePreferenceFragment(), } } else { registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { - RealPathUtil.getPath(requireContext(), uri)?.let { path -> - val imgFile = File(path) - if (imgFile.exists()) { - var file = requireContext().externalFilesDir - file = FileUtils.createFileIfNotExist(file, preferenceKey, imgFile.name) - file.writeBytes(imgFile.readBytes()) - putPrefString(preferenceKey, file.absolutePath) - upPreferenceSummary(preferenceKey, file.absolutePath) - success() + var hasPermission = true + it.forEach { (t, u) -> + if (!u) { + hasPermission = false + toastOnUi(t) + } + } + if (hasPermission) { + RealPathUtil.getPath(requireContext(), uri)?.let { path -> + val imgFile = File(path) + if (imgFile.exists()) { + var file = requireContext().externalFilesDir + file = FileUtils.createFileIfNotExist(file, preferenceKey, imgFile.name) + file.writeBytes(imgFile.readBytes()) + putPrefString(preferenceKey, file.absolutePath) + upPreferenceSummary(preferenceKey, file.absolutePath) + success() + } } } }.launch(Permissions.Group.STORAGE) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 8f6b7bf2f..e14f27591 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -163,7 +163,16 @@ class FontSelectDialog : BaseDialogFragment(), private fun loadFontFilesByPermission(path: String) { registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { - loadFontFiles(path) + var hasPermission = true + it.forEach { (t, u) -> + if (!u) { + hasPermission = false + toastOnUi(t) + } + } + if (hasPermission) { + loadFontFiles(path) + } }.launch(Permissions.Group.STORAGE) }