pull/71/head^2^2
kunfei 5 years ago
parent ede7b0a62b
commit a7d157db34
  1. 9
      app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt

@ -43,6 +43,8 @@ class FontSelectDialog : DialogFragment(),
private val fontFolderRequestCode = 35485
private val fontFolder =
App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator
private val fontCacheFolder =
App.INSTANCE.cacheDir.absolutePath + File.separator + "Fonts" + File.separator
override val coroutineContext: CoroutineContext
get() = job + Main
private var adapter: FontAdapter? = null
@ -129,15 +131,16 @@ class FontSelectDialog : DialogFragment(),
@SuppressLint("DefaultLocale")
private fun getFontFiles(uri: Uri) {
launch(IO) {
FileHelp.deleteFile(fontCacheFolder)
DocumentFile.fromTreeUri(App.INSTANCE, uri)?.listFiles()?.forEach { file ->
if (file.name?.toLowerCase()?.matches(".*\\.[ot]tf".toRegex()) == true) {
DocumentUtils.readBytes(App.INSTANCE, file.uri)?.let {
FileHelp.getFile(fontFolder + file.name).writeBytes(it)
FileHelp.getFile(fontCacheFolder + file.name).writeBytes(it)
}
}
}
try {
val file = File(fontFolder)
val file = File(fontCacheFolder)
file.listFiles { pathName ->
pathName.name.toLowerCase().matches(".*\\.[ot]tf".toRegex())
}?.let {
@ -167,7 +170,7 @@ class FontSelectDialog : DialogFragment(),
}
override fun onClick(file: File) {
file.absolutePath.let { path ->
file.copyTo(FileHelp.getFile(fontFolder + file.name)).absolutePath.let { path ->
(parentFragment as? CallBack)?.let {
if (it.curFontPath != path) {
it.selectFile(path)

Loading…
Cancel
Save