From 572c5957a24f36cbdfe7f8ff6267d9f73c4c3ed1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 16:47:58 +0800 Subject: [PATCH] up --- .../app/ui/widget/font/FontSelectDialog.kt | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 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 ca154a4ea..4d726d973 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 @@ -38,10 +38,8 @@ class FontSelectDialog : DialogFragment(), lateinit var job: Job private val fontFolderRequestCode = 35485 private lateinit var adapter: FontAdapter - var curPath: String? = null private val fontFolder = App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator - var selectFile: ((path: String) -> Unit)? = null override val coroutineContext: CoroutineContext get() = job + Main @@ -141,15 +139,32 @@ class FontSelectDialog : DialogFragment(), override fun onClick(file: File) { file.absolutePath.let { - if (it != curPath) { - selectFile?.invoke(it) - dialog?.dismiss() + val pf = parentFragment + if (pf is CallBack) { + if (it != pf.curPath) { + pf.selectFile(it) + } + } + val activity = activity + if (activity is CallBack) { + if (it != activity.curPath) { + activity.selectFile(it) + } } } + dialog?.dismiss() } override fun curFilePath(): String { - return curPath ?: "" + val pf = parentFragment + if (pf is CallBack) { + return pf.curPath + } + val activity = activity + if (activity is CallBack) { + return activity.curPath + } + return "" } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { @@ -169,6 +184,7 @@ class FontSelectDialog : DialogFragment(), } interface CallBack { - fun selectFile(uri: Uri) + fun selectFile(path: String) + val curPath: String } } \ No newline at end of file