From fbd2e4573dfc248d68b90f28e30ad4f34ee811a3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 15:52:56 +0800 Subject: [PATCH] up --- .../app/ui/widget/font/FontSelectDialog.kt | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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 714111062..194007e6c 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 @@ -16,6 +16,8 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.help.FileHelp +import io.legado.app.help.permission.Permissions +import io.legado.app.help.permission.PermissionsCompat import io.legado.app.utils.DocumentUtils import io.legado.app.utils.getPrefString import io.legado.app.utils.putPrefString @@ -73,7 +75,11 @@ class FontSelectDialog : DialogFragment(), 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() } } else { val uri = Uri.parse(fontPath) @@ -111,6 +117,20 @@ class FontSelectDialog : DialogFragment(), } } + @SuppressLint("DefaultLocale") + private fun getFontFilesOld() { + try { + val file = File(fontFolder) + file.listFiles { pathName -> + pathName.name.toLowerCase().matches(".*\\.[ot]tf".toRegex()) + }?.let { + adapter.setItems(it.toList()) + } + } catch (e: Exception) { + toast(e.localizedMessage ?: "") + } + } + override fun onClick(file: File) { file.absolutePath.let { if (it != curPath) {