pull/37/head
kunfei 5 years ago
parent 198a0bd502
commit ae3bcf98ec
  1. 34
      app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt
  2. 6
      app/src/main/java/io/legado/app/ui/main/bookshelf/BooksFragment.kt

@ -28,9 +28,10 @@ class BooksAdapter(private val callBack: CallBack) :
override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean =
oldItem.durChapterTitle == newItem.durChapterTitle
&& oldItem.name == newItem.name
&& oldItem.getDisplayCover() == newItem.getDisplayCover()
&& oldItem.latestChapterTitle == newItem.latestChapterTitle
&& oldItem.durChapterTime == newItem.durChapterTime
&& oldItem.lastCheckTime == newItem.lastCheckTime
&& oldItem.durChapterTitle == newItem.durChapterTitle
}
}
@ -38,7 +39,7 @@ class BooksAdapter(private val callBack: CallBack) :
for (i in 0 until itemCount) {
getItem(i)?.let {
if (it.bookUrl == bookUrl) {
notifyItemChanged(i)
notifyItemChanged(i, 5)
return
}
}
@ -52,6 +53,16 @@ class BooksAdapter(private val callBack: CallBack) :
)
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int, payloads: MutableList<Any>) {
if (payloads.isEmpty()) {
super.onBindViewHolder(holder, position, payloads)
} else {
currentList?.get(position)?.let {
holder.bind(it, callBack, payloads[0])
}
}
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
currentList?.get(position)?.let {
holder.bind(it, callBack)
@ -92,6 +103,23 @@ class BooksAdapter(private val callBack: CallBack) :
bv_unread.setHighlight(book.lastCheckCount > 0)
}
}
fun bind(book: Book, callBack: CallBack, payload: Any) = with(itemView) {
when (payload) {
5 -> {
if (book.origin != BookType.local && callBack.isUpdate(book.bookUrl)) {
LogUtils.d(book.name, "loading")
bv_unread.invisible()
rl_loading.show()
} else {
LogUtils.d(book.name, "loadingHide")
rl_loading.hide()
bv_unread.setBadgeCount(book.getUnreadChapterNum())
bv_unread.setHighlight(book.lastCheckCount > 0)
}
}
}
}
}
interface CallBack {

@ -78,15 +78,15 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
when (groupId) {
-1 -> {
bookshelfLiveData =
LivePagedListBuilder(App.db.bookDao().observeAll(), 10).build()
LivePagedListBuilder(App.db.bookDao().observeAll(), 100).build()
}
-2 -> {
bookshelfLiveData =
LivePagedListBuilder(App.db.bookDao().observeLocal(), 10).build()
LivePagedListBuilder(App.db.bookDao().observeLocal(), 100).build()
}
-3 -> {
bookshelfLiveData =
LivePagedListBuilder(App.db.bookDao().observeAudio(), 10).build()
LivePagedListBuilder(App.db.bookDao().observeAudio(), 100).build()
}
else -> {
bookshelfLiveData =

Loading…
Cancel
Save