Skip to content

Commit

Permalink
[#139] Fix dots refresh bug when the adapter items change without cal…
Browse files Browse the repository at this point in the history
…ling notifyDataSetChanged
  • Loading branch information
tommybuonomo committed Apr 30, 2022
1 parent 3298964 commit 57968d2
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,32 @@ abstract class BaseDotsIndicator @JvmOverloads constructor(
viewPager2.adapter!!.registerAdapterDataObserver(object : AdapterDataObserver() {
override fun onChanged() {
super.onChanged()
refreshDots()
post { refreshDots() }
}

override fun onItemRangeChanged(positionStart: Int, itemCount: Int) {
super.onItemRangeChanged(positionStart, itemCount)
post { refreshDots() }
}

override fun onItemRangeChanged(positionStart: Int, itemCount: Int, payload: Any?) {
super.onItemRangeChanged(positionStart, itemCount, payload)
post { refreshDots() }
}

override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
super.onItemRangeInserted(positionStart, itemCount)
post { refreshDots() }
}

override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
super.onItemRangeRemoved(positionStart, itemCount)
post { refreshDots() }
}

override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) {
super.onItemRangeMoved(fromPosition, toPosition, itemCount)
post { refreshDots() }
}
})

Expand Down

0 comments on commit 57968d2

Please sign in to comment.