|
|
|
@ -125,11 +125,19 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : |
|
|
|
|
private var isMoved = false |
|
|
|
|
|
|
|
|
|
override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { |
|
|
|
|
val srcItem = getItem(srcPosition) |
|
|
|
|
val targetItem = getItem(targetPosition) |
|
|
|
|
Collections.swap(getItems(), srcPosition, targetPosition) |
|
|
|
|
notifyItemMoved(srcPosition, targetPosition) |
|
|
|
|
if (getItem(srcPosition)?.order == getItem(targetPosition)?.order) { |
|
|
|
|
for ((index, item) in getItems().withIndex()) { |
|
|
|
|
item.order = index + 1 |
|
|
|
|
if (srcItem != null && targetItem != null) { |
|
|
|
|
if (srcItem.order == targetItem.order) { |
|
|
|
|
for ((index, item) in getItems().withIndex()) { |
|
|
|
|
item.order = index + 1 |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
val pos = srcItem.order |
|
|
|
|
srcItem.order = targetItem.order |
|
|
|
|
targetItem.order = pos |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
isMoved = true |
|
|
|
|