pull/94/head
parent
96b3846313
commit
675aa0cb88
@ -0,0 +1,34 @@ |
|||||||
|
package io.legado.app.help |
||||||
|
|
||||||
|
import androidx.recyclerview.widget.ListUpdateCallback |
||||||
|
import androidx.recyclerview.widget.RecyclerView |
||||||
|
import io.legado.app.base.adapter.ItemViewHolder |
||||||
|
|
||||||
|
class ToTopListUpCallback : ListUpdateCallback { |
||||||
|
var firstInsert = -1 |
||||||
|
lateinit var adapter: RecyclerView.Adapter<ItemViewHolder> |
||||||
|
|
||||||
|
override fun onChanged(position: Int, count: Int, payload: Any?) { |
||||||
|
adapter.notifyItemRangeChanged(position, count, payload) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onMoved(fromPosition: Int, toPosition: Int) { |
||||||
|
if (toPosition == 0) { |
||||||
|
firstInsert = 0 |
||||||
|
} |
||||||
|
adapter.notifyItemMoved(fromPosition, toPosition) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onInserted(position: Int, count: Int) { |
||||||
|
if (firstInsert == -1 || firstInsert > position) { |
||||||
|
firstInsert = position |
||||||
|
} |
||||||
|
adapter.notifyItemRangeInserted(position, count) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onRemoved(position: Int, count: Int) { |
||||||
|
adapter.notifyItemRangeRemoved(position, count) |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue