From f876dbce2089cc234abb42407d52bf88df9986bc Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 16:57:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/widget/font/FontSelectDialog.kt | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 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 0e2f21213..6732bf985 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 @@ -89,17 +89,14 @@ class FontSelectDialog : BaseDialogFragment(), override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { R.id.menu_default -> { - val cb = (parentFragment as? CallBack) ?: (activity as? CallBack) - cb?.let { - val requireContext = requireContext() - requireContext.alert(titleResource = R.string.system_typeface) { - items(requireContext.resources.getStringArray(R.array.system_typefaces).toList()) { _, i -> - AppConfig.systemTypefaces = i - onDefaultFontChange(it) - } - }.show() - } - dismiss() + val requireContext = requireContext() + requireContext.alert(titleResource = R.string.system_typeface) { + items(requireContext.resources.getStringArray(R.array.system_typefaces).toList()) { _, i -> + AppConfig.systemTypefaces = i + onDefaultFontChange() + dismiss() + } + }.show() } R.id.menu_other -> { openFolder() @@ -212,12 +209,9 @@ class FontSelectDialog : BaseDialogFragment(), launch(IO) { file.copyTo(FileUtils.createFileIfNotExist(fontFolder, file.name), true) .absolutePath.let { path -> - val cb = (parentFragment as? CallBack) ?: (activity as? CallBack) - cb?.let { - if (it.curFontPath != path) { - withContext(Main) { - it.selectFile(path) - } + if (callBack?.curFontPath != path) { + withContext(Main) { + callBack?.selectFile(path) } } } @@ -226,9 +220,7 @@ class FontSelectDialog : BaseDialogFragment(), } override fun curFilePath(): String { - return (parentFragment as? CallBack)?.curFontPath - ?: (activity as? CallBack)?.curFontPath - ?: "" + return callBack?.curFontPath ?: "" } override fun onFilePicked(requestCode: Int, currentPath: String) { @@ -263,14 +255,17 @@ class FontSelectDialog : BaseDialogFragment(), } } - private fun onDefaultFontChange(callBack: CallBack) { + private fun onDefaultFontChange() { if (curFilePath() == "") { postEvent(EventBus.UP_CONFIG, true) } else { - callBack.selectFile("") + callBack?.selectFile("") } } + private val callBack: CallBack? + get() = (parentFragment as? CallBack) ?: (activity as? CallBack) + interface CallBack { fun selectFile(path: String) val curFontPath: String