From f31a5a082d184397fea07f8c6bbdcf1cfa11882e Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 6 Mar 2022 20:45:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=9B=AE=E5=BD=95=E7=95=8C?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/toc/ChapterListAdapter.kt | 19 ++++++++++++------- .../app/ui/book/toc/ChapterListFragment.kt | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) 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 6e62c907a..c882c5d2f 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 @@ -25,7 +25,7 @@ class ChapterListAdapter(context: Context, val callback: Callback) : DiffRecyclerAdapter(context) { val cacheFileNames = hashSetOf() - val displayTileMap = ConcurrentHashMap() + private val displayTitleMap = ConcurrentHashMap() override val diffItemCallback: DiffUtil.ItemCallback get() = object : DiffUtil.ItemCallback() { @@ -62,11 +62,16 @@ class ChapterListAdapter(context: Context, val callback: Callback) : override fun onCurrentListChanged() { super.onCurrentListChanged() - upDisplayTile() + upDisplayTitle() callback.onListChanged() } - fun upDisplayTile() { + fun clearDisplayTitle() { + upDisplayTileJob?.cancel() + displayTitleMap.clear() + } + + fun upDisplayTitle() { upDisplayTileJob?.cancel() upDisplayTileJob = Coroutine.async(callback.scope) { val replaceRules = replaceRules @@ -75,8 +80,8 @@ class ChapterListAdapter(context: Context, val callback: Callback) : if (!isActive) { return@async } - if (displayTileMap[it.index] == null) { - displayTileMap[it.index] = it.getDisplayTitle(replaceRules, useReplace) + if (displayTitleMap[it.index] == null) { + displayTitleMap[it.index] = it.getDisplayTitle(replaceRules, useReplace) } } } @@ -87,12 +92,12 @@ class ChapterListAdapter(context: Context, val callback: Callback) : } private fun getDisplayTile(chapter: BookChapter): String { - var displayTile = displayTileMap[chapter.index] + var displayTile = displayTitleMap[chapter.index] if (displayTile != null) { return displayTile } displayTile = chapter.getDisplayTitle(replaceRules, useReplace) - displayTileMap[chapter.index] = displayTile + displayTitleMap[chapter.index] = displayTile return displayTile } 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 35355f534..7dbe80e92 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 @@ -132,8 +132,8 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt } override fun clearDisplayTitle() { - adapter.displayTileMap.clear() - adapter.upDisplayTile() + adapter.clearDisplayTitle() + adapter.upDisplayTitle() } override val scope: CoroutineScope