pull/1876/head^2
kunfei 3 years ago
parent 019c54763e
commit d3d0e0e1d2
  1. 1
      app/src/main/assets/updateLog.md
  2. 45
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt

@ -14,6 +14,7 @@
**2022/05/11** **2022/05/11**
* 修复替换报错的bug * 修复替换报错的bug
* 优化目录界面替换
**2022/05/10** **2022/05/10**

@ -20,6 +20,7 @@ import io.legado.app.utils.longToastOnUi
import io.legado.app.utils.visible import io.legado.app.utils.visible
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.async
import kotlinx.coroutines.ensureActive import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
@ -79,30 +80,34 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
val replaceRules = replaceRules val replaceRules = replaceRules
val useReplace = useReplace val useReplace = useReplace
val items = getItems() val items = getItems()
for (i in startIndex until items.size) { async {
val item = items[i] for (i in startIndex until items.size) {
if (displayTitleMap[item.title] == null) { val item = items[i]
ensureActive() if (displayTitleMap[item.title] == null) {
val displayTitle = item.getDisplayTitle(replaceRules, useReplace) ensureActive()
ensureActive() val displayTitle = item.getDisplayTitle(replaceRules, useReplace)
displayTitleMap[item.title] = displayTitle ensureActive()
withContext(Main) { displayTitleMap[item.title] = displayTitle
notifyItemChanged(i, true) withContext(Main) {
notifyItemChanged(i, true)
}
} }
} }
} }.start()
for (i in 0 until startIndex) { async {
val item = items[i] for (i in startIndex downTo 0) {
if (displayTitleMap[item.title] == null) { val item = items[i]
ensureActive() if (displayTitleMap[item.title] == null) {
val displayTitle = item.getDisplayTitle(replaceRules, useReplace) ensureActive()
ensureActive() val displayTitle = item.getDisplayTitle(replaceRules, useReplace)
displayTitleMap[item.title] = displayTitle ensureActive()
withContext(Main) { displayTitleMap[item.title] = displayTitle
notifyItemChanged(i, true) withContext(Main) {
notifyItemChanged(i, true)
}
} }
} }
} }.start()
} }
} }

Loading…
Cancel
Save