|
|
@ -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 |
|
|
@ -88,12 +90,8 @@ class FontSelectDialog : DialogFragment(), |
|
|
|
override fun onMenuItemClick(item: MenuItem?): Boolean { |
|
|
|
override fun onMenuItemClick(item: MenuItem?): Boolean { |
|
|
|
when (item?.itemId) { |
|
|
|
when (item?.itemId) { |
|
|
|
R.id.menu_default -> { |
|
|
|
R.id.menu_default -> { |
|
|
|
(parentFragment as? CallBack)?.let { |
|
|
|
val cb = (parentFragment as? CallBack) ?: (activity as? CallBack) |
|
|
|
if (it.curFontPath != "") { |
|
|
|
cb?.let { |
|
|
|
it.selectFile("") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
(activity as? CallBack)?.let { |
|
|
|
|
|
|
|
if (it.curFontPath != "") { |
|
|
|
if (it.curFontPath != "") { |
|
|
|
it.selectFile("") |
|
|
|
it.selectFile("") |
|
|
|
} |
|
|
|
} |
|
|
@ -129,15 +127,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,20 +166,20 @@ class FontSelectDialog : DialogFragment(), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onClick(file: File) { |
|
|
|
override fun onClick(file: File) { |
|
|
|
file.absolutePath.let { path -> |
|
|
|
launch(IO) { |
|
|
|
(parentFragment as? CallBack)?.let { |
|
|
|
file.copyTo(FileHelp.getFile(fontFolder + file.name), true).absolutePath.let { path -> |
|
|
|
|
|
|
|
val cb = (parentFragment as? CallBack) ?: (activity as? CallBack) |
|
|
|
|
|
|
|
cb?.let { |
|
|
|
if (it.curFontPath != path) { |
|
|
|
if (it.curFontPath != path) { |
|
|
|
|
|
|
|
withContext(Main) { |
|
|
|
it.selectFile(path) |
|
|
|
it.selectFile(path) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
(activity as? CallBack)?.let { |
|
|
|
|
|
|
|
if (it.curFontPath != path) { |
|
|
|
|
|
|
|
it.selectFile(path) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
dialog?.dismiss() |
|
|
|
dialog?.dismiss() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun curFilePath(): String { |
|
|
|
override fun curFilePath(): String { |
|
|
|
return (parentFragment as? CallBack)?.curFontPath |
|
|
|
return (parentFragment as? CallBack)?.curFontPath |
|
|
|