Skip to content

Commit

Permalink
Fixed function of move list items
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima Ivanov committed Feb 10, 2021
1 parent 5e565aa commit 2ce5354
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
import java.util.*

/**
* Main adapter class, which implements androidx.RecyclerView.
Expand Down Expand Up @@ -91,11 +92,11 @@ open class MultiBindingAdapter(
fun moveItem(fromPosition: Int, toPosition: Int): Boolean {
if (fromPosition < toPosition) {
for (i in fromPosition until toPosition) {
mutableItems[i] = mutableItems.set(i + 1, mutableItems[i]);
Collections.swap(mutableItems, i, i + 1)
}
} else {
for (i in toPosition + 1 downTo fromPosition) {
mutableItems[i] = mutableItems.set(i - 1, mutableItems[i]);
for (i in fromPosition downTo toPosition + 1) {
Collections.swap(mutableItems, i, i - 1)
}
}
notifyItemMoved(fromPosition, toPosition)
Expand Down

0 comments on commit 2ce5354

Please sign in to comment.