pull/66/head
kunfei 5 years ago
parent fbd2e4573d
commit d1e25c9772
  1. 32
      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) {

Loading…
Cancel
Save