pull/94/head
kunfei 5 years ago
parent a845fe192f
commit 153830e143
  1. 20
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt

@ -78,12 +78,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
recycler_view.adapter = adapter recycler_view.adapter = adapter
App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, Observer { App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, Observer {
val diffResult = val diffResult =
DiffUtil.calculateDiff( DiffUtil.calculateDiff(GroupDiffCallBack(ArrayList(adapter.getItems()), it))
GroupDiffCallBack(
adapter.getItems(),
it
)
)
adapter.setItems(it, false) adapter.setItems(it, false)
diffResult.dispatchUpdatesTo(adapter) diffResult.dispatchUpdatesTo(adapter)
}) })
@ -154,13 +149,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private class GroupDiffCallBack( private class GroupDiffCallBack(
private val oldItems: List<BookGroup>, private val oldItems: List<BookGroup>,
private val newItems: List<BookGroup> private val newItems: List<BookGroup>
) : ) : DiffUtil.Callback() {
DiffUtil.Callback() {
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition]
return oldItem.groupId == newItem.groupId
}
override fun getOldListSize(): Int { override fun getOldListSize(): Int {
return oldItems.size return oldItems.size
@ -170,11 +159,14 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
return newItems.size return newItems.size
} }
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
return true
}
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
val oldItem = oldItems[oldItemPosition] val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition] val newItem = newItems[newItemPosition]
return oldItem.groupName == newItem.groupName return oldItem.groupName == newItem.groupName
&& oldItem.order == newItem.order
} }
} }

Loading…
Cancel
Save