This commit is contained in:
kunfei 2022-02-09 21:27:33 +08:00
parent d4a99ea5df
commit 9c28737a40
3 changed files with 13 additions and 7 deletions

View File

@ -16,7 +16,6 @@ import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
import splitties.init.appCtx import splitties.init.appCtx
@Suppress("unused")
@Parcelize @Parcelize
@Entity( @Entity(
tableName = "chapters", tableName = "chapters",
@ -124,8 +123,10 @@ data class BookChapter(
} }
} }
@Suppress("unused")
fun getFileName(): String = String.format("%05d-%s.nb", index, MD5Utils.md5Encode16(title)) 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)) fun getFontName(): String = String.format("%05d-%s.ttf", index, MD5Utils.md5Encode16(title))
} }

View File

@ -10,20 +10,22 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.databinding.ItemChapterListBinding import io.legado.app.databinding.ItemChapterListBinding
import io.legado.app.help.ContentProcessor 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.ThemeUtils
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.visible 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<BookChapter, ItemChapterListBinding>(context) { RecyclerAdapter<BookChapter, ItemChapterListBinding>(context) {
val replaceRules private val replaceRules
get() = callback.book?.let { get() = callback.book?.let {
ContentProcessor.get(it.name, it.origin).getReplaceRules() 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<String>() val cacheFileNames = hashSetOf<String>()
val diffCallBack = object : DiffUtil.ItemCallback<BookChapter>() { val diffCallBack = object : DiffUtil.ItemCallback<BookChapter>() {
@ -62,7 +64,11 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
} else { } else {
tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText)) 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) { if (item.isVolume) {
//卷名,如第一卷 突出显示 //卷名,如第一卷 突出显示
tvChapterItem.setBackgroundColor(context.getCompatColor(R.color.btn_bg_press)) tvChapterItem.setBackgroundColor(context.getCompatColor(R.color.btn_bg_press))

View File

@ -24,7 +24,6 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@ -34,7 +33,7 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
override val viewModel by activityViewModels<TocViewModel>() override val viewModel by activityViewModels<TocViewModel>()
private val binding by viewBinding(FragmentChapterListBinding::bind) private val binding by viewBinding(FragmentChapterListBinding::bind)
private val mLayoutManager by lazy { UpLinearLayoutManager(requireContext()) } 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 durChapterIndex = 0
private var tocFlowJob: Job? = null private var tocFlowJob: Job? = null