From f26546be22a79f9c9b502edb420af4765e153339 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 6 Jun 2020 16:43:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/ReadBookViewModel.kt | 3 + .../main/bookshelf/books/BooksDiffCallBack.kt | 57 ++++++++----------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index a4755213d..93322a998 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -82,6 +82,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { ReadBook.callBack?.upContent(resetPageOffset = false) } } + if (ReadBook.inBookshelf) { + ReadBook.saveRead() + } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt index 27954c634..130847312 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt @@ -16,54 +16,45 @@ class BooksDiffCallBack(private val oldItems: List, private val newItems: } 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 { val oldItem = oldItems[oldItemPosition] val newItem = newItems[newItemPosition] - 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 + return when { + oldItem.durChapterTime != newItem.durChapterTime -> false + oldItem.name != newItem.name -> false + oldItem.author != newItem.author -> false + oldItem.durChapterTitle != newItem.durChapterTitle -> false + oldItem.latestChapterTitle != newItem.latestChapterTitle -> false + oldItem.lastCheckCount != newItem.lastCheckCount -> false + oldItem.getDisplayCover() != newItem.getDisplayCover() -> false + oldItem.getUnreadChapterNum() != newItem.getUnreadChapterNum() -> false + else -> 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("dur", null) - if (oldItem.latestChapterTitle != newItem.latestChapterTitle) - bundle.putString("last", null) - if (oldItem.getDisplayCover() != newItem.getDisplayCover()) - bundle.putString("cover", null) - if (oldItem.lastCheckCount != newItem.lastCheckCount) - bundle.putString("refresh", null) - if (oldItem.getUnreadChapterNum() != newItem.getUnreadChapterNum() + 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("dur", null) + if (oldItem.latestChapterTitle != newItem.latestChapterTitle) bundle.putString("last", null) + if (oldItem.getDisplayCover() != newItem.getDisplayCover()) bundle.putString("cover", null) + if (oldItem.lastCheckCount != newItem.lastCheckCount) bundle.putString("refresh", null) + if (oldItem.durChapterTime != newItem.durChapterTime + || oldItem.getUnreadChapterNum() != newItem.getUnreadChapterNum() || oldItem.lastCheckCount != newItem.lastCheckCount ) { bundle.putString("refresh", null) } - - if (bundle.isEmpty) { - return null - } + if (bundle.isEmpty) return null return bundle }