diff --git a/app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt b/app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt similarity index 98% rename from app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt rename to app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt index d684449a4..ea96c3b61 100644 --- a/app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt +++ b/app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt @@ -15,7 +15,7 @@ import kotlin.collections.ArrayList * Created by Invincible on 2017/12/15. */ @Suppress("unused") -abstract class SimpleRecyclerAdapter(protected val context: Context) : +abstract class DiffRecyclerAdapter(protected val context: Context) : RecyclerView.Adapter() { val inflater: LayoutInflater = LayoutInflater.from(context) diff --git a/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt index 6132ca3dd..6801e0ebc 100644 --- a/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt @@ -3,14 +3,14 @@ package io.legado.app.ui.book.changecover import android.content.Context import android.view.ViewGroup import androidx.recyclerview.widget.DiffUtil +import io.legado.app.base.adapter.DiffRecyclerAdapter import io.legado.app.base.adapter.ItemViewHolder -import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.SearchBook import io.legado.app.databinding.ItemCoverBinding import org.jetbrains.anko.sdk27.listeners.onClick class CoverAdapter(context: Context, val callBack: CallBack) : - SimpleRecyclerAdapter(context) { + DiffRecyclerAdapter(context) { override val diffItemCallback: DiffUtil.ItemCallback get() = object : DiffUtil.ItemCallback() { diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt index 48a9dfcc1..2db9cb239 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt @@ -7,8 +7,8 @@ import android.view.ViewGroup import androidx.appcompat.widget.PopupMenu import androidx.recyclerview.widget.DiffUtil import io.legado.app.R +import io.legado.app.base.adapter.DiffRecyclerAdapter import io.legado.app.base.adapter.ItemViewHolder -import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.SearchBook import io.legado.app.databinding.ItemChangeSourceBinding import io.legado.app.utils.invisible @@ -18,7 +18,7 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick class ChangeSourceAdapter(context: Context, val callBack: CallBack) : - SimpleRecyclerAdapter(context) { + DiffRecyclerAdapter(context) { override val diffItemCallback: DiffUtil.ItemCallback get() = object : DiffUtil.ItemCallback() { diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index d0d237f7d..0e93876d9 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -16,8 +16,8 @@ import androidx.recyclerview.widget.RecyclerView import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseDialogFragment +import io.legado.app.base.adapter.DiffRecyclerAdapter import io.legado.app.base.adapter.ItemViewHolder -import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.BookGroup import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogRecyclerViewBinding @@ -137,7 +137,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } private inner class GroupAdapter(context: Context) : - SimpleRecyclerAdapter(context), + DiffRecyclerAdapter(context), ItemTouchCallback.Callback { private var isMoved = false diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index c3d77b2fe..732a5de4e 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -5,8 +5,8 @@ import android.os.Bundle import android.view.ViewGroup import androidx.recyclerview.widget.DiffUtil import io.legado.app.R +import io.legado.app.base.adapter.DiffRecyclerAdapter import io.legado.app.base.adapter.ItemViewHolder -import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.SearchBook import io.legado.app.databinding.ItemSearchBinding import io.legado.app.utils.gone @@ -14,7 +14,7 @@ import io.legado.app.utils.visible import org.jetbrains.anko.sdk27.listeners.onClick class SearchAdapter(context: Context, val callBack: CallBack) : - SimpleRecyclerAdapter(context) { + DiffRecyclerAdapter(context) { override val diffItemCallback: DiffUtil.ItemCallback get() = object : DiffUtil.ItemCallback() { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt index 949a86516..41e5a1819 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt @@ -11,8 +11,8 @@ import androidx.core.os.bundleOf import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import io.legado.app.R +import io.legado.app.base.adapter.DiffRecyclerAdapter import io.legado.app.base.adapter.ItemViewHolder -import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.BookSource import io.legado.app.databinding.ItemBookSourceBinding import io.legado.app.lib.theme.backgroundColor @@ -23,11 +23,53 @@ import io.legado.app.utils.visible import org.jetbrains.anko.sdk27.listeners.onClick class BookSourceAdapter(context: Context, val callBack: CallBack) : - SimpleRecyclerAdapter(context), + DiffRecyclerAdapter(context), Callback { override val diffItemCallback: DiffUtil.ItemCallback - get() = DiffCallBack() + get() = object : DiffUtil.ItemCallback() { + + override fun areItemsTheSame(oldItem: BookSource, newItem: BookSource): Boolean { + return oldItem.bookSourceUrl == newItem.bookSourceUrl + } + + override fun areContentsTheSame(oldItem: BookSource, newItem: BookSource): Boolean { + if (oldItem.bookSourceName != newItem.bookSourceName) + return false + if (oldItem.bookSourceGroup != newItem.bookSourceGroup) + return false + if (oldItem.enabled != newItem.enabled) + return false + if (oldItem.enabledExplore != newItem.enabledExplore + || oldItem.exploreUrl != newItem.exploreUrl + ) { + return false + } + return true + } + + override fun getChangePayload(oldItem: BookSource, newItem: BookSource): Any? { + val payload = Bundle() + if (oldItem.bookSourceName != newItem.bookSourceName) { + payload.putString("name", newItem.bookSourceName) + } + if (oldItem.bookSourceGroup != newItem.bookSourceGroup) { + payload.putString("group", newItem.bookSourceGroup) + } + if (oldItem.enabled != newItem.enabled) { + payload.putBoolean("enabled", newItem.enabled) + } + if (oldItem.enabledExplore != newItem.enabledExplore + || oldItem.exploreUrl != newItem.exploreUrl + ) { + payload.putBoolean("showExplore", true) + } + if (payload.isEmpty) { + return null + } + return payload + } + } private val selected = linkedSetOf() diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt deleted file mode 100644 index 787e3a129..000000000 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt +++ /dev/null @@ -1,49 +0,0 @@ -package io.legado.app.ui.book.source.manage - -import android.os.Bundle -import androidx.recyclerview.widget.DiffUtil -import io.legado.app.data.entities.BookSource - -class DiffCallBack : DiffUtil.ItemCallback() { - - override fun areItemsTheSame(oldItem: BookSource, newItem: BookSource): Boolean { - return oldItem.bookSourceUrl == newItem.bookSourceUrl - } - - override fun areContentsTheSame(oldItem: BookSource, newItem: BookSource): Boolean { - if (oldItem.bookSourceName != newItem.bookSourceName) - return false - if (oldItem.bookSourceGroup != newItem.bookSourceGroup) - return false - if (oldItem.enabled != newItem.enabled) - return false - if (oldItem.enabledExplore != newItem.enabledExplore - || oldItem.exploreUrl != newItem.exploreUrl - ) { - return false - } - return true - } - - override fun getChangePayload(oldItem: BookSource, newItem: BookSource): Any? { - val payload = Bundle() - if (oldItem.bookSourceName != newItem.bookSourceName) { - payload.putString("name", newItem.bookSourceName) - } - if (oldItem.bookSourceGroup != newItem.bookSourceGroup) { - payload.putString("group", newItem.bookSourceGroup) - } - if (oldItem.enabled != newItem.enabled) { - payload.putBoolean("enabled", newItem.enabled) - } - if (oldItem.enabledExplore != newItem.enabledExplore - || oldItem.exploreUrl != newItem.exploreUrl - ) { - payload.putBoolean("showExplore", true) - } - if (payload.isEmpty) { - return null - } - return payload - } -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BaseBooksAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BaseBooksAdapter.kt index 034003538..538887c1c 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BaseBooksAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BaseBooksAdapter.kt @@ -4,14 +4,63 @@ import android.content.Context import androidx.core.os.bundleOf import androidx.recyclerview.widget.DiffUtil import androidx.viewbinding.ViewBinding -import io.legado.app.base.adapter.SimpleRecyclerAdapter +import io.legado.app.base.adapter.DiffRecyclerAdapter import io.legado.app.data.entities.Book abstract class BaseBooksAdapter(context: Context) : - SimpleRecyclerAdapter(context) { + DiffRecyclerAdapter(context) { override val diffItemCallback: DiffUtil.ItemCallback - get() = BooksDiffCallBack() + get() = object : DiffUtil.ItemCallback() { + + override fun areItemsTheSame(oldItem: Book, newItem: Book): Boolean { + return oldItem.name == newItem.name + && oldItem.author == newItem.author + } + + override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean { + 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(oldItem: Book, newItem: Book): Any? { + val bundle = bundleOf() + if (oldItem.name != newItem.name) { + bundle.putString("name", newItem.name) + } + if (oldItem.author != newItem.author) { + bundle.putString("author", newItem.author) + } + if (oldItem.durChapterTitle != newItem.durChapterTitle) { + bundle.putString("dur", newItem.durChapterTitle) + } + if (oldItem.latestChapterTitle != newItem.latestChapterTitle) { + bundle.putString("last", newItem.latestChapterTitle) + } + if (oldItem.getDisplayCover() != newItem.getDisplayCover()) { + bundle.putString("cover", newItem.getDisplayCover()) + } + if (oldItem.lastCheckCount != newItem.lastCheckCount + || oldItem.durChapterTime != newItem.durChapterTime + || oldItem.getUnreadChapterNum() != newItem.getUnreadChapterNum() + || oldItem.lastCheckCount != newItem.lastCheckCount + ) { + bundle.putBoolean("refresh", true) + } + if (bundle.isEmpty) return null + return bundle + } + + } fun notification(bookUrl: String) { for (i in 0 until itemCount) { 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 deleted file mode 100644 index 5c5fcf62f..000000000 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt +++ /dev/null @@ -1,56 +0,0 @@ -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 - -class BooksDiffCallBack() : DiffUtil.ItemCallback() { - - override fun areItemsTheSame(oldItem: Book, newItem: Book): Boolean { - return oldItem.name == newItem.name - && oldItem.author == newItem.author - } - - override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean { - 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(oldItem: Book, newItem: Book): Any? { - val bundle = bundleOf() - if (oldItem.name != newItem.name) { - bundle.putString("name", newItem.name) - } - if (oldItem.author != newItem.author) { - bundle.putString("author", newItem.author) - } - if (oldItem.durChapterTitle != newItem.durChapterTitle) { - bundle.putString("dur", newItem.durChapterTitle) - } - if (oldItem.latestChapterTitle != newItem.latestChapterTitle) { - bundle.putString("last", newItem.latestChapterTitle) - } - if (oldItem.getDisplayCover() != newItem.getDisplayCover()) { - bundle.putString("cover", newItem.getDisplayCover()) - } - if (oldItem.lastCheckCount != newItem.lastCheckCount - || oldItem.durChapterTime != newItem.durChapterTime - || oldItem.getUnreadChapterNum() != newItem.getUnreadChapterNum() - || oldItem.lastCheckCount != newItem.lastCheckCount - ) { - bundle.putBoolean("refresh", true) - } - if (bundle.isEmpty) return null - return bundle - } - -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/DiffCallBack.kt deleted file mode 100644 index 2945a9b95..000000000 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/DiffCallBack.kt +++ /dev/null @@ -1,35 +0,0 @@ -package io.legado.app.ui.rss.source.manage - -import android.os.Bundle -import androidx.recyclerview.widget.DiffUtil -import io.legado.app.data.entities.RssSource - -class DiffCallBack : DiffUtil.ItemCallback() { - - override fun areItemsTheSame(oldItem: RssSource, newItem: RssSource): Boolean { - return oldItem.sourceUrl == newItem.sourceUrl - } - - override fun areContentsTheSame(oldItem: RssSource, newItem: RssSource): Boolean { - return oldItem.sourceName == newItem.sourceName - && oldItem.sourceGroup == newItem.sourceGroup - && oldItem.enabled == newItem.enabled - } - - override fun getChangePayload(oldItem: RssSource, newItem: RssSource): Any? { - val payload = Bundle() - if (oldItem.sourceName != newItem.sourceName) { - payload.putString("name", newItem.sourceName) - } - if (oldItem.sourceGroup != newItem.sourceGroup) { - payload.putString("group", newItem.sourceGroup) - } - if (oldItem.enabled != newItem.enabled) { - payload.putBoolean("enabled", newItem.enabled) - } - if (payload.isEmpty) { - return null - } - return payload - } -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt index 952e814f4..284149d37 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt @@ -9,8 +9,8 @@ import androidx.core.os.bundleOf import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import io.legado.app.R +import io.legado.app.base.adapter.DiffRecyclerAdapter import io.legado.app.base.adapter.ItemViewHolder -import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.RssSource import io.legado.app.databinding.ItemRssSourceBinding import io.legado.app.lib.theme.backgroundColor @@ -19,11 +19,39 @@ import io.legado.app.ui.widget.recycler.ItemTouchCallback import org.jetbrains.anko.sdk27.listeners.onClick class RssSourceAdapter(context: Context, val callBack: CallBack) : - SimpleRecyclerAdapter(context), + DiffRecyclerAdapter(context), ItemTouchCallback.Callback { override val diffItemCallback: DiffUtil.ItemCallback - get() = DiffCallBack() + get() = object : DiffUtil.ItemCallback() { + + override fun areItemsTheSame(oldItem: RssSource, newItem: RssSource): Boolean { + return oldItem.sourceUrl == newItem.sourceUrl + } + + override fun areContentsTheSame(oldItem: RssSource, newItem: RssSource): Boolean { + return oldItem.sourceName == newItem.sourceName + && oldItem.sourceGroup == newItem.sourceGroup + && oldItem.enabled == newItem.enabled + } + + override fun getChangePayload(oldItem: RssSource, newItem: RssSource): Any? { + val payload = Bundle() + if (oldItem.sourceName != newItem.sourceName) { + payload.putString("name", newItem.sourceName) + } + if (oldItem.sourceGroup != newItem.sourceGroup) { + payload.putString("group", newItem.sourceGroup) + } + if (oldItem.enabled != newItem.enabled) { + payload.putBoolean("enabled", newItem.enabled) + } + if (payload.isEmpty) { + return null + } + return payload + } + } private val selected = linkedSetOf()