From ae3bcf98ec7a40ee9eed4030b48f4c900265a02b Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 14 Oct 2019 08:33:50 +0800 Subject: [PATCH] up --- .../app/ui/main/bookshelf/BooksAdapter.kt | 34 +++++++++++++++++-- .../app/ui/main/bookshelf/BooksFragment.kt | 6 ++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt index ccb7731d6..00e8a81a8 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.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) { + 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 { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksFragment.kt index f867948d1..6575d4933 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksFragment.kt @@ -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 =