diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt index 730e63822..d2423de01 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt @@ -144,7 +144,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : private var isMoved = false - override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { + override fun swap(srcPosition: Int, targetPosition: Int): Boolean { val srcItem = getItem(srcPosition) val targetItem = getItem(targetPosition) if (srcItem != null && targetItem != null) { 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 0e93876d9..5d1fecf80 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 @@ -192,7 +192,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } } - override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { + override fun swap(srcPosition: Int, targetPosition: Int): Boolean { swapItem(srcPosition, targetPosition) isMoved = true return true diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index 3a02b4757..0aaac8ce4 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -191,7 +191,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } } - override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { + override fun swap(srcPosition: Int, targetPosition: Int): Boolean { swapItem(srcPosition, targetPosition) isMoved = true return true diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt index 7fe704620..11ee46f6c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -247,10 +247,10 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { private var isMoved = false - override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { + override fun swap(srcPosition: Int, targetPosition: Int): Boolean { swapItem(srcPosition, targetPosition) isMoved = true - return super.onMove(srcPosition, targetPosition) + return super.swap(srcPosition, targetPosition) } override fun onClearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { 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 9d37f7776..85b3b4a07 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 @@ -229,7 +229,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : return selection.sortedBy { it.customOrder } } - override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { + override fun swap(srcPosition: Int, targetPosition: Int): Boolean { val srcItem = getItem(srcPosition) val targetItem = getItem(targetPosition) if (srcItem != null && targetItem != null) { diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt index 51588e29f..c08ac9690 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt @@ -145,7 +145,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : popupMenu.show() } - override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { + override fun swap(srcPosition: Int, targetPosition: Int): Boolean { val srcItem = getItem(srcPosition) val targetItem = getItem(targetPosition) if (srcItem != null && targetItem != null) { 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 96f4be01f..532b9e89d 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 @@ -181,7 +181,7 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : popupMenu.show() } - override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { + override fun swap(srcPosition: Int, targetPosition: Int): Boolean { val srcItem = getItem(srcPosition) val targetItem = getItem(targetPosition) if (srcItem != null && targetItem != null) { diff --git a/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubAdapter.kt index f8e1c916d..d8c3c044d 100644 --- a/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubAdapter.kt @@ -59,7 +59,7 @@ class RuleSubAdapter(context: Context, val callBack: Callback) : return ItemRuleSubBinding.inflate(inflater, parent, false) } - override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { + override fun swap(srcPosition: Int, targetPosition: Int): Boolean { val srcItem = getItem(srcPosition) val targetItem = getItem(targetPosition) if (srcItem != null && targetItem != null) { diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt index 368fd8c36..ef9872298 100644 --- a/app/src/main/java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt @@ -85,7 +85,18 @@ class ItemTouchCallback(private val callback: Callback) : ItemTouchHelper.Callba srcViewHolder: RecyclerView.ViewHolder, targetViewHolder: RecyclerView.ViewHolder ): Boolean { - return callback.onMove(srcViewHolder.adapterPosition, targetViewHolder.adapterPosition) + val fromPosition: Int = srcViewHolder.adapterPosition + val toPosition: Int = targetViewHolder.adapterPosition + if (fromPosition < toPosition) { + for (i in fromPosition until toPosition) { + callback.swap(i, i + 1) + } + } else { + for (i in fromPosition downTo toPosition + 1) { + callback.swap(i, i - 1) + } + } + return true } override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { @@ -122,7 +133,7 @@ class ItemTouchCallback(private val callback: Callback) : ItemTouchHelper.Callba * @param targetPosition 目的地的Item的position * @return 开发者处理了操作应该返回true,开发者没有处理就返回false */ - fun onMove(srcPosition: Int, targetPosition: Int): Boolean { + fun swap(srcPosition: Int, targetPosition: Int): Boolean { return true }