Skip to content

Commit

Permalink
feature: add position param in isForViewType()
Browse files Browse the repository at this point in the history
  • Loading branch information
fbsum committed Jan 26, 2018
1 parent 0c9e896 commit ce20f2e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ComplexDelegate(Activity activity) {
}

@Override
public boolean isForViewType(@NonNull Item item) {
public boolean isForViewType(int position, @NonNull Item item) {
return item instanceof ComplexItem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ContentDelegate(Activity activity) {
}

@Override
public boolean isForViewType(@NonNull Item item) {
public boolean isForViewType(int position, @NonNull Item item) {
return item instanceof ContentItem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ImageDelegate(Activity activity) {
}

@Override
public boolean isForViewType(@NonNull Item item) {
public boolean isForViewType(int position, @NonNull Item item) {
return item instanceof ImageItem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public AdapterDelegate(Activity activity) {
this.layoutInflater = LayoutInflater.from(activity);
}

public abstract boolean isForViewType(@NonNull T item);
public abstract boolean isForViewType(int position, @NonNull T item);

@NonNull
public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ int getItemViewType(List<T> items, int position) {
int delegatesCount = delegates.size();
for (int i = 0; i < delegatesCount; i++) {
AdapterDelegate<T> delegate = delegates.valueAt(i);
if (delegate.isForViewType(items.get(position))) {
if (delegate.isForViewType(position, items.get(position))) {
return delegates.keyAt(i);
}
}
throw new IllegalArgumentException("No AdapterDelegate added that matches position=" + position + " in data source");
throw new IllegalArgumentException("No AdapterDelegate added that matches position =" + position + " in data source");
}

RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Expand Down

0 comments on commit ce20f2e

Please sign in to comment.