Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add vararg delegate parameter to AsyncListDifferDelegationAdapter #76

Merged
merged 8 commits into from
Sep 5, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ public AbsDelegationAdapter(@NonNull AdapterDelegatesManager<T> delegatesManager
* @since 4.1.0
*/
public AbsDelegationAdapter(@NonNull AdapterDelegate<T>... delegates) {
this();
for (int i = 0; i < delegates.length; i++) {
delegatesManager.addDelegate(delegates[i]);
}
this(new AdapterDelegatesManager<T>(delegates));
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ public class AdapterDelegatesManager<T> {
*/
protected SparseArrayCompat<AdapterDelegate<T>> delegates = new SparseArrayCompat();
protected AdapterDelegate<T> fallbackDelegate;

/**
* Creates a AdapterDelegatesManager without any delegates.
*/
public AdapterDelegatesManager() {
}

/**
* Creates a AdapterDelegatesManager which already has the gived delegates added to it.
*/
public AdapterDelegatesManager(@NonNull AdapterDelegate<T>... delegates) {
for (int i = 0; i < delegates.length; i++) {
addDelegate(delegates[i]);
}
}

/**
* Adds an {@link AdapterDelegate}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,41 @@ public AsyncListDifferDelegationAdapter(@NonNull AsyncDifferConfig differConfig,
this.differ = new AsyncListDiffer<T>(new AdapterListUpdateCallback(this), differConfig);
this.delegatesManager = delegatesManager;
}

/**
* Adds a list of {@link AdapterDelegate}s
*
* @param delegates
* @since 4.2.0
*/
public AsyncListDifferDelegationAdapter(@NonNull DiffUtil.ItemCallback<T> diffCallback,
@NonNull AdapterDelegate<List<T>>... delegates) {

if (diffCallback == null) {
throw new NullPointerException("ItemCallback is null");
}

this.differ = new AsyncListDiffer<T>(this, diffCallback);
this.delegatesManager = new AdapterDelegatesManager<List<T>>(delegates);
}


/**
* Adds a list of {@link AdapterDelegate}s
*
* @param delegates
* @since 4.2.0
*/
public AsyncListDifferDelegationAdapter(@NonNull AsyncDifferConfig differConfig,
@NonNull AdapterDelegate<List<T>>... delegates) {

if (differConfig == null) {
throw new NullPointerException("AsyncDifferConfig is null");
}

this.differ = new AsyncListDiffer<T>(new AdapterListUpdateCallback(this), differConfig);
this.delegatesManager = new AdapterDelegatesManager<List<T>>(delegates);
}

@NonNull
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public int getItemCount() {
@Test
public void adapterDelegateManagerIsNull() {
try {
AsyncListDifferDelegationAdapter<Object> adapter = new AsyncListDifferDelegationAdapter<Object>(callback, null) {
AsyncListDifferDelegationAdapter<Object> adapter = new AsyncListDifferDelegationAdapter<Object>(callback, (AdapterDelegatesManager) null) {
@Override
public int getItemCount() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public int getItemCount() {
@Test
public void adapterDelegateManagerIsNull() {
try {
AsyncListDifferDelegationAdapter<Object> adapter = new AsyncListDifferDelegationAdapter<Object>(callback, null) {
PagedListDelegationAdapter<Object> adapter = new PagedListDelegationAdapter<Object>(null, callback) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was a copy and paste error and this change made it visible.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nice, thank you

@Override
public int getItemCount() {
return 0;
Expand Down