public interface SeizeAdapter<VH extends RecyclerView.ViewHolder> {

    void setParentAdapter(RecyclerView.Adapter<VH> parentAdapter);

    void setHeader(@NonNull View view);

    void setFooter(@NonNull View view);

    boolean isHeader(int subPosition);

    boolean isFooter(int subPosition);

    boolean hasViewType(int viewType);

    int getItemViewType(SeizePosition seizePosition);

    VH onCreateViewHolder(ViewGroup parent, int viewType);

    void onBindViewHolder(VH holder, SeizePosition seizePosition);

    int getItemCount();

    long getItemId(int position);

    int subPositionToSubSourcePosition(int subPosition);

    int subSourcePositionToSubPosition(int subSourcePosition);

    void notifyDataSetChanged();

} public class SeizePosition implements Serializable{
    private int seizeAdapterIndex;
    private int position;
    private int sourcePosition;
    private int subPosition;
    private int subSourcePosition;

    public SeizePosition(int seizeAdapterIndex, int position, int sourcePosition, int subPosition, int subSourcePosition) {
        this.seizeAdapterIndex = seizeAdapterIndex;
        this.position = position;
        this.sourcePosition = sourcePosition;
        this.subPosition = subPosition;
        this.subSourcePosition = subSourcePosition;
    }

    public int getSeizeAdapterIndex() {
        return seizeAdapterIndex;
    }

    public void setSeizeAdapterIndex(int seizeAdapterIndex) {
        this.seizeAdapterIndex = seizeAdapterIndex;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public int getSubPosition() {
        return subPosition;
    }

    public void setSubPosition(int subPosition) {
        this.subPosition = subPosition;
    }

    public int getSubSourcePosition() {
        return subSourcePosition;
    }

    public void setSubSourcePosition(int subSourcePosition) {
        this.subSourcePosition = subSourcePosition;
    }

    public int getSourcePosition() {
        return sourcePosition;
    }

    public void setSourcePosition(int sourcePosition) {
        this.sourcePosition = sourcePosition;
    }

    @Override
    public String toString() {
        return "SeizePosition{" +
                "seizeAdapterIndex=" + seizeAdapterIndex +
                ", position=" + position +
                ", sourcePosition=" + sourcePosition +
                ", subPosition=" + subPosition +
                ", subSourcePosition=" + subSourcePosition +
                '}';
    }
} public interface Func1R<Param1, Result> {
    Result call(Param1 param1);
} public class MultiSeizeAdapter<T> extends BaseSeizeAdapter {
    /**
     * Get type function
     */
    private Func1R<T, Integer> getItemType;
    /**
     * Map -> key: type; value: viewHolderOwner creation function
     */
    private SparseArray<ViewHolderOwner> viewHolderOwnerMap = new SparseArray<>();

    public void setGetItemType(Func1R<T, Integer> getItemType) {
        this.getItemType = getItemType;
    }

    public void addSupportViewHolder(int type, ViewHolderOwner viewHolderOwner) {
        viewHolderOwnerMap.put(type, viewHolderOwner);
    }

    private List<T> list = new ArrayList<>();

    public List<T> getList() {
        return list;
    }

    public void addList(List<T> list) {
        this.list.addAll(list);
    }

    public void setList(List<T> list) {
        if (null == list) {
            this.list = new ArrayList<>();
        } else {
            this.list = list;
        }
    }

    @Override
    public int getSourceItemViewType(int subSourcePosition) {
        if (null != getItemType) {
            return getItemType.call(list.get(subSourcePosition));
        }
        return super.getSourceItemViewType(subSourcePosition);
    }

    @Override
    public BaseViewHolder onCreateTypeViewHolder(ViewGroup parent, int type) {
        ViewHolderOwner viewHolderOwner = viewHolderOwnerMap.get(type);
        if (null != viewHolderOwner) {
            return viewHolderOwner.createViewHolder(parent);
        }
        return null;
    }

    @Override
    public Object getItem(int subSourcePosition) {
        return list.get(subSourcePosition);
    }

    @Override
    public int getSourceItemCount() {
        return list.size();
    }


} public class FeedAdapter extends BaseRecyclerAdapter {

} public class FilmActorAViewHolderOwner extends ViewHolderOwner implements FilmActorAViewHolder.OnFilmActorAViewHolderListener {
    public FilmActorAViewHolderOwner(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder createViewHolder(ViewGroup parent) {
        FilmActorAViewHolder holder = new FilmActorAViewHolder(parent);
        holder.setOnFilmActorAViewHolderListener(this);
        return holder;
    }

    @Override
    public void onFilmActorAItemClick(int subSourcePosition) {
        Toast.makeText(context, "A actor " + subSourcePosition + " clicked", Toast.LENGTH_SHORT).show();
    }
} public class FilmActorBViewHolderOwner extends ViewHolderOwner implements FilmActorBViewHolder.OnFilmActorBViewHolderListener {
    public FilmActorBViewHolderOwner(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder createViewHolder(ViewGroup parent) {
        FilmActorBViewHolder filmActorBViewHolder = new FilmActorBViewHolder(parent);
        filmActorBViewHolder.setOnFilmActorBViewHolderListener(this);
        return filmActorBViewHolder;
    }

    @Override
    public void onFilmActorBItemClick(int subSourcePosition) {
        Toast.makeText(context, "B actor " + subSourcePosition + " clicked", Toast.LENGTH_SHORT).show();
    }
} public class FilmCommentAViewHolderOwner extends ViewHolderOwner implements FilmCommentAViewHolder.OnFilmCommentAViewHolderListener {
    public FilmCommentAViewHolderOwner(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder createViewHolder(ViewGroup parent) {
        FilmCommentAViewHolder holder = new FilmCommentAViewHolder(parent);
        holder.setOnFilmCommentAViewHolderListener(this);
        return holder;
    }

    @Override
    public void onFilmCommentAItemClick(int subSourcePosition) {
        Toast.makeText(context, "A comment " + subSourcePosition + " clicked", Toast.LENGTH_SHORT).show();
    }
} public class FilmCommentBViewHolderOwner extends ViewHolderOwner implements FilmCommentBViewHolder.OnFilmCommentBViewHolderListener {
    public FilmCommentBViewHolderOwner(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder createViewHolder(ViewGroup parent) {
        FilmCommentBViewHolder filmCommentBViewHolder = new FilmCommentBViewHolder(parent);
        filmCommentBViewHolder.setOnFilmCommentBViewHolderListener(this);
        return filmCommentBViewHolder;
    }

    @Override
    public void onFilmCommentBItemClick(int subSourcePosition) {
        Toast.makeText(context, "B comment " + subSourcePosition + " clicked", Toast.LENGTH_SHORT).show();
    }
} public class ActorAVM extends ActorVM {
    public ActorAVM(String obj) {
        super(obj);
    }

    @Override
    public int getActorViewType() {
        return TYPE_ACTOR_A;
    }
} public class ActorBVM extends ActorVM {
    public ActorBVM(String obj) {
        super(obj);
    }

    @Override
    public int getActorViewType() {
        return TYPE_ACTOR_B;
    }
} public class ActorVM extends VM<String> {
    public static final int TYPE_ACTOR = 10;
    public static final int TYPE_ACTOR_A = 11;
    public static final int TYPE_ACTOR_B = 12;

    public ActorVM(String obj) {
        super(obj);
    }

    @Override
    public int getViewType() {
        return TYPE_ACTOR;
    }

    public int getActorViewType() {
        return TYPE_ACTOR_A;
    }
} public class CommentAVM extends CommentVM {
    public CommentAVM(String obj) {
        super(obj);
    }

    @Override
    public int getCommentViewType() {
        return TYPE_COMMENT_A;
    }
} public class CommentBVM extends CommentVM {
    public CommentBVM(String obj) {
        super(obj);
    }

    @Override
    public int getCommentViewType() {
        return TYPE_COMMENT_B;
    }
} public class CommentVM extends VM<String> {
    public static final int TYPE_COMMENT = 20;
    public static final int TYPE_COMMENT_A = 21;
    public static final int TYPE_COMMENT_B = 22;

    public CommentVM(String obj) {
        super(obj);
    }

    @Override
    public int getViewType() {
        return TYPE_COMMENT;
    }

    public int getCommentViewType() {
        return TYPE_COMMENT_A;
    }
}
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.wangjie.seizerecyclerview.SeizeAdapter;
import com.wangjie.seizerecyclerview.SeizePosition;
import com.wangjie.seizerecyclerview.attacher.Func1R;
import com.wangjie.seizerecyclerview.attacher.MultiSeizeAdapter;
import com.wangjie.seizerecyclerview.example.R;
import com.wangjie.seizerecyclerview.example.basic.adapter.FeedAdapter;
import com.wangjie.seizerecyclerview.example.multitype.adapter.actor.a.FilmActorAViewHolderOwner;
import com.wangjie.seizerecyclerview.example.multitype.adapter.actor.b.FilmActorBViewHolderOwner;
import com.wangjie.seizerecyclerview.example.multitype.adapter.comment.a.FilmCommentAViewHolderOwner;
import com.wangjie.seizerecyclerview.example.multitype.adapter.comment.b.FilmCommentBViewHolderOwner;
import com.wangjie.seizerecyclerview.example.multitype.vm.actor.ActorAVM;
import com.wangjie.seizerecyclerview.example.multitype.vm.actor.ActorBVM;
import com.wangjie.seizerecyclerview.example.vm.actor.ActorVM;
import com.wangjie.seizerecyclerview.example.multitype.vm.comment.CommentAVM;
import com.wangjie.seizerecyclerview.example.multitype.vm.comment.CommentBVM;
import com.wangjie.seizerecyclerview.example.vm.comment.CommentVM;
import java.util.ArrayList;
import java.util.List;
package com.wangjie.seizerecyclerview.example.multitype;




/**
 * Author: wangjie
 * Email: tiantian.china.2@gmail.com
 * Date: 3/29/17.
 */
public class MultiTypeActivity extends AppCompatActivity implements
        View.OnClickListener {

    private FeedAdapter adapter;
    private RecyclerView feedRv;
    private MultiSeizeAdapter<ActorVM> filmActorSeizeAdapter;