From 5df6c303ad4f030c3fc2fb074a3a165916796f82 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 26 Oct 2021 14:43:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/main/explore/ExploreDiffCallBack.kt | 34 ------------------- .../main/explore/ExploreDiffItemCallBack.kt | 20 +++++++++++ .../app/ui/main/explore/ExploreFragment.kt | 6 +--- 3 files changed, 21 insertions(+), 39 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/ui/main/explore/ExploreDiffCallBack.kt create mode 100644 app/src/main/java/io/legado/app/ui/main/explore/ExploreDiffItemCallBack.kt diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreDiffCallBack.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreDiffCallBack.kt deleted file mode 100644 index 7f3c7d020..000000000 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreDiffCallBack.kt +++ /dev/null @@ -1,34 +0,0 @@ -package io.legado.app.ui.main.explore - -import androidx.recyclerview.widget.DiffUtil -import io.legado.app.data.entities.BookSource - - -class ExploreDiffCallBack( - private val oldItems: List, - private val newItems: List -) : - DiffUtil.Callback() { - - override fun getOldListSize(): Int { - return oldItems.size - } - - override fun getNewListSize(): Int { - return newItems.size - } - - override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { - return true - } - - override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { - val oldItem = oldItems[oldItemPosition] - val newItem = newItems[newItemPosition] - if (oldItem.bookSourceName != newItem.bookSourceName) { - return false - } - return true - } - -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreDiffItemCallBack.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreDiffItemCallBack.kt new file mode 100644 index 000000000..67d527d2a --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreDiffItemCallBack.kt @@ -0,0 +1,20 @@ +package io.legado.app.ui.main.explore + +import androidx.recyclerview.widget.DiffUtil +import io.legado.app.data.entities.BookSource + + +class ExploreDiffItemCallBack : DiffUtil.ItemCallback() { + + override fun areItemsTheSame(oldItem: BookSource, newItem: BookSource): Boolean { + return true + } + + override fun areContentsTheSame(oldItem: BookSource, newItem: BookSource): Boolean { + if (oldItem.bookSourceName != newItem.bookSourceName) { + return false + } + return true + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 65e61300a..80ccfef1d 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -9,7 +9,6 @@ import androidx.appcompat.widget.SearchView import androidx.core.view.isGone import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope -import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.R @@ -128,10 +127,7 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_explo } exploreFlow.collect { binding.tvEmptyMsg.isGone = it.isNotEmpty() || searchView.query.isNotEmpty() - val diffResult = DiffUtil - .calculateDiff(ExploreDiffCallBack(ArrayList(adapter.getItems()), it)) - adapter.setItems(it) - diffResult.dispatchUpdatesTo(adapter) + adapter.setItems(it, ExploreDiffItemCallBack()) } } }