recycler: make fast scroller respond to changes
Make the fast scroller respond to changes in the RecyclerView data. This again prepares it for use in the library with it's sorting and item configuration.
This commit is contained in:
parent
aebe279e95
commit
7adfb921fa
1 changed files with 27 additions and 0 deletions
|
@ -49,6 +49,31 @@ class FastScrollView @JvmOverloads constructor(
|
||||||
|
|
||||||
private var mRecycler: RecyclerView? = null
|
private var mRecycler: RecyclerView? = null
|
||||||
private var mGetItem: ((Int) -> Char)? = null
|
private var mGetItem: ((Int) -> Char)? = null
|
||||||
|
private val mObserver = object : RecyclerView.AdapterDataObserver() {
|
||||||
|
override fun onChanged() = postIndicatorUpdate()
|
||||||
|
|
||||||
|
override fun onItemRangeChanged(
|
||||||
|
positionStart: Int,
|
||||||
|
itemCount: Int,
|
||||||
|
payload: Any?
|
||||||
|
) = postIndicatorUpdate()
|
||||||
|
|
||||||
|
override fun onItemRangeInserted(
|
||||||
|
positionStart: Int,
|
||||||
|
itemCount: Int
|
||||||
|
) = onChanged()
|
||||||
|
|
||||||
|
override fun onItemRangeMoved(
|
||||||
|
fromPosition: Int,
|
||||||
|
toPosition: Int,
|
||||||
|
itemCount: Int
|
||||||
|
) = onChanged()
|
||||||
|
|
||||||
|
override fun onItemRangeRemoved(
|
||||||
|
positionStart: Int,
|
||||||
|
itemCount: Int
|
||||||
|
) = onChanged()
|
||||||
|
}
|
||||||
|
|
||||||
// --- INDICATORS ---
|
// --- INDICATORS ---
|
||||||
|
|
||||||
|
@ -93,6 +118,8 @@ class FastScrollView @JvmOverloads constructor(
|
||||||
mRecycler = recycler
|
mRecycler = recycler
|
||||||
mGetItem = getItem
|
mGetItem = getItem
|
||||||
|
|
||||||
|
recycler.adapter?.registerAdapterDataObserver(mObserver)
|
||||||
|
|
||||||
postIndicatorUpdate()
|
postIndicatorUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue