Skip to content

Commit 37a4377

Browse files
Merge pull request #142 from Omega-R/develop
Fix issues
2 parents 568163f + 433b21b commit 37a4377

File tree

18 files changed

+208
-67
lines changed

18 files changed

+208
-67
lines changed

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dependencies {
3333
# Usage
3434
Example of usage in xml layout
3535
```
36-
com.omega_r.libs.omegarecyclerview.OmegaRecyclerView
36+
<com.omega_r.libs.omegarecyclerview.OmegaRecyclerView
3737
android:id="@+id/custom_recycler_view"
3838
android:layout_width="match_parent"
3939
android:layout_height="match_parent"
@@ -306,7 +306,7 @@ Adding OmegaExpandableRecyclerView to layout:
306306

307307
Create adapter like following:
308308
```
309-
public class ExpandableAdapter extends OmegaExpandableRecyclerView.Adapter<QuoteGlobalInfo, String> {
309+
public class ExpandableAdapter extends OmegaExpandableRecyclerView.Adapter<QuoteGlobalInfo, Quote> {
310310
311311
@Override
312312
protected ExGroupViewHolder provideGroupViewHolder(@NonNull ViewGroup viewGroup) {
@@ -353,18 +353,19 @@ public class ExpandableAdapter extends OmegaExpandableRecyclerView.Adapter<Quote
353353
}
354354
355355
@Override
356-
protected void onBind(String item) {
357-
textView.setText(item);
356+
protected void onBind(Quote item) {
357+
textView.setText(item.getQuote());
358358
}
359359
}
360360
}
361361
```
362362

363363
Use one of the following methods to set items for adapter or use adapter constructors:
364364
```
365-
void setItems(@NonNull List<ExpandableViewData<G, CH>> expandableViewData)
366-
void setItems(ExpandableViewData<G, CH>... expandableViewData)
367-
void setItems(GroupProvider<G, CH>... groupProviders)
365+
public final void setItems(@NonNull List<ExpandableViewData<G, CH>> expandableViewData)
366+
public final void setItems(ExpandableViewData<G, CH>... expandableViewData)
367+
public final void setItemsAsGroupProviders(GroupProvider<G, CH>... groupProviders)
368+
public final void setItemsAsGroupProviders(@NonNull List<GroupProvider<G, CH>> groupProviders)
368369
```
369370

370371
Your view data (group and childs) should be wrapped with ```ExpandableViewData``` using one of the following ways:
@@ -387,6 +388,12 @@ public interface GroupProvider<G, CH> {
387388
}
388389
```
389390

391+
It is available to update only child item using
392+
```
393+
// Adapter
394+
public void notifyChildChanged(CH child)
395+
```
396+
390397
You can set expandMode and childAnimation both with xml attr and programmatically
391398

392399
*Available expandModes are single and multiple*

app/src/main/java/com/omega_r/omegarecyclerview/ListAdapterExample/ListAdapter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.view.ViewGroup;
44
import android.widget.TextView;
55

6+
import androidx.annotation.NonNull;
67
import com.omega_r.libs.omegarecyclerview.BaseListAdapter;
78
import com.omega_r.omegarecyclerview.R;
89

@@ -13,8 +14,9 @@ public ListAdapter(BaseListAdapter.OnItemClickListener<String> clickListener,
1314
super(clickListener, longClickListener);
1415
}
1516

17+
@NonNull
1618
@Override
17-
protected ViewHolder provideViewHolder(ViewGroup parent) {
19+
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
1820
return new SampleViewHolder(parent);
1921
}
2022

app/src/main/java/com/omega_r/omegarecyclerview/expandable_example/core/ExpandableActivity.java

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@
33
import android.os.Bundle;
44
import androidx.annotation.LayoutRes;
55
import androidx.appcompat.app.AppCompatActivity;
6+
7+
import android.view.View;
8+
import android.widget.Button;
69
import android.widget.CompoundButton;
710
import android.widget.RadioButton;
811

912
import com.omega_r.libs.omegarecyclerview.expandable_recycler_view.OmegaExpandableRecyclerView;
1013
import com.omega_r.libs.omegarecyclerview.expandable_recycler_view.animation.ExpandableItemAnimator;
1114
import com.omega_r.libs.omegarecyclerview.expandable_recycler_view.animation.standard_animations.DropDownItemAnimator;
1215
import com.omega_r.libs.omegarecyclerview.expandable_recycler_view.animation.standard_animations.FadeItemAnimator;
16+
import com.omega_r.libs.omegarecyclerview.expandable_recycler_view.data.GroupProvider;
1317
import com.omega_r.omegarecyclerview.R;
1418

19+
import java.util.Arrays;
20+
import java.util.List;
21+
1522
import omega.com.annotations.OmegaActivity;
1623

1724
@OmegaActivity
@@ -27,6 +34,8 @@ protected OmegaExpandableRecyclerView.Adapter provideAdapter() {
2734
return new ExpandableAdapter();
2835
}
2936

37+
private List<? extends GroupProvider<QuoteGlobalInfo, Quote>> items;
38+
3039
@LayoutRes
3140
protected int provideContentLayoutRes() {
3241
return R.layout.activity_expandable;
@@ -37,9 +46,46 @@ protected void onCreate(Bundle savedInstanceState) {
3746
super.onCreate(savedInstanceState);
3847
setContentView(provideContentLayoutRes());
3948

49+
createItems();
50+
4051
setupRecyclerView();
4152
setupRadioButtons();
4253
fillAdapter();
54+
55+
findViewById(R.id.button_test_update_child).setOnClickListener(new View.OnClickListener() {
56+
@Override
57+
public void onClick(View v) {
58+
Quote quote = items.get(3).provideChilds().get(1);
59+
quote.setQuote("UPDATED QUOTE");
60+
mAdapter.notifyChildChanged(quote);
61+
}
62+
});
63+
}
64+
65+
private void createItems() {
66+
items = Arrays.asList(
67+
SimpleData.from(
68+
new QuoteGlobalInfo(getString(R.string.group_text_1), 1500),
69+
new Quote(getString(R.string.child_text_1))
70+
),
71+
SimpleData.from(
72+
new QuoteGlobalInfo(getString(R.string.group_text_2), 1500),
73+
new Quote(getString(R.string.child_text_2))
74+
),
75+
SimpleData.from(
76+
new QuoteGlobalInfo(getString(R.string.group_text_3), 1914),
77+
new Quote(getString(R.string.child_text_3)),
78+
new Quote(getString(R.string.child_text_5))
79+
),
80+
SimpleData.from(
81+
new QuoteGlobalInfo(getString(R.string.group_text_5), 1914),
82+
new Quote(getString(R.string.child_text_1)),
83+
new Quote(getString(R.string.child_text_2)),
84+
new Quote(getString(R.string.child_text_3)),
85+
new Quote(getString(R.string.child_text_4)),
86+
new Quote(getString(R.string.child_text_5))
87+
)
88+
);
4389
}
4490

4591
protected void setupRecyclerView() {
@@ -48,19 +94,7 @@ protected void setupRecyclerView() {
4894
}
4995

5096
protected void fillAdapter() {
51-
mAdapter.setItems(
52-
SimpleData.from(new QuoteGlobalInfo(getString(R.string.group_text_1), 1500), getString(R.string.child_text_1)),
53-
SimpleData.from(new QuoteGlobalInfo(getString(R.string.group_text_2), 1500), getString(R.string.child_text_2)),
54-
SimpleData.from(new QuoteGlobalInfo(getString(R.string.group_text_3), 1914),
55-
getString(R.string.child_text_3),
56-
getString(R.string.child_text_5)),
57-
SimpleData.from(new QuoteGlobalInfo(getString(R.string.group_text_5), 1914),
58-
getString(R.string.child_text_1),
59-
getString(R.string.child_text_2),
60-
getString(R.string.child_text_3),
61-
getString(R.string.child_text_4),
62-
getString(R.string.child_text_5))
63-
);
97+
mAdapter.setItemsAsGroupProviders(items);
6498
}
6599

66100
protected void setupRadioButtons() {

app/src/main/java/com/omega_r/omegarecyclerview/expandable_example/core/ExpandableAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import com.omega_r.libs.omegarecyclerview.expandable_recycler_view.OmegaExpandableRecyclerView;
88
import com.omega_r.omegarecyclerview.R;
99

10-
public class ExpandableAdapter extends OmegaExpandableRecyclerView.Adapter<QuoteGlobalInfo, String> {
10+
public class ExpandableAdapter extends OmegaExpandableRecyclerView.Adapter<QuoteGlobalInfo, Quote> {
1111

1212
@Override
1313
protected ExGroupViewHolder provideGroupViewHolder(@NonNull ViewGroup viewGroup) {
@@ -54,8 +54,8 @@ class ExChildViewHolder extends ChildViewHolder {
5454
}
5555

5656
@Override
57-
protected void onBind(String item) {
58-
textView.setText(item);
57+
protected void onBind(Quote item) {
58+
textView.setText(item.getQuote());
5959
}
6060
}
6161
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.omega_r.omegarecyclerview.expandable_example.core;
2+
3+
public class Quote {
4+
private String mQuote;
5+
6+
public Quote(String quote) {
7+
mQuote = quote;
8+
}
9+
10+
public String getQuote() {
11+
return mQuote;
12+
}
13+
14+
public void setQuote(String quote) {
15+
mQuote = quote;
16+
}
17+
18+
@Override
19+
public boolean equals(Object o) {
20+
if (this == o) return true;
21+
if (o == null || getClass() != o.getClass()) return false;
22+
Quote quote = (Quote) o;
23+
return mQuote.equals(quote.mQuote);
24+
}
25+
26+
@Override
27+
public int hashCode() {
28+
return mQuote.hashCode();
29+
}
30+
}

app/src/main/java/com/omega_r/omegarecyclerview/expandable_example/core/SimpleData.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
import java.util.Arrays;
88
import java.util.List;
99

10-
public class SimpleData implements GroupProvider<QuoteGlobalInfo, String> {
10+
public class SimpleData implements GroupProvider<QuoteGlobalInfo, Quote> {
1111

1212
private QuoteGlobalInfo mQuoteGlobalInfo;
13-
private List<String> mQuotes;
13+
private List<Quote> mQuotes;
1414

15-
public static SimpleData from(QuoteGlobalInfo title, String... quotes) {
15+
public static SimpleData from(QuoteGlobalInfo title, Quote... quotes) {
1616
return new SimpleData(title, Arrays.asList(quotes));
1717
}
1818

19-
public SimpleData(QuoteGlobalInfo quoteGlobalInfo, List<String> quotes) {
19+
public SimpleData(QuoteGlobalInfo quoteGlobalInfo, List<Quote> quotes) {
2020
mQuoteGlobalInfo = quoteGlobalInfo;
2121
mQuotes = quotes;
2222
}
@@ -29,11 +29,11 @@ public void setQuoteGlobalInfo(QuoteGlobalInfo quoteGlobalInfo) {
2929
mQuoteGlobalInfo = quoteGlobalInfo;
3030
}
3131

32-
public List<String> getQuotes() {
32+
public List<Quote> getQuotes() {
3333
return mQuotes;
3434
}
3535

36-
public void setQuotes(List<String> quotes) {
36+
public void setQuotes(List<Quote> quotes) {
3737
mQuotes = quotes;
3838
}
3939

@@ -43,7 +43,7 @@ public QuoteGlobalInfo provideGroup() {
4343
}
4444

4545
@Override
46-
public List<String> provideChilds() {
46+
public List<Quote> provideChilds() {
4747
return mQuotes;
4848
}
4949

app/src/main/java/com/omega_r/omegarecyclerview/expandable_example/support_sticky/DefaultStickyAdapter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
import com.omega_r.libs.omegarecyclerview.sticky_decoration.StickyAdapter;
1212
import com.omega_r.libs.omegarecyclerview.sticky_decoration.HeaderStickyDecoration;
1313
import com.omega_r.omegarecyclerview.R;
14+
import com.omega_r.omegarecyclerview.expandable_example.core.Quote;
1415
import com.omega_r.omegarecyclerview.expandable_example.core.QuoteGlobalInfo;
1516

16-
public class DefaultStickyAdapter extends OmegaExpandableRecyclerView.Adapter<QuoteGlobalInfo, String> implements StickyAdapter<DefaultStickyAdapter.StickyViewHolder> {
17+
public class DefaultStickyAdapter extends OmegaExpandableRecyclerView.Adapter<QuoteGlobalInfo, Quote> implements StickyAdapter<DefaultStickyAdapter.StickyViewHolder> {
1718

1819
@Override
1920
protected ExGroupViewHolder provideGroupViewHolder(@NonNull ViewGroup viewGroup) {
@@ -27,7 +28,7 @@ protected ExChildViewHolder provideChildViewHolder(@NonNull ViewGroup viewGroup)
2728

2829
@Override
2930
public long getStickyId(int position) {
30-
ExpandableViewData<QuoteGlobalInfo, String> item = getItem(position);
31+
ExpandableViewData<QuoteGlobalInfo, Quote> item = getItem(position);
3132
if (item == null) return HeaderStickyDecoration.NO_STICKY_ID;
3233
Integer providedId = item.getStickyId();
3334
return providedId == null ? HeaderStickyDecoration.NO_STICKY_ID : providedId;
@@ -78,8 +79,8 @@ class ExChildViewHolder extends ChildViewHolder {
7879
}
7980

8081
@Override
81-
protected void onBind(String item) {
82-
textView.setText(item);
82+
protected void onBind(Quote item) {
83+
textView.setText(item.getQuote());
8384
}
8485
}
8586

app/src/main/res/layout/activity_expandable.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
android:text="@string/button_use_dropdown"
3030
android:textColor="@color/white"/>
3131

32+
<Button
33+
android:id="@+id/button_test_update_child"
34+
android:layout_width="wrap_content"
35+
android:layout_height="wrap_content"
36+
android:text="@string/test_update_child" />
37+
3238
</RadioGroup>
3339

3440
<RadioGroup

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@
3232
<string name="button_core">Core</string>
3333
<string name="button_support_sticky">Sticky header support</string>
3434
<string name="button_group_sticky">Group as sticky header</string>
35+
<string name="test_update_child">Test update child</string>
3536
</resources>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
google()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.3.2'
10+
classpath 'com.android.tools.build:gradle:3.5.0'
1111
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1212

1313
// NOTE: Do not place your application dependencies here; they belong

0 commit comments

Comments
 (0)