ExpandableRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @Override @UiThread public int getItemCount() { return mFlatItemList.size(); } ExpandableRecyclerAdapter(@NonNull List<P> parentList); @NonNull @Override @UiThread RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType); @Override @SuppressWarnings("unchecked") @UiThread void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int flatPosition); @NonNull @UiThread abstract PVH onCreateParentViewHolder(@NonNull ViewGroup parentViewGroup, int viewType); @NonNull @UiThread abstract CVH onCreateChildViewHolder(@NonNull ViewGroup childViewGroup, int viewType); @UiThread abstract void onBindParentViewHolder(@NonNull PVH parentViewHolder, int parentPosition, @NonNull P parent); @UiThread abstract void onBindChildViewHolder(@NonNull CVH childViewHolder, int parentPosition, int childPosition, @NonNull C child); @Override @UiThread int getItemCount(); @Override @UiThread int getItemViewType(int flatPosition); int getParentViewType(int parentPosition); int getChildViewType(int parentPosition, int childPosition); boolean isParentViewType(int viewType); @NonNull @UiThread List<P> getParentList(); @UiThread void setParentList(@NonNull List<P> parentList, boolean preserveExpansionState); @Override @UiThread void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView); @Override @UiThread void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView); @UiThread void setExpandCollapseListener(@Nullable ExpandCollapseListener expandCollapseListener); @UiThread void expandParent(@NonNull P parent); @UiThread void expandParent(int parentPosition); @UiThread void expandParentRange(int startParentPosition, int parentCount); @UiThread void expandAllParents(); @UiThread void collapseParent(@NonNull P parent); @UiThread void collapseParent(int parentPosition); @UiThread void collapseParentRange(int startParentPosition, int parentCount); @UiThread void collapseAllParents(); @UiThread void onSaveInstanceState(@NonNull Bundle savedInstanceState); @SuppressWarnings("unchecked") @UiThread void onRestoreInstanceState(@Nullable Bundle savedInstanceState); @UiThread void notifyParentDataSetChanged(boolean preserveExpansionState); @UiThread void notifyParentInserted(int parentPosition); @UiThread void notifyParentRangeInserted(int parentPositionStart, int itemCount); @UiThread void notifyParentRemoved(int parentPosition); void notifyParentRangeRemoved(int parentPositionStart, int itemCount); @UiThread void notifyParentChanged(int parentPosition); @UiThread void notifyParentRangeChanged(int parentPositionStart, int itemCount); @UiThread void notifyParentMoved(int fromParentPosition, int toParentPosition); @UiThread void notifyChildInserted(int parentPosition, int childPosition); @UiThread void notifyChildRangeInserted(int parentPosition, int childPositionStart, int itemCount); @UiThread void notifyChildRemoved(int parentPosition, int childPosition); @UiThread void notifyChildRangeRemoved(int parentPosition, int childPositionStart, int itemCount); @UiThread void notifyChildChanged(int parentPosition, int childPosition); @UiThread void notifyChildRangeChanged(int parentPosition, int childPositionStart, int itemCount); @UiThread void notifyChildMoved(int parentPosition, int fromChildPosition, int toChildPosition); static final int TYPE_PARENT; static final int TYPE_CHILD; static final int TYPE_FIRST_USER; }
@Test public void adapterCorrectlyInitializesExpandedParents() { assertEquals(25, mExpandableRecyclerAdapter.getItemCount()); }
@Test public void adapterCorrectlyInitializesExpandedParentsWhenAllParentItemsAreInitiallyCollapsed() { for (Parent parent : mBaseParents) { when(parent.isInitiallyExpanded()).thenReturn(false); } mExpandableRecyclerAdapter = new TestExpandableRecyclerAdapter(mBaseParents); assertEquals(10, mExpandableRecyclerAdapter.getItemCount()); }
@Test public void adapterCorrectlyInitializesExpandedParentsWhenAllParentItemsAreInitiallyExpanded() { for (Parent parent : mBaseParents) { when(parent.isInitiallyExpanded()).thenReturn(true); } mExpandableRecyclerAdapter = new TestExpandableRecyclerAdapter(mBaseParents); assertEquals(40, mExpandableRecyclerAdapter.getItemCount()); }