@SuppressWarnings("unchecked")
    @UiThread
    public void onRestoreInstanceState(@Nullable Bundle savedInstanceState) {
        if (savedInstanceState == null
                || !savedInstanceState.containsKey(EXPANDED_STATE_MAP)) {
            return;
        }

        HashMap<Integer, Boolean> expandedStateMap = (HashMap<Integer, Boolean>) savedInstanceState.getSerializable(EXPANDED_STATE_MAP);
        if (expandedStateMap == null) {
            return;
        }

        List<ExpandableWrapper<P, C>> itemList = new ArrayList<>();
        int parentsCount = mParentList.size();
        for (int i = 0; i < parentsCount; i++) {
            ExpandableWrapper<P, C> parentWrapper = new ExpandableWrapper<>(mParentList.get(i));
            itemList.add(parentWrapper);

            if (expandedStateMap.containsKey(i)) {
                boolean expanded = expandedStateMap.get(i);
                parentWrapper.setExpanded(expanded);

                if (expanded) {
                    List<ExpandableWrapper<P, C>> wrappedChildList = parentWrapper.getWrappedChildList();
                    int childrenCount = wrappedChildList.size();
                    for (int j = 0; j < childrenCount; j++) {
                        ExpandableWrapper<P, C> childWrapper = wrappedChildList.get(j);
                        itemList.add(childWrapper);
                    }
                }
            }
        }

        mFlatItemList = itemList;

        notifyDataSetChanged();
    }
@ SuppressWarnings ( "unchecked" ) @ UiThread public void onRestoreInstanceState ( @ Nullable Bundle savedInstanceState ) { if ( savedInstanceState == null || ! savedInstanceState . containsKey ( EXPANDED_STATE_MAP ) ) { return ; } HashMap < Integer , Boolean > expandedStateMap = ( HashMap < Integer , Boolean > ) savedInstanceState . getSerializable ( EXPANDED_STATE_MAP ) ; if ( expandedStateMap == null ) { return ; } List < ExpandableWrapper < P , C > > itemList = new ArrayList < > ( ) ; int parentsCount = mParentList . size ( ) ; for ( int i = 0 ; i < parentsCount ; i ++ ) { ExpandableWrapper < P , C > parentWrapper = new ExpandableWrapper < > ( mParentList . get ( i ) ) ; itemList . add ( parentWrapper ) ; if ( expandedStateMap . containsKey ( i ) ) { boolean expanded = expandedStateMap . get ( i ) ; parentWrapper . setExpanded ( expanded ) ; if ( expanded ) { List < ExpandableWrapper < P , C > > wrappedChildList = parentWrapper . getWrappedChildList ( ) ; int childrenCount = wrappedChildList . size ( ) ; for ( int j = 0 ; j < childrenCount ; j ++ ) { ExpandableWrapper < P , C > childWrapper = wrappedChildList . get ( j ) ; itemList . add ( childWrapper ) ; } } } } mFlatItemList = itemList ; notifyDataSetChanged ( ) ; }
Fetches the expandable state map from the saved instance state {@link Bundle}
and restores the expanded states of all of the parents.
<p>
Should be called from {@link Activity#onRestoreInstanceState(Bundle)} in
the {@link Activity} that hosts the RecyclerView that this
{@link ExpandableRecyclerAdapter} is attached to.
<p>
Assumes that the list of parents is the same as when the saved
instance state was stored.

@param savedInstanceState The {@code Bundle} from which the expanded
state map is loaded