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

How to collapse all items at start? #767

Closed Godsmack121Kcamsdog closed 3 years ago

Godsmack121Kcamsdog commented 3 years ago

What should I do if I need all expandable items to be collapsed at start?

Currently I have Items AbstractExpandableHeaderItem and AbstractSectionableItem I`ve made pet project and inicialize items like this:

   List<AbstractFlexibleItem> items = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            Header h = new Header("Header " + i, new Body("Body " + i));
            CustomHeaderItem headerItem = new CustomHeaderItem(h); //extends **AbstractExpandableHeaderItem**
            for (Body b : h.getBody()) {
                headerItem.addSubItem(new CustomSubItem(headerItem, b)); //extends **AbstractSectionableItem**
            }
            items.add(headerItem);
        }

        adapter = new CustomAdapter(items);
        adapter
                .expandItemsAtStartUp()//Items must be pre-initialized with expanded=true
                .setAutoCollapseOnExpand(true) //Force closes all others expandable item before expanding a new one
                .setMinCollapsibleLevel(1) //Auto collapse only items with level >= 1 (Don't auto-collapse level 0)
                .setAutoScrollOnExpand(true) //Needs a SmoothScrollXXXLayoutManager
                .setAnimationOnForwardScrolling(true) //Enable scrolling animation: entry + forward scrolling
                .setAnimationOnReverseScrolling(true); //Enable animation for reverse scrolling
        recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(this));
        recyclerView.setAdapter(adapter);

If I dont call expandItemsAtStartUp() - then it doesnt work correct. I have 100 headers, each with 5 subitems. If I click Header1, for example - then at place of Header2 appears Header6 and Header1 does not expand. If I call expandItemsAtStartUp() and then call collapseAll() - nothing happens.

Godsmack121Kcamsdog commented 3 years ago
 adapter
                .setAutoCollapseOnExpand(true)
                .setAutoScrollOnExpand(true)
                .setMinCollapsibleLevel(0)
                .setStickyHeaders(true)
                .setAnimateToLimit(Integer.MAX_VALUE) //Size limit = MAX_VALUE will always animate the changes
                .setNotifyMoveOfFilteredItems(true) //When true, filtering on big list is very slow!
                .setAnimationOnForwardScrolling(true)
                .setAnimationOnReverseScrolling(true);

        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(this));
        recyclerView.setHasFixedSize(true);
        recyclerView.setAdapter(adapter);