From 9c28737a4033acfed5e792bf6701666cce56eb6a Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 9 Feb 2022 21:27:33 +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 --- .../io/legado/app/data/entities/BookChapter.kt | 3 ++- .../legado/app/ui/book/toc/ChapterListAdapter.kt | 14 ++++++++++---- .../legado/app/ui/book/toc/ChapterListFragment.kt | 3 +-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt index ac5718872..8258151dd 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt @@ -16,7 +16,6 @@ import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.Parcelize import splitties.init.appCtx -@Suppress("unused") @Parcelize @Entity( tableName = "chapters", @@ -124,8 +123,10 @@ data class BookChapter( } } + @Suppress("unused") fun getFileName(): String = String.format("%05d-%s.nb", index, MD5Utils.md5Encode16(title)) + @Suppress("unused") fun getFontName(): String = String.format("%05d-%s.ttf", index, MD5Utils.md5Encode16(title)) } diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt index 5dd420649..5868981ec 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt @@ -10,20 +10,22 @@ import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.databinding.ItemChapterListBinding import io.legado.app.help.ContentProcessor +import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.theme.ThemeUtils import io.legado.app.lib.theme.accentColor import io.legado.app.utils.getCompatColor import io.legado.app.utils.gone import io.legado.app.utils.visible +import kotlinx.coroutines.CoroutineScope -class ChapterListAdapter(context: Context, val callback: Callback) : +class ChapterListAdapter(context: Context, private val scope: CoroutineScope, val callback: Callback) : RecyclerAdapter(context) { - val replaceRules + private val replaceRules get() = callback.book?.let { ContentProcessor.get(it.name, it.origin).getReplaceRules() } - val useReplace get() = callback.book?.getUseReplaceRule() == true + private val useReplace get() = callback.book?.getUseReplaceRule() == true val cacheFileNames = hashSetOf() val diffCallBack = object : DiffUtil.ItemCallback() { @@ -62,7 +64,11 @@ class ChapterListAdapter(context: Context, val callback: Callback) : } else { tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText)) } - tvChapterName.text = item.getDisplayTitle(replaceRules, useReplace) + Coroutine.async(scope) { + item.getDisplayTitle(replaceRules, useReplace) + }.onSuccess { + tvChapterName.text = it + } if (item.isVolume) { //卷名,如第一卷 突出显示 tvChapterItem.setBackgroundColor(context.getCompatColor(R.color.btn_bg_press)) diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt index d3154e64f..64c65f80a 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt @@ -24,7 +24,6 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Job -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -34,7 +33,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt override val viewModel by activityViewModels() private val binding by viewBinding(FragmentChapterListBinding::bind) private val mLayoutManager by lazy { UpLinearLayoutManager(requireContext()) } - private val adapter by lazy { ChapterListAdapter(requireContext(), this) } + private val adapter by lazy { ChapterListAdapter(requireContext(), this, this) } private var durChapterIndex = 0 private var tocFlowJob: Job? = null