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.55k stars 553 forks source link

Duplicate header #182

Closed ulx closed 8 years ago

ulx commented 8 years ago

1) For Bugs / Support

I created

private void initListView() {
        rvOperationsAdapter = new HistoryOperationAdapter(null);
        rvOperationsAdapter.setRemoveOrphanHeaders(false)
                .setNotifyChangeOfUnfilteredItems(true);
        rvOperations.setLayoutManager(createNewLinearLayoutManager());
        rvOperations.setAdapter(rvOperationsAdapter);
        rvOperations.setHasFixedSize(true);
        rvOperations.setItemAnimator(new DefaultItemAnimator());
        rvOperations.addItemDecoration(new DividerItemDecoration(getContext(), 0, 24));
        rvOperationsAdapter
                .setUnlinkAllItemsOnRemoveHeaders(true)
                .enableStickyHeaders();
        rvOperationsAdapter.addUserLearnedSelection(filterItem, true);
        rvOperationsAdapter.setEndlessScrollListener(new LoadMoreListner(), new ProgressItem());
        rvOperationsAdapter.setEndlessScrollThreshold(1);

    }

public void setListOperations(List<HistoryOperation> listOperations) {
        rvOperationsAdapter.removeRange(1, rvOperationsAdapter.getItemCount());
        showData();

        final List<AbstractFlexibleItem> newItems = new ArrayList<>(listOperations.size());

        String prev = "";
        for (HistoryOperation item : listOperations) {
            HeaderItem header = null;
            if (!prev.equals(DateUtils.parseDate(item.date))) {
                header = new HeaderItem(item.id + "");
                header.setTitle(DateUtils.parseDate(item.date));
                prev = header.getTitle();
            }
            SimpleItem simpleItem = new SimpleItem(item, header);
            simpleItem.setTitle("Simple Item " + item.id);
            newItems.add(simpleItem);
        }

        rvOperationsAdapter.onLoadMoreComplete(newItems);
    }

2 I refreched list. 3 I see duplicate header

example https://postimg.org/image/6vraw3ccd/

davideas commented 8 years ago

Hi @ulx, I'm trying to understand your code. The first thing is nothing to do with this library: I see that HeaderItem is reinitialized to null at every cycle, so you are setting a new object every time, different from the previous header.

Also you can enable Adapter logs and see yourself what's happening behind. Or, you can try to debug and see if those items have the same reference or are new objects.

Please, remove the Header init. outside the for statement, it should fix, I think. If you need more help, write here.

ulx commented 8 years ago

Yes, you right. @davideas I called multiple times method "setListOperations". But I don't see method "clear" or "removeAll"

davideas commented 8 years ago

removeRange() is good, also, you can use removeItemsOfType(...). But probably I will add in the future a removeAll().

ulx commented 8 years ago

Thanks!