From a7d157db34c9fd6d432d87260ce5da11819d9c15 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 09:06:52 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/widget/font/FontSelectDialog.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 6ff51d379..8d3deef08 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 @@ -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)