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

Loading…
Cancel
Save