Skip to content

Commit

Permalink
EMPTY_LIST for payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
sockeqwe committed Oct 10, 2016
1 parent c5cf236 commit d047d1a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android:
components:
- platform-tools
- tools
- android-23
- android-24
- build-tools-23.0.3
- extra-android-support
- extra-android-m2repository
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public class CatAdapterDelegate extends AdapterDelegate<List<Animal>> {
}
```

Please note that `onBindViewHolder()` last parameter `payloads` is null unless you use from `adpater.notify`. There are more methods like `onViewRecycled(ViewHolder)`, `onFailedToRecycleView(ViewHolder)`,
`onViewAttachedToWindow(ViewHolder)` and `onViewDetachedFromWindow(ViewHolder)` you can override in your `AdapterDelegate` class.


Then an `AnimalAdapter` could look like this:

```java
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

VERSION_NAME=3.0.0-SNAPSHOT
VERSION_NAME=3.0.0
VERSION_CODE=300
GROUP=com.hannesdorfmann

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ public abstract class AbsListItemAdapterDelegate<I extends T, T, VH extends Recy
* @param viewHolder The payloads
*/
protected abstract void onBindViewHolder(@NonNull I item, @NonNull VH viewHolder,
@Nullable List<Object> payloads);
@NonNull List<Object> payloads);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.hannesdorfmann.adapterdelegates3;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import java.util.List;
Expand Down Expand Up @@ -61,7 +60,7 @@ public abstract class AdapterDelegate<T> {
* @param payloads A non-null list of merged payloads. Can be empty list if requires full update.
*/
protected abstract void onBindViewHolder(@NonNull T items, int position,
@NonNull RecyclerView.ViewHolder holder, @Nullable List<Object> payloads);
@NonNull RecyclerView.ViewHolder holder, @NonNull List<Object> payloads);

/**
* Called when a view created by this adapter has been recycled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.support.v4.util.SparseArrayCompat;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import java.util.Collections;
import java.util.List;

/**
Expand Down Expand Up @@ -58,6 +59,7 @@ public class AdapterDelegatesManager<T> {
* This id is used internally to claim that the {@link}
*/
static final int FALLBACK_DELEGATE_VIEW_TYPE = Integer.MAX_VALUE - 1;
private static final List<Object> PAYLOADS_EMPTY_LIST = Collections.emptyList();

/**
* Map for ViewType to AdapterDelegate
Expand Down Expand Up @@ -286,7 +288,7 @@ public void onBindViewHolder(@NonNull T items, int position,
*/
public void onBindViewHolder(@NonNull T items, int position,
@NonNull RecyclerView.ViewHolder viewHolder) {
onBindViewHolder(items, position, viewHolder, null);
onBindViewHolder(items, position, viewHolder, PAYLOADS_EMPTY_LIST);
}

/**
Expand Down

0 comments on commit d047d1a

Please sign in to comment.