From 543f0aec87d4b77683870e23aa518c1d9fe34051 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 17 Dec 2020 10:01:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/base/adapter/DiffRecyclerAdapter.kt | 10 ---- .../app/ui/book/group/GroupManageDialog.kt | 22 +------ .../book/source/manage/BookSourceAdapter.kt | 58 +------------------ .../ui/rss/source/manage/RssSourceAdapter.kt | 44 +------------- 4 files changed, 6 insertions(+), 128 deletions(-) diff --git a/app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt b/app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt index 7de76e8e6..258f93c87 100644 --- a/app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt +++ b/app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt @@ -8,8 +8,6 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.viewbinding.ViewBinding -import java.util.* -import kotlin.collections.ArrayList /** * Created by Invincible on 2017/12/15. @@ -63,14 +61,6 @@ abstract class DiffRecyclerAdapter(protected val context } } - fun swapItem(srcPosition: Int, targetPosition: Int) { - synchronized(lock) { - val list = ArrayList(getItems()) - Collections.swap(list, srcPosition, targetPosition) - setItems(list) - } - } - fun updateItem(item: ITEM) = synchronized(lock) { val index = asyncListDiffer.currentList.indexOf(item) 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 5d1fecf80..4eda999ce 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 @@ -9,15 +9,14 @@ import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.Toolbar import androidx.core.view.isGone -import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager 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.RecyclerAdapter import io.legado.app.data.entities.BookGroup import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogRecyclerViewBinding @@ -137,28 +136,11 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } private inner class GroupAdapter(context: Context) : - DiffRecyclerAdapter(context), + RecyclerAdapter(context), ItemTouchCallback.Callback { private var isMoved = false - override val diffItemCallback: DiffUtil.ItemCallback - get() = object : DiffUtil.ItemCallback() { - - override fun areItemsTheSame(oldItem: BookGroup, newItem: BookGroup): Boolean { - return oldItem.groupId == newItem.groupId - } - - override fun areContentsTheSame( - oldItem: BookGroup, - newItem: BookGroup - ): Boolean { - return oldItem.groupName == newItem.groupName - && oldItem.show == newItem.show - } - - } - override fun getViewBinding(parent: ViewGroup): ItemGroupManageBinding { return ItemGroupManageBinding.inflate(inflater, parent, false) } 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 85b3b4a07..55f179023 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 @@ -8,11 +8,10 @@ import android.view.ViewGroup import android.widget.ImageView import android.widget.PopupMenu 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.RecyclerAdapter import io.legado.app.data.entities.BookSource import io.legado.app.databinding.ItemBookSourceBinding import io.legado.app.lib.theme.backgroundColor @@ -23,54 +22,9 @@ import io.legado.app.utils.visible import org.jetbrains.anko.sdk27.listeners.onClick class BookSourceAdapter(context: Context, val callBack: CallBack) : - DiffRecyclerAdapter(context), + RecyclerAdapter(context), Callback { - override val diffItemCallback: DiffUtil.ItemCallback - 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() override fun getViewBinding(parent: ViewGroup): ItemBookSourceBinding { @@ -100,14 +54,6 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : payload.keySet().map { when (it) { "selected" -> cbBookSource.isChecked = selected.contains(item) - "name", "group" -> if (item.bookSourceGroup.isNullOrEmpty()) { - cbBookSource.text = item.bookSourceName - } else { - cbBookSource.text = - String.format("%s (%s)", item.bookSourceName, item.bookSourceGroup) - } - "enabled" -> swtEnabled.isChecked = payload.getBoolean(it) - "showExplore" -> upShowExplore(ivExplore, item) } } } 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 532b9e89d..964775abf 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 @@ -6,11 +6,10 @@ import android.view.View import android.view.ViewGroup import android.widget.PopupMenu 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.RecyclerAdapter import io.legado.app.data.entities.RssSource import io.legado.app.databinding.ItemRssSourceBinding import io.legado.app.lib.theme.backgroundColor @@ -19,40 +18,9 @@ import io.legado.app.ui.widget.recycler.ItemTouchCallback import org.jetbrains.anko.sdk27.listeners.onClick class RssSourceAdapter(context: Context, val callBack: CallBack) : - DiffRecyclerAdapter(context), + RecyclerAdapter(context), ItemTouchCallback.Callback { - override val diffItemCallback: DiffUtil.ItemCallback - 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() override fun getViewBinding(parent: ViewGroup): ItemRssSourceBinding { @@ -80,15 +48,7 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : } else { bundle.keySet().map { when (it) { - "name", "group" -> - if (item.sourceGroup.isNullOrEmpty()) { - cbSource.text = item.sourceName - } else { - cbSource.text = - String.format("%s (%s)", item.sourceName, item.sourceGroup) - } "selected" -> cbSource.isChecked = selected.contains(item) - "enabled" -> cbSource.isChecked = item.enabled } } }