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 194007e6c..ca154a4ea 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 @@ -70,20 +70,14 @@ class FontSelectDialog : DialogFragment(), val fontPath = getPrefString(PreferKey.fontFolder) if (fontPath.isNullOrEmpty()) { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(intent, fontFolderRequestCode) - } catch (e: java.lang.Exception) { - PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { getFontFilesOld() } - .request() - } + openFolder() } else { val uri = Uri.parse(fontPath) - getFontFiles(uri) + if (DocumentFile.fromTreeUri(requireContext(), uri)?.canRead() == true) { + getFontFiles(uri) + } else { + openFolder() + } } } @@ -92,6 +86,20 @@ class FontSelectDialog : DialogFragment(), job.cancel() } + private fun openFolder() { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, fontFolderRequestCode) + } catch (e: java.lang.Exception) { + PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { getFontFilesOld() } + .request() + } + } + @SuppressLint("DefaultLocale") private fun getFontFiles(uri: Uri) { launch(IO) {