pull/94/head
kunfei 5 years ago
parent aa49a88b76
commit 64cb64dc6e
  1. 3
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BaseBooksAdapter.kt
  2. 15
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt
  3. 47
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt

@ -1,6 +1,7 @@
package io.legado.app.ui.main.bookshelf.books
import android.content.Context
import androidx.core.os.bundleOf
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.Book
@ -11,7 +12,7 @@ abstract class BaseBooksAdapter(context: Context, layoutId: Int) :
for (i in 0 until itemCount) {
getItem(i)?.let {
if (it.bookUrl == bookUrl) {
notifyItemChanged(i, 5)
notifyItemChanged(i, bundleOf(Pair("refresh", null)))
return
}
}

@ -1,6 +1,7 @@
package io.legado.app.ui.main.bookshelf.books
import android.content.Context
import android.os.Bundle
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.constant.BookType
@ -15,8 +16,9 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) :
BaseBooksAdapter(context, R.layout.item_bookshelf_list) {
override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList<Any>) {
val bundle = payloads.getOrNull(0) as? Bundle
with(holder.itemView) {
if (payloads.isEmpty()) {
if (bundle == null) {
ATH.applyBackgroundTint(this)
tv_name.text = item.name
tv_author.text = item.author
@ -37,9 +39,14 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) :
bv_unread.setHighlight(item.lastCheckCount > 0)
}
} else {
when (payloads[0]) {
5 -> {
if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) {
bundle.keySet().map {
when (it) {
"name" -> tv_name.text = item.name
"author" -> tv_author.text = item.author
"durTitle" -> tv_read.text = item.durChapterTitle
"latestTitle" -> tv_last.text = item.latestChapterTitle
"cover" -> iv_cover.load(item.getDisplayCover(), item.name, item.author)
"refresh" -> if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) {
bv_unread.invisible()
rl_loading.show()
} else {

@ -1,5 +1,6 @@
package io.legado.app.ui.main.bookshelf.books
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.DiffUtil
import io.legado.app.data.entities.Book
@ -22,13 +23,45 @@ class BooksDiffCallBack(private val oldItems: List<Book>, private val newItems:
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition]
return oldItem.name == newItem.name
&& oldItem.author == newItem.author
&& oldItem.durChapterTitle == newItem.durChapterTitle
&& oldItem.latestChapterTitle == newItem.latestChapterTitle
&& oldItem.getDisplayCover() == newItem.getDisplayCover()
&& oldItem.getUnreadChapterNum() == newItem.getUnreadChapterNum()
&& oldItem.lastCheckCount == newItem.lastCheckCount
if (oldItem.name != newItem.name)
return false
if (oldItem.author != newItem.author)
return false
if (oldItem.durChapterTitle != newItem.durChapterTitle)
return false
if (oldItem.latestChapterTitle != newItem.latestChapterTitle)
return false
if (oldItem.lastCheckCount != newItem.lastCheckCount)
return false
if (oldItem.getDisplayCover() != newItem.getDisplayCover())
return false
if (oldItem.getUnreadChapterNum() != newItem.getUnreadChapterNum())
return false
return true
}
override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? {
val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition]
val bundle = bundleOf()
if (oldItem.name != newItem.name)
bundle.putString("name", null)
if (oldItem.author != newItem.author)
bundle.putString("author", null)
if (oldItem.durChapterTitle != newItem.durChapterTitle)
bundle.putString("durTitle", null)
if (oldItem.latestChapterTitle != newItem.latestChapterTitle)
bundle.putString("latestTitle", null)
if (oldItem.getDisplayCover() != newItem.getDisplayCover())
bundle.putString("cover", null)
if (oldItem.getUnreadChapterNum() != newItem.getUnreadChapterNum()
|| oldItem.lastCheckCount != newItem.lastCheckCount
)
bundle.putString("refresh", null)
if (bundle.isEmpty) {
return null
}
return bundle
}
}
Loading…
Cancel
Save