Skip to content

Commit

Permalink
Merge pull request #142 from Omega-R/develop
Browse files Browse the repository at this point in the history
Fix issues
  • Loading branch information
anton-knyazev authored Aug 23, 2019
2 parents 568163f + 433b21b commit 37a4377
Show file tree
Hide file tree
Showing 18 changed files with 208 additions and 67 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
# Usage
Example of usage in xml layout
```
com.omega_r.libs.omegarecyclerview.OmegaRecyclerView
<com.omega_r.libs.omegarecyclerview.OmegaRecyclerView
android:id="@+id/custom_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -306,7 +306,7 @@ Adding OmegaExpandableRecyclerView to layout:

Create adapter like following:
```
public class ExpandableAdapter extends OmegaExpandableRecyclerView.Adapter<QuoteGlobalInfo, String> {
public class ExpandableAdapter extends OmegaExpandableRecyclerView.Adapter<QuoteGlobalInfo, Quote> {
@Override
protected ExGroupViewHolder provideGroupViewHolder(@NonNull ViewGroup viewGroup) {
Expand Down Expand Up @@ -353,18 +353,19 @@ public class ExpandableAdapter extends OmegaExpandableRecyclerView.Adapter<Quote
}
@Override
protected void onBind(String item) {
textView.setText(item);
protected void onBind(Quote item) {
textView.setText(item.getQuote());
}
}
}
```

Use one of the following methods to set items for adapter or use adapter constructors:
```
void setItems(@NonNull List<ExpandableViewData<G, CH>> expandableViewData)
void setItems(ExpandableViewData<G, CH>... expandableViewData)
void setItems(GroupProvider<G, CH>... groupProviders)
public final void setItems(@NonNull List<ExpandableViewData<G, CH>> expandableViewData)
public final void setItems(ExpandableViewData<G, CH>... expandableViewData)
public final void setItemsAsGroupProviders(GroupProvider<G, CH>... groupProviders)
public final void setItemsAsGroupProviders(@NonNull List<GroupProvider<G, CH>> groupProviders)
```

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

It is available to update only child item using
```
// Adapter
public void notifyChildChanged(CH child)
```

You can set expandMode and childAnimation both with xml attr and programmatically

*Available expandModes are single and multiple*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import com.omega_r.libs.omegarecyclerview.BaseListAdapter;
import com.omega_r.omegarecyclerview.R;

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

@NonNull
@Override
protected ViewHolder provideViewHolder(ViewGroup parent) {
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new SampleViewHolder(parent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
import android.os.Bundle;
import androidx.annotation.LayoutRes;
import androidx.appcompat.app.AppCompatActivity;

import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.RadioButton;

import com.omega_r.libs.omegarecyclerview.expandable_recycler_view.OmegaExpandableRecyclerView;
import com.omega_r.libs.omegarecyclerview.expandable_recycler_view.animation.ExpandableItemAnimator;
import com.omega_r.libs.omegarecyclerview.expandable_recycler_view.animation.standard_animations.DropDownItemAnimator;
import com.omega_r.libs.omegarecyclerview.expandable_recycler_view.animation.standard_animations.FadeItemAnimator;
import com.omega_r.libs.omegarecyclerview.expandable_recycler_view.data.GroupProvider;
import com.omega_r.omegarecyclerview.R;

import java.util.Arrays;
import java.util.List;

import omega.com.annotations.OmegaActivity;

@OmegaActivity
Expand All @@ -27,6 +34,8 @@ protected OmegaExpandableRecyclerView.Adapter provideAdapter() {
return new ExpandableAdapter();
}

private List<? extends GroupProvider<QuoteGlobalInfo, Quote>> items;

@LayoutRes
protected int provideContentLayoutRes() {
return R.layout.activity_expandable;
Expand All @@ -37,9 +46,46 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(provideContentLayoutRes());

createItems();

setupRecyclerView();
setupRadioButtons();
fillAdapter();

findViewById(R.id.button_test_update_child).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Quote quote = items.get(3).provideChilds().get(1);
quote.setQuote("UPDATED QUOTE");
mAdapter.notifyChildChanged(quote);
}
});
}

private void createItems() {
items = Arrays.asList(
SimpleData.from(
new QuoteGlobalInfo(getString(R.string.group_text_1), 1500),
new Quote(getString(R.string.child_text_1))
),
SimpleData.from(
new QuoteGlobalInfo(getString(R.string.group_text_2), 1500),
new Quote(getString(R.string.child_text_2))
),
SimpleData.from(
new QuoteGlobalInfo(getString(R.string.group_text_3), 1914),
new Quote(getString(R.string.child_text_3)),
new Quote(getString(R.string.child_text_5))
),
SimpleData.from(
new QuoteGlobalInfo(getString(R.string.group_text_5), 1914),
new Quote(getString(R.string.child_text_1)),
new Quote(getString(R.string.child_text_2)),
new Quote(getString(R.string.child_text_3)),
new Quote(getString(R.string.child_text_4)),
new Quote(getString(R.string.child_text_5))
)
);
}

protected void setupRecyclerView() {
Expand All @@ -48,19 +94,7 @@ protected void setupRecyclerView() {
}

protected void fillAdapter() {
mAdapter.setItems(
SimpleData.from(new QuoteGlobalInfo(getString(R.string.group_text_1), 1500), getString(R.string.child_text_1)),
SimpleData.from(new QuoteGlobalInfo(getString(R.string.group_text_2), 1500), getString(R.string.child_text_2)),
SimpleData.from(new QuoteGlobalInfo(getString(R.string.group_text_3), 1914),
getString(R.string.child_text_3),
getString(R.string.child_text_5)),
SimpleData.from(new QuoteGlobalInfo(getString(R.string.group_text_5), 1914),
getString(R.string.child_text_1),
getString(R.string.child_text_2),
getString(R.string.child_text_3),
getString(R.string.child_text_4),
getString(R.string.child_text_5))
);
mAdapter.setItemsAsGroupProviders(items);
}

protected void setupRadioButtons() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.omega_r.libs.omegarecyclerview.expandable_recycler_view.OmegaExpandableRecyclerView;
import com.omega_r.omegarecyclerview.R;

public class ExpandableAdapter extends OmegaExpandableRecyclerView.Adapter<QuoteGlobalInfo, String> {
public class ExpandableAdapter extends OmegaExpandableRecyclerView.Adapter<QuoteGlobalInfo, Quote> {

@Override
protected ExGroupViewHolder provideGroupViewHolder(@NonNull ViewGroup viewGroup) {
Expand Down Expand Up @@ -54,8 +54,8 @@ class ExChildViewHolder extends ChildViewHolder {
}

@Override
protected void onBind(String item) {
textView.setText(item);
protected void onBind(Quote item) {
textView.setText(item.getQuote());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.omega_r.omegarecyclerview.expandable_example.core;

public class Quote {
private String mQuote;

public Quote(String quote) {
mQuote = quote;
}

public String getQuote() {
return mQuote;
}

public void setQuote(String quote) {
mQuote = quote;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Quote quote = (Quote) o;
return mQuote.equals(quote.mQuote);
}

@Override
public int hashCode() {
return mQuote.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import java.util.Arrays;
import java.util.List;

public class SimpleData implements GroupProvider<QuoteGlobalInfo, String> {
public class SimpleData implements GroupProvider<QuoteGlobalInfo, Quote> {

private QuoteGlobalInfo mQuoteGlobalInfo;
private List<String> mQuotes;
private List<Quote> mQuotes;

public static SimpleData from(QuoteGlobalInfo title, String... quotes) {
public static SimpleData from(QuoteGlobalInfo title, Quote... quotes) {
return new SimpleData(title, Arrays.asList(quotes));
}

public SimpleData(QuoteGlobalInfo quoteGlobalInfo, List<String> quotes) {
public SimpleData(QuoteGlobalInfo quoteGlobalInfo, List<Quote> quotes) {
mQuoteGlobalInfo = quoteGlobalInfo;
mQuotes = quotes;
}
Expand All @@ -29,11 +29,11 @@ public void setQuoteGlobalInfo(QuoteGlobalInfo quoteGlobalInfo) {
mQuoteGlobalInfo = quoteGlobalInfo;
}

public List<String> getQuotes() {
public List<Quote> getQuotes() {
return mQuotes;
}

public void setQuotes(List<String> quotes) {
public void setQuotes(List<Quote> quotes) {
mQuotes = quotes;
}

Expand All @@ -43,7 +43,7 @@ public QuoteGlobalInfo provideGroup() {
}

@Override
public List<String> provideChilds() {
public List<Quote> provideChilds() {
return mQuotes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import com.omega_r.libs.omegarecyclerview.sticky_decoration.StickyAdapter;
import com.omega_r.libs.omegarecyclerview.sticky_decoration.HeaderStickyDecoration;
import com.omega_r.omegarecyclerview.R;
import com.omega_r.omegarecyclerview.expandable_example.core.Quote;
import com.omega_r.omegarecyclerview.expandable_example.core.QuoteGlobalInfo;

public class DefaultStickyAdapter extends OmegaExpandableRecyclerView.Adapter<QuoteGlobalInfo, String> implements StickyAdapter<DefaultStickyAdapter.StickyViewHolder> {
public class DefaultStickyAdapter extends OmegaExpandableRecyclerView.Adapter<QuoteGlobalInfo, Quote> implements StickyAdapter<DefaultStickyAdapter.StickyViewHolder> {

@Override
protected ExGroupViewHolder provideGroupViewHolder(@NonNull ViewGroup viewGroup) {
Expand All @@ -27,7 +28,7 @@ protected ExChildViewHolder provideChildViewHolder(@NonNull ViewGroup viewGroup)

@Override
public long getStickyId(int position) {
ExpandableViewData<QuoteGlobalInfo, String> item = getItem(position);
ExpandableViewData<QuoteGlobalInfo, Quote> item = getItem(position);
if (item == null) return HeaderStickyDecoration.NO_STICKY_ID;
Integer providedId = item.getStickyId();
return providedId == null ? HeaderStickyDecoration.NO_STICKY_ID : providedId;
Expand Down Expand Up @@ -78,8 +79,8 @@ class ExChildViewHolder extends ChildViewHolder {
}

@Override
protected void onBind(String item) {
textView.setText(item);
protected void onBind(Quote item) {
textView.setText(item.getQuote());
}
}

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_expandable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
android:text="@string/button_use_dropdown"
android:textColor="@color/white"/>

<Button
android:id="@+id/button_test_update_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test_update_child" />

</RadioGroup>

<RadioGroup
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
<string name="button_core">Core</string>
<string name="button_support_sticky">Sticky header support</string>
<string name="button_group_sticky">Group as sticky header</string>
<string name="test_update_child">Test update child</string>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'

// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Mar 06 12:09:01 MSK 2019
#Fri Aug 23 11:22:57 MSK 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
5 changes: 2 additions & 3 deletions omegarecyclerviewlibs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'com.google.android.material:material:1.1.0-alpha02'

implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'com.google.android.material:material:1.1.0-alpha09'
}
Loading

0 comments on commit 37a4377

Please sign in to comment.