From e885c30cacaa5a20fa914717e96aa2c2e16abe98 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 10 Feb 2022 16:56:44 +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 --- .../java/io/legado/app/ui/book/toc/ChapterListAdapter.kt | 5 +++-- .../java/io/legado/app/ui/book/toc/ChapterListFragment.kt | 5 ++++- 2 files changed, 7 insertions(+), 3 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 9a9cfa421..8072f2d70 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 @@ -17,7 +17,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Deferred import kotlinx.coroutines.launch -class ChapterListAdapter(context: Context, val callback: Callback, private val scope: CoroutineScope) : +class ChapterListAdapter(context: Context, val callback: Callback) : RecyclerAdapter>, ItemChapterListBinding>(context) { val cacheFileNames = hashSetOf() @@ -64,7 +64,7 @@ class ChapterListAdapter(context: Context, val callback: Callback, private val s } else { tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText)) } - scope.launch { + callback.scope.launch { tvChapterName.text = item.second.await() } if (item.first.isVolume) { @@ -108,6 +108,7 @@ class ChapterListAdapter(context: Context, val callback: Callback, private val s } interface Callback { + val scope: CoroutineScope val isLocalBook: Boolean fun openChapter(bookChapter: BookChapter) fun durChapterIndex(): Int 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 3fd41aec9..338c454ff 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 @@ -33,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, this) } + private val adapter by lazy { ChapterListAdapter(requireContext(), this) } private var durChapterIndex = 0 private var tocFlowJob: Job? = null @@ -136,6 +136,9 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt } } + override val scope: CoroutineScope + get() = this + override val isLocalBook: Boolean get() = viewModel.bookData.value?.isLocalBook() == true