pull/1072/head
gedoor 3 years ago
parent c8be3a3e74
commit e1b38ac694
  1. 15
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  2. 52
      app/src/main/java/io/legado/app/ui/book/info/ChapterListAdapter.kt
  3. 6
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt

@ -46,7 +46,6 @@ import kotlinx.coroutines.withContext
class BookInfoActivity : class BookInfoActivity :
VMBaseActivity<ActivityBookInfoBinding, BookInfoViewModel>(toolBarTheme = Theme.Dark), VMBaseActivity<ActivityBookInfoBinding, BookInfoViewModel>(toolBarTheme = Theme.Dark),
GroupSelectDialog.CallBack, GroupSelectDialog.CallBack,
ChapterListAdapter.CallBack,
ChangeSourceDialog.CallBack, ChangeSourceDialog.CallBack,
ChangeCoverDialog.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) { override fun upGroup(requestCode: Int, groupId: Long) {
upGroup(groupId) upGroup(groupId)
viewModel.bookData.value?.group = groupId viewModel.bookData.value?.group = groupId

@ -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<BookChapter, ItemChapterListBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemChapterListBinding {
return ItemChapterListBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemChapterListBinding,
item: BookChapter,
payloads: MutableList<Any>
) {
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
}
}

@ -77,7 +77,7 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
private fun initBook(book: Book) { private fun initBook(book: Book) {
launch { launch {
initDoc() initToc()
durChapterIndex = book.durChapterIndex durChapterIndex = book.durChapterIndex
binding.tvCurrentChapterInfo.text = binding.tvCurrentChapterInfo.text =
"${book.durChapterTitle}(${book.durChapterIndex + 1}/${book.totalChapterNum})" "${book.durChapterTitle}(${book.durChapterIndex + 1}/${book.totalChapterNum})"
@ -85,7 +85,7 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
} }
} }
private fun initDoc() { private fun initToc() {
tocLiveData?.removeObservers(this@ChapterListFragment) tocLiveData?.removeObservers(this@ChapterListFragment)
tocLiveData = appDb.bookChapterDao.observeByBook(viewModel.bookUrl) tocLiveData = appDb.bookChapterDao.observeByBook(viewModel.bookUrl)
tocLiveData?.observe(viewLifecycleOwner, { tocLiveData?.observe(viewLifecycleOwner, {
@ -119,7 +119,7 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
override fun startChapterListSearch(newText: String?) { override fun startChapterListSearch(newText: String?) {
if (newText.isNullOrBlank()) { if (newText.isNullOrBlank()) {
initDoc() initToc()
} else { } else {
tocLiveData?.removeObservers(this) tocLiveData?.removeObservers(this)
tocLiveData = appDb.bookChapterDao.liveDataSearch(viewModel.bookUrl, newText) tocLiveData = appDb.bookChapterDao.liveDataSearch(viewModel.bookUrl, newText)

Loading…
Cancel
Save