|
|
@ -70,20 +70,14 @@ class FontSelectDialog : DialogFragment(), |
|
|
|
|
|
|
|
|
|
|
|
val fontPath = getPrefString(PreferKey.fontFolder) |
|
|
|
val fontPath = getPrefString(PreferKey.fontFolder) |
|
|
|
if (fontPath.isNullOrEmpty()) { |
|
|
|
if (fontPath.isNullOrEmpty()) { |
|
|
|
try { |
|
|
|
openFolder() |
|
|
|
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() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val uri = Uri.parse(fontPath) |
|
|
|
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() |
|
|
|
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") |
|
|
|
@SuppressLint("DefaultLocale") |
|
|
|
private fun getFontFiles(uri: Uri) { |
|
|
|
private fun getFontFiles(uri: Uri) { |
|
|
|
launch(IO) { |
|
|
|
launch(IO) { |
|
|
|