Skip to content

Commit c46bdd1

Browse files
Merge pull request #112 from Omega-R/develop
Expandable recyclerview
2 parents e903d60 + 8ce7415 commit c46bdd1

File tree

57 files changed

+4004
-245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+4004
-245
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
*.iml
22
.gradle
33
/local.properties
4-
/.idea/workspace.xml
4+
/.idea/assetWizardSettings.xml
5+
/.idea/caches
56
/.idea/libraries
7+
/.idea/dictionaries
8+
/.idea/misc.xml
9+
/.idea/workspace.xml
10+
/.idea/markdown-navigator
11+
/.idea/markdown-navigator.xml
612
.DS_Store
713
/build
814
/captures

.idea/misc.xml

Lines changed: 0 additions & 49 deletions
This file was deleted.

README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,139 @@ setLongClickListener(@Nullable OnItemLongClickListener<T> longClickListener)
289289
```
290290
You 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
```
294427
The MIT License

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
<activity android:name=".sections_example.SectionsActivity" />
2323
<activity android:name=".viewpager.ViewPagerActivity" />
2424
<activity android:name=".ListAdapterExample.ListAdapterActivity" />
25+
<activity android:name=".expandable_example.core.ExpandableActivity" />
26+
<activity android:name=".expandable_example.support_sticky.DefaultStickyExpandableActivity" />
27+
<activity android:name=".expandable_example.ChooseExpandableActivity" />
28+
<activity android:name=".expandable_example.sticky_groups.StickyGroupsActivity"></activity>
2529
</application>
2630

2731
</manifest>

app/src/main/java/com/omega_r/omegarecyclerview/MainActivity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ protected void onCreate(Bundle savedInstanceState) {
1919
findViewById(R.id.button_sections).setOnClickListener(this);
2020
findViewById(R.id.button_viewpager).setOnClickListener(this);
2121
findViewById(R.id.button_list_adapter).setOnClickListener(this);
22+
findViewById(R.id.button_expandable_recyclerview).setOnClickListener(this);
2223
}
2324

2425
/**
@@ -27,6 +28,7 @@ protected void onCreate(Bundle savedInstanceState) {
2728
*/
2829
@Override
2930
public void onClick(View view) {
31+
3032
switch (view.getId()) {
3133
case R.id.button_swipe_menu:
3234
AppOmegaIntentBuilder.from(this)
@@ -70,6 +72,13 @@ public void onClick(View view) {
7072
.createIntentHandler()
7173
.startActivity();
7274
break;
75+
case R.id.button_expandable_recyclerview:
76+
AppOmegaIntentBuilder.from(this)
77+
.appActivities()
78+
.chooseExpandableActivity()
79+
.createIntentHandler()
80+
.startActivity();
81+
break;
7382
}
7483
}
7584
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.omega_r.omegarecyclerview.expandable_example;
2+
3+
import android.os.Bundle;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.view.View;
6+
7+
import com.omega_r.libs.omegaintentbuilder.AppOmegaIntentBuilder;
8+
import com.omega_r.omegarecyclerview.R;
9+
10+
import omega.com.annotations.OmegaActivity;
11+
12+
@OmegaActivity
13+
public class ChooseExpandableActivity extends AppCompatActivity implements View.OnClickListener {
14+
15+
@Override
16+
protected void onCreate(Bundle savedInstanceState) {
17+
super.onCreate(savedInstanceState);
18+
setContentView(R.layout.activity_choose_expandable);
19+
20+
findViewById(R.id.button_core).setOnClickListener(this);
21+
findViewById(R.id.button_sticky_support).setOnClickListener(this);
22+
}
23+
24+
@Override
25+
public void onClick(View v) {
26+
switch (v.getId()) {
27+
case R.id.button_core:
28+
AppOmegaIntentBuilder.from(this)
29+
.appActivities()
30+
.expandableActivity()
31+
.createIntentHandler()
32+
.startActivity();
33+
break;
34+
case R.id.button_sticky_support:
35+
AppOmegaIntentBuilder.from(this)
36+
.appActivities()
37+
.defaultStickyExpandableActivity()
38+
.createIntentHandler()
39+
.startActivity();
40+
break;
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)