Fixed error that prevented flashing

This commit is contained in:
Viktor De Pasquale 2019-05-23 16:50:31 +02:00
parent 0119ebddbe
commit dabe6267b9
2 changed files with 9 additions and 4 deletions

View File

@ -155,8 +155,6 @@ fun setScrollToLast(view: RecyclerView, shouldScrollToLast: Boolean) {
Observable.timer(1, TimeUnit.SECONDS).subscribeK { callback() }
}
val tag = RecyclerView::class.java.name.sumBy { it.toInt() }
fun RecyclerView.Adapter<*>.setListener() {
val observer = object : RecyclerView.AdapterDataObserver() {
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
@ -164,11 +162,12 @@ fun setScrollToLast(view: RecyclerView, shouldScrollToLast: Boolean) {
}
}
registerAdapterDataObserver(observer)
view.setTag(tag, observer)
view.setTag(R.id.recyclerScrollListener, observer)
}
fun RecyclerView.Adapter<*>.removeListener() {
val observer = view.getTag(tag) as? RecyclerView.AdapterDataObserver ?: return
val observer =
view.getTag(R.id.recyclerScrollListener) as? RecyclerView.AdapterDataObserver ?: return
unregisterAdapterDataObserver(observer)
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="recyclerScrollListener" type="id" />
</resources>