feat: 修复bug

pull/238/head
gedoor 5 years ago
parent 2a3d8f3402
commit f26546be22
  1. 3
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  2. 57
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt

@ -82,6 +82,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.callBack?.upContent(resetPageOffset = false) ReadBook.callBack?.upContent(resetPageOffset = false)
} }
} }
if (ReadBook.inBookshelf) {
ReadBook.saveRead()
}
} }
} }

@ -16,54 +16,45 @@ class BooksDiffCallBack(private val oldItems: List<Book>, private val newItems:
} }
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
return oldItems[oldItemPosition].bookUrl == newItems[newItemPosition].bookUrl val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition]
return oldItem.name == newItem.name
&& oldItem.author == newItem.author
} }
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
val oldItem = oldItems[oldItemPosition] val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition] val newItem = newItems[newItemPosition]
if (oldItem.name != newItem.name) return when {
return false oldItem.durChapterTime != newItem.durChapterTime -> false
if (oldItem.author != newItem.author) oldItem.name != newItem.name -> false
return false oldItem.author != newItem.author -> false
if (oldItem.durChapterTitle != newItem.durChapterTitle) oldItem.durChapterTitle != newItem.durChapterTitle -> false
return false oldItem.latestChapterTitle != newItem.latestChapterTitle -> false
if (oldItem.latestChapterTitle != newItem.latestChapterTitle) oldItem.lastCheckCount != newItem.lastCheckCount -> false
return false oldItem.getDisplayCover() != newItem.getDisplayCover() -> false
if (oldItem.lastCheckCount != newItem.lastCheckCount) oldItem.getUnreadChapterNum() != newItem.getUnreadChapterNum() -> false
return false else -> true
if (oldItem.getDisplayCover() != newItem.getDisplayCover()) }
return false
if (oldItem.getUnreadChapterNum() != newItem.getUnreadChapterNum())
return false
return true
} }
override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? { override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? {
val oldItem = oldItems[oldItemPosition] val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition] val newItem = newItems[newItemPosition]
val bundle = bundleOf() val bundle = bundleOf()
if (oldItem.name != newItem.name) if (oldItem.name != newItem.name) bundle.putString("name", null)
bundle.putString("name", null) if (oldItem.author != newItem.author) bundle.putString("author", null)
if (oldItem.author != newItem.author) if (oldItem.durChapterTitle != newItem.durChapterTitle) bundle.putString("dur", null)
bundle.putString("author", null) if (oldItem.latestChapterTitle != newItem.latestChapterTitle) bundle.putString("last", null)
if (oldItem.durChapterTitle != newItem.durChapterTitle) if (oldItem.getDisplayCover() != newItem.getDisplayCover()) bundle.putString("cover", null)
bundle.putString("dur", null) if (oldItem.lastCheckCount != newItem.lastCheckCount) bundle.putString("refresh", null)
if (oldItem.latestChapterTitle != newItem.latestChapterTitle) if (oldItem.durChapterTime != newItem.durChapterTime
bundle.putString("last", null) || oldItem.getUnreadChapterNum() != newItem.getUnreadChapterNum()
if (oldItem.getDisplayCover() != newItem.getDisplayCover())
bundle.putString("cover", null)
if (oldItem.lastCheckCount != newItem.lastCheckCount)
bundle.putString("refresh", null)
if (oldItem.getUnreadChapterNum() != newItem.getUnreadChapterNum()
|| oldItem.lastCheckCount != newItem.lastCheckCount || oldItem.lastCheckCount != newItem.lastCheckCount
) { ) {
bundle.putString("refresh", null) bundle.putString("refresh", null)
} }
if (bundle.isEmpty) return null
if (bundle.isEmpty) {
return null
}
return bundle return bundle
} }

Loading…
Cancel
Save