@@ -289,6 +289,139 @@ setLongClickListener(@Nullable OnItemLongClickListener<T> longClickListener)
289289```
290290You can subscribe to this event on the fly - all view holders will be notified.
291291
292+ ## Expandable
293+ <img src =" /images/exp_fade_single.gif?raw=true " width =" 250 " height =" 400 " /> <img src =" /images/exp_dd_single.gif?raw=true " width =" 250 " height =" 400 " /> <img src =" /images/exp_dd_multi.gif?raw=true " width =" 250 " height =" 400 " />
294+
295+ Adding OmegaExpandableRecyclerView to layout:
296+ ```
297+ <com.omega_r.libs.omegarecyclerview.expandable_recycler_view.OmegaExpandableRecyclerView
298+ android:id="@+id/recyclerview"
299+ android:layout_width="match_parent"
300+ android:layout_height="match_parent"
301+ app:childAnimation="Dropdown"
302+ app:expandMode="single"/>
303+ ```
304+
305+ Create adapter like following:
306+ ```
307+ public class ExpandableAdapter extends OmegaExpandableRecyclerView.Adapter<QuoteGlobalInfo, String> {
308+
309+ @Override
310+ protected ExGroupViewHolder provideGroupViewHolder(@NonNull ViewGroup viewGroup) {
311+ return new ExGroupViewHolder(viewGroup);
312+ }
313+
314+ @Override
315+ protected ExChildViewHolder provideChildViewHolder(@NonNull ViewGroup viewGroup) {
316+ return new ExChildViewHolder(viewGroup);
317+ }
318+
319+ class ExGroupViewHolder extends GroupViewHolder {
320+
321+ private TextView textView;
322+
323+ ExGroupViewHolder(ViewGroup parent) {
324+ super(parent, R.layout.item_exp_group);
325+ textView = findViewById(R.id.textview_group_name);
326+ }
327+
328+ @Override
329+ protected void onExpand(GroupViewHolder viewHolder, int groupIndex) {
330+ // nothing
331+ }
332+
333+ @Override
334+ protected void onCollapse(GroupViewHolder viewHolder, int groupIndex) {
335+ // nothing
336+ }
337+
338+ @Override
339+ protected void onBind(QuoteGlobalInfo item) {
340+ textView.setText(item.getTitle());
341+ }
342+ }
343+
344+ class ExChildViewHolder extends ChildViewHolder {
345+
346+ private TextView textView;
347+
348+ ExChildViewHolder(ViewGroup parent) {
349+ super(parent, R.layout.item_exp_child);
350+ textView = findViewById(R.id.textview_child_content);
351+ }
352+
353+ @Override
354+ protected void onBind(String item) {
355+ textView.setText(item);
356+ }
357+ }
358+ }
359+ ```
360+
361+ Use one of the following methods to set items for adapter or use adapter constructors:
362+ ```
363+ void setItems(@NonNull List<ExpandableViewData<G, CH>> expandableViewData)
364+ void setItems(ExpandableViewData<G, CH>... expandableViewData)
365+ void setItems(GroupProvider<G, CH>... groupProviders)
366+ ```
367+
368+ Your view data (group and childs) should be wrapped with ``` ExpandableViewData ``` using one of the following ways:
369+ ```
370+ ExpandableViewData(G group, List<CH> childs, @Nullable Integer stickyId) // constructor
371+
372+ static <G, CH> ExpandableViewData<G, CH> of(G group, @Nullable Integer stickyId, List<CH> childs)
373+ static <G, CH> ExpandableViewData<G, CH> of(G group, @Nullable Integer stickyId, CH... childs)
374+ ```
375+
376+ Or it should implement interface
377+ ```
378+ public interface GroupProvider<G, CH> {
379+ G provideGroup();
380+
381+ List<CH> provideChilds();
382+
383+ @Nullable
384+ Integer provideStickyId();
385+ }
386+ ```
387+
388+ You can set expandMode and childAnimation both with xml attr and programmatically
389+
390+ * Available expandModes are single and multiple*
391+
392+ * Available childAnimations are Dropdown and Fade*
393+
394+ You can simply create your own animations by extending ``` ExpandableItemAnimator ``` class and then just set it to RecyclerView ``` recyclerView.setItemAnimator ```
395+
396+ <img src =" /images/exp_bg.gif?raw=true " width =" 250 " height =" 400 " />
397+
398+ It is possible to emulate background expanding using "app: backgrounds " attribute.
399+
400+ Create LevelListDrawable in res/drawable folder
401+
402+ * expandable_backgrounds.xml*
403+ ```
404+ <?xml version="1.0" encoding="utf-8"?>
405+ <level-list xmlns:android="http://schemas.android.com/apk/res/android">
406+ <item android:maxLevel="@integer/backgroundGroupCollapsed" android:drawable="@drawable/group_collapsed" />
407+ <item android:maxLevel="@integer/backgroundGroupExpanded" android:drawable="@drawable/group_expanded" />
408+ <item android:maxLevel="@integer/backgroundFirstChild" android:drawable="@drawable/child_bg" />
409+ <item android:maxLevel="@integer/backgroundLastChild" android:drawable="@drawable/child_last" />
410+ <item android:maxLevel="@integer/backgroundChild" android:drawable="@drawable/child_bg" />
411+ </level-list>
412+ ```
413+
414+ And then just add ``` app:backgrounds="@drawable/expandable_backgrounds" ``` attribute to your OmegaExpandableRecyclerView
415+
416+ <img src =" /images/exp_sticky_sup.gif?raw=true " width =" 250 " height =" 400 " /> <img src =" /images/exp_sticky_group.gif?raw=true " width =" 250 " height =" 400 " /> <img src =" /images/exp_sticky_all.gif?raw=true " width =" 250 " height =" 400 " />
417+
418+ OmegaExpandableRecyclerView have 2 ways of using Sticky Header feature: Default (that is described above in StickyHeader section) and StickyGroups. Last one is the way to make GroupViewHolders work as StickyHeaders.
419+
420+ To do that just add ``` app:stickyGroups="true" ``` attribute to your OmegaExpandableRecyclerView and be sure that you set items providing unique ``` stickyId ``` for each group.
421+
422+ And, of course, you CAN use both sticky behaviors at the same time
423+
424+
292425# License
293426```
294427The MIT License
0 commit comments