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:
OxygenCobalt 2021-06-18 15:19:15 -06:00
parent aebe279e95
commit 7adfb921fa
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -49,6 +49,31 @@ class FastScrollView @JvmOverloads constructor(
private var mRecycler: RecyclerView? = 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 ---
@ -93,6 +118,8 @@ class FastScrollView @JvmOverloads constructor(
mRecycler = recycler
mGetItem = getItem
recycler.adapter?.registerAdapterDataObserver(mObserver)
postIndicatorUpdate()
}