From d1e25c9772ccd6610630d2968382456050139b6c Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 16:23:13 +0800 Subject: [PATCH] up --- .../app/ui/widget/font/FontSelectDialog.kt | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) 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) {