davideas / FlexibleAdapter

Fast and versatile Adapter for RecyclerView which regroups several features into one library to considerably improve the user experience :-)
Apache License 2.0
3.56k stars 552 forks source link

onLoadMoreComplete() does not display headers while updateDataSet() does #734

Open ketain opened 5 years ago

ketain commented 5 years ago

I know that you have answered similar questions on #271 and #183. But I think there is still a problem.

Using the method updateDataSet() properly displays all items with headers. Changing nothing else in the code but exchanging the call from updateDataSet() to onLoadMoreComplete() causes headers to not be displayed anymore.

In order to display the headers I had to copy this code from FlexibleAdapter.prepareItemsForUpdate into my own:

` int position = 0; IHeader sameHeader = null; while (position < items.size()) { IFlexible item = items.get(position);

        IHeader header = mFlexAdapter.getHeaderOf(item);
        if (header != null && !header.equals(sameHeader)) {
            header.setHidden(false);
            sameHeader = header;
            items.add(position, header);
            position++;
        }
        position++;
    }

`

(I slightly adapted the names to the ones used in my own code, of course)

This unfortunatley breaks the sticky header functionality, as none of the newly loaded items are being displayed. In their sted some of the old ones are shown.

I believe this has something to do with them not being added to the list of sticky headers?

I use version: v5.1.0

andro-jedi commented 4 years ago

The same issue in v5.1.0. At first I use updateDataSet (headers are displayed) and after I call onLoadMoreComplete (No headers on newly inserted items)

It seems that addItems->showOrUpdateHeaders only updates already added headers but skips new one. When I use suggested fix from @ketain it works.


override fun onLoadMoreComplete(newItems: List<T>?) {
       val itemsWithHeaders = newItems?.toMutableList() ?: mutableListOf()
        prepareItemsForUpdate(itemsWithHeaders)
        super.onLoadMoreComplete(itemsWithHeaders)
}```
raquezha commented 4 years ago

prepareItemsForUpdate(itemsWithHeaders)

this is a private function how wil you call this?