pull/66/head
kunfei 5 years ago
parent 8e0f4c7f81
commit fbd2e4573d
  1. 22
      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.R
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.FileHelp 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.DocumentUtils
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import io.legado.app.utils.putPrefString import io.legado.app.utils.putPrefString
@ -73,7 +75,11 @@ class FontSelectDialog : DialogFragment(),
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
startActivityForResult(intent, fontFolderRequestCode) startActivityForResult(intent, fontFolderRequestCode)
} catch (e: java.lang.Exception) { } 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)
@ -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) { override fun onClick(file: File) {
file.absolutePath.let { file.absolutePath.let {
if (it != curPath) { if (it != curPath) {

Loading…
Cancel
Save