From d3d0e0e1d238781848d3300ad7b9e03bd28acab9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 11 May 2022 20:16:13 +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 --- app/src/main/assets/updateLog.md | 1 + .../app/ui/book/toc/ChapterListAdapter.kt | 45 ++++++++++--------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 1620106bb..8e4d4ac7e 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -14,6 +14,7 @@ **2022/05/11** * 修复替换报错的bug +* 优化目录界面替换 **2022/05/10** 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 1bc59c305..4d20a8002 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 @@ -20,6 +20,7 @@ import io.legado.app.utils.longToastOnUi import io.legado.app.utils.visible import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.Main +import kotlinx.coroutines.async import kotlinx.coroutines.ensureActive import kotlinx.coroutines.withContext import java.util.concurrent.ConcurrentHashMap @@ -79,30 +80,34 @@ class ChapterListAdapter(context: Context, val callback: Callback) : val replaceRules = replaceRules val useReplace = useReplace val items = getItems() - for (i in startIndex until items.size) { - val item = items[i] - if (displayTitleMap[item.title] == null) { - ensureActive() - val displayTitle = item.getDisplayTitle(replaceRules, useReplace) - ensureActive() - displayTitleMap[item.title] = displayTitle - withContext(Main) { - notifyItemChanged(i, true) + async { + for (i in startIndex until items.size) { + val item = items[i] + if (displayTitleMap[item.title] == null) { + ensureActive() + val displayTitle = item.getDisplayTitle(replaceRules, useReplace) + ensureActive() + displayTitleMap[item.title] = displayTitle + withContext(Main) { + notifyItemChanged(i, true) + } } } - } - for (i in 0 until startIndex) { - val item = items[i] - if (displayTitleMap[item.title] == null) { - ensureActive() - val displayTitle = item.getDisplayTitle(replaceRules, useReplace) - ensureActive() - displayTitleMap[item.title] = displayTitle - withContext(Main) { - notifyItemChanged(i, true) + }.start() + async { + for (i in startIndex downTo 0) { + val item = items[i] + if (displayTitleMap[item.title] == null) { + ensureActive() + val displayTitle = item.getDisplayTitle(replaceRules, useReplace) + ensureActive() + displayTitleMap[item.title] = displayTitle + withContext(Main) { + notifyItemChanged(i, true) + } } } - } + }.start() } }