pull/32/head
kunfei 5 years ago
parent ef52d44209
commit e26532ec7f
  1. 12
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListAdapter.kt
  2. 4
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt

@ -7,7 +7,9 @@ import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R import io.legado.app.R
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.help.BookHelp
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 kotlinx.android.synthetic.main.item_bookmark.view.* import kotlinx.android.synthetic.main.item_bookmark.view.*
@ -41,9 +43,9 @@ class ChapterListAdapter(val callback: Callback) :
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(bookChapter: BookChapter, callback: Callback?) = with(itemView) { fun bind(bookChapter: BookChapter, callback: Callback) = with(itemView) {
tv_chapter_name.text = bookChapter.title tv_chapter_name.text = bookChapter.title
callback?.let { callback.let {
if (it.durChapterIndex() == bookChapter.index) { if (it.durChapterIndex() == bookChapter.index) {
tv_chapter_name.setTextColor(context.accentColor) tv_chapter_name.setTextColor(context.accentColor)
} else { } else {
@ -51,12 +53,16 @@ class ChapterListAdapter(val callback: Callback) :
} }
} }
itemView.onClick { itemView.onClick {
callback?.openChapter(bookChapter) callback.openChapter(bookChapter)
}
callback.book()?.let {
tv_chapter_name.paint.isFakeBoldText = BookHelp.hasContent(it, bookChapter)
} }
} }
} }
interface Callback { interface Callback {
fun book(): Book?
fun openChapter(bookChapter: BookChapter) fun openChapter(bookChapter: BookChapter)
fun durChapterIndex(): Int fun durChapterIndex(): Int
} }

@ -87,4 +87,8 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
postEvent(Bus.OPEN_CHAPTER, bookChapter) postEvent(Bus.OPEN_CHAPTER, bookChapter)
activity?.finish() activity?.finish()
} }
override fun book(): Book? {
return viewModel.bookDate.value
}
} }
Loading…
Cancel
Save