mikepenz / FastAdapter

The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
https://mikepenz.dev
Apache License 2.0
3.83k stars 492 forks source link

EventHook unexpected behavior with EndlessScroll and ProgressItem #961

Closed Berthod closed 2 years ago

Berthod commented 3 years ago

This is similar issue to #643. Initial binding is fine but any calls to notifyAdapterItemChanged(position) are not shown until the list is scrolled for a bit. Interesting part of the problem is that it occurs only when page 2 list is empty. If there are enough data for second page bindings work fine.

As in #643, if we don't add ProgressItem EventHook works fine.

EventHook

adapter.addEventHook(object : ClickEventHook<MyItemView>() {
            override fun onBind(viewHolder: RecyclerView.ViewHolder): View? {
                return if (viewHolder is MyItemView.ViewHolder) {
                    viewHolder.MyItemClickView
                }
                else null
            }

            override fun onClick(v: View, position: Int, fastAdapter: FastAdapter<MyItemView>, item: MyItemView) {
                *network request*
            }
})

EndlessScrollListener

endlessRecyclerOnScrollListener = object : EndlessRecyclerOnScrollListener(manager , visibleTreshold, footerAdapter) {
            override fun onLoadMore(currentPage: Int) {
                footerAdapter.clear()
                mViewModel.page = currentPage + 1

                val progressItem = ProgressItem()
                progressItem.isEnabled = false
                footerAdapter.add(progressItem)

               *network call*
            }
}
recycler_view.addOnScrollListener(endlessRecyclerOnScrollListener)

Details

Checklist

mikepenz commented 3 years ago

is notifyAdapterItemChanged called from the UI thread?

can you please clarify if we don't add ProgressItem EventHook works fine

Are you meaning if you don't add the EventHook it's fine? or if you don't add this item to the list it is fine?

Berthod commented 3 years ago

is notifyAdapterItemChanged called from the UI thread?

yes

Are you meaning if you don't add the EventHook it's fine? or if you don't add this item to the list it is fine?

Sorry for bad wording. What I meant was if we don't call this line footerAdapter.add(progressItem) in onLoadMore everything works fine

mikepenz commented 3 years ago

Could you please provide a sample app showcasing this issue?

mikepenz commented 2 years ago

Closing due to inactivity and outstanding quetsions