From e1b38ac694ba8a803df956272c056e79f2fa32df Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 19 Jun 2021 18:46:57 +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/ui/book/info/BookInfoActivity.kt | 15 ------ .../app/ui/book/info/ChapterListAdapter.kt | 52 ------------------- .../app/ui/book/toc/ChapterListFragment.kt | 6 +-- 3 files changed, 3 insertions(+), 70 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/ui/book/info/ChapterListAdapter.kt diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 51d23caaa..1b647aa7c 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -46,7 +46,6 @@ import kotlinx.coroutines.withContext class BookInfoActivity : VMBaseActivity(toolBarTheme = Theme.Dark), GroupSelectDialog.CallBack, - ChapterListAdapter.CallBack, ChangeSourceDialog.CallBack, ChangeCoverDialog.CallBack { @@ -393,20 +392,6 @@ class BookInfoActivity : } } - override fun openChapter(chapter: BookChapter) { - if (chapter.index != viewModel.durChapterIndex) { - viewModel.bookData.value?.let { - it.durChapterIndex = chapter.index - it.durChapterPos = 0 - readBook(it) - } - } - } - - override fun durChapterIndex(): Int { - return viewModel.durChapterIndex - } - override fun upGroup(requestCode: Int, groupId: Long) { upGroup(groupId) viewModel.bookData.value?.group = groupId diff --git a/app/src/main/java/io/legado/app/ui/book/info/ChapterListAdapter.kt b/app/src/main/java/io/legado/app/ui/book/info/ChapterListAdapter.kt deleted file mode 100644 index dde20e3e8..000000000 --- a/app/src/main/java/io/legado/app/ui/book/info/ChapterListAdapter.kt +++ /dev/null @@ -1,52 +0,0 @@ -package io.legado.app.ui.book.info - -import android.content.Context -import android.view.ViewGroup -import io.legado.app.R -import io.legado.app.base.adapter.ItemViewHolder -import io.legado.app.base.adapter.RecyclerAdapter -import io.legado.app.data.entities.BookChapter -import io.legado.app.databinding.ItemChapterListBinding -import io.legado.app.lib.theme.accentColor -import io.legado.app.utils.getCompatColor - - -class ChapterListAdapter(context: Context, var callBack: CallBack) : - RecyclerAdapter(context) { - - override fun getViewBinding(parent: ViewGroup): ItemChapterListBinding { - return ItemChapterListBinding.inflate(inflater, parent, false) - } - - override fun convert( - holder: ItemViewHolder, - binding: ItemChapterListBinding, - item: BookChapter, - payloads: MutableList - ) { - with(binding) { - tvChapterName.text = item.title - if (item.index == callBack.durChapterIndex()) { - tvChapterName.setTextColor(context.accentColor) - } else { - tvChapterName.setTextColor(context.getCompatColor(R.color.secondaryText)) - } - - } - } - - override fun registerListener(holder: ItemViewHolder, binding: ItemChapterListBinding) { - holder.itemView.apply { - this.setOnClickListener { - getItem(holder.layoutPosition)?.let { - callBack.openChapter(it) - } - } - } - } - - interface CallBack { - fun openChapter(chapter: BookChapter) - fun durChapterIndex(): Int - } -} \ No newline at end of file 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 63e18bf22..62af4a8d2 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 @@ -77,7 +77,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt @SuppressLint("SetTextI18n") private fun initBook(book: Book) { launch { - initDoc() + initToc() durChapterIndex = book.durChapterIndex binding.tvCurrentChapterInfo.text = "${book.durChapterTitle}(${book.durChapterIndex + 1}/${book.totalChapterNum})" @@ -85,7 +85,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt } } - private fun initDoc() { + private fun initToc() { tocLiveData?.removeObservers(this@ChapterListFragment) tocLiveData = appDb.bookChapterDao.observeByBook(viewModel.bookUrl) tocLiveData?.observe(viewLifecycleOwner, { @@ -119,7 +119,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt override fun startChapterListSearch(newText: String?) { if (newText.isNullOrBlank()) { - initDoc() + initToc() } else { tocLiveData?.removeObservers(this) tocLiveData = appDb.bookChapterDao.liveDataSearch(viewModel.bookUrl, newText)