From 14ab6f8b4a17141e461daebf997496c23ebc5516 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 20 Oct 2021 23:57:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/widget/font/FontAdapter.kt | 10 +++++----- .../io/legado/app/ui/widget/font/FontSelectDialog.kt | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt index 7d4fe0ccb..ad526c69e 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt @@ -12,9 +12,12 @@ import timber.log.Timber import java.io.File import java.net.URLDecoder -class FontAdapter(context: Context, val callBack: CallBack) : +class FontAdapter(context: Context, curFilePath: String, val callBack: CallBack) : RecyclerAdapter(context) { + private val curName = URLDecoder.decode(curFilePath, "utf-8") + .substringAfterLast(File.separator) + override fun getViewBinding(parent: ViewGroup): ItemFontBinding { return ItemFontBinding.inflate(inflater, parent, false) } @@ -47,9 +50,7 @@ class FontAdapter(context: Context, val callBack: CallBack) : } tvFont.text = item.name root.setOnClickListener { callBack.onClick(item) } - if (item.name == URLDecoder.decode(callBack.curFilePath, "utf-8") - .substringAfterLast(File.separator) - ) { + if (item.name == curName) { ivChecked.visible() } else { ivChecked.invisible() @@ -67,6 +68,5 @@ class FontAdapter(context: Context, val callBack: CallBack) : interface CallBack { fun onClick(docItem: DocItem) - val curFilePath: String } } \ No newline at end of file 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 f67aff380..f055b22bd 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 @@ -36,7 +36,10 @@ class FontSelectDialog : BaseDialogFragment(R.layout.dialog_font_select), FileUtils.createFolderIfNotExist(appCtx.filesDir, "Fonts") } private val binding by viewBinding(DialogFontSelectBinding::bind) - private val adapter by lazy { FontAdapter(requireContext(), this) } + private val adapter by lazy { + val curFontPath = callBack?.curFontPath ?: "" + FontAdapter(requireContext(), curFontPath, this) + } private val selectFontDir = registerForActivityResult(HandleFileContract()) { uri -> uri ?: return@registerForActivityResult if (uri.toString().isContentScheme()) { @@ -229,8 +232,6 @@ class FontSelectDialog : BaseDialogFragment(R.layout.dialog_font_select), callBack?.selectFont("") } - override val curFilePath: String get() = callBack?.curFontPath ?: "" - private val callBack: CallBack? get() = (parentFragment as? CallBack) ?: (activity as? CallBack)