{"action":"opened","issue":{"url":"https://api.github.com/repos/StanKocken/EfficientAdapter/issues/27","repository_url":"https://api.github.com/repos/StanKocken/EfficientAdapter","labels_url":"https://api.github.com/repos/StanKocken/EfficientAdapter/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/StanKocken/EfficientAdapter/issues/27/comments","events_url":"https://api.github.com/repos/StanKocken/EfficientAdapter/issues/27/events","html_url":"https://github.com/StanKocken/EfficientAdapter/issues/27","id":163110407,"number":27,"title":"【improve】 support head、footView","user":{"login":"xiaobaDev","id":5645220,"avatar_url":"https://avatars.githubusercontent.com/u/5645220?v=3","gravatar_id":"","url":"https://api.github.com/users/xiaobaDev","html_url":"https://github.com/xiaobaDev","followers_url":"https://api.github.com/users/xiaobaDev/followers","following_url":"https://api.github.com/users/xiaobaDev/following{/other_user}","gists_url":"https://api.github.com/users/xiaobaDev/gists{/gist_id}","starred_url":"https://api.github.com/users/xiaobaDev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiaobaDev/subscriptions","organizations_url":"https://api.github.com/users/xiaobaDev/orgs","repos_url":"https://api.github.com/users/xiaobaDev/repos","events_url":"https://api.github.com/users/xiaobaDev/events{/privacy}","received_events_url":"https://api.github.com/users/xiaobaDev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-06-30T08:33:59Z","updated_at":"2016-06-30T08:33:59Z","closed_at":null,"body":"add custom headView、footView\r\n```\r\npublic class HeadFootRecyclerAdapter<T> extends EfficientRecyclerAdapter<T> {\r\n    private static final int HEAD_VIEW_TYPE = 3300;\r\n    private static final int FOOT_VIEW_TYPE = HEAD_VIEW_TYPE + 1;\r\n\r\n    private View mHeadView;\r\n    private View mFootView;\r\n\r\n    public HeadFootRecyclerAdapter(List<T> objects) {\r\n        super(objects);\r\n    }\r\n\r\n    public HeadFootRecyclerAdapter(int layoutResId, Class<? extends EfficientViewHolder<? extends T>> viewHolderClass, List<T> objects) {\r\n        super(layoutResId, viewHolderClass, objects);\r\n    }\r\n\r\n    public void setHeadView(View headView) {\r\n        mHeadView = headView;\r\n        notifyDataSetChanged();\r\n    }\r\n\r\n    public void setFootView(View footView) {\r\n        mFootView = footView;\r\n        notifyDataSetChanged();\r\n    }\r\n\r\n    public boolean hasHeadView() {\r\n        return mHeadView != null;\r\n    }\r\n\r\n    public boolean hasFootView() {\r\n        return mFootView != null;\r\n    }\r\n\r\n    public void removeHeadView() {\r\n        if (!hasHeadView()) return;\r\n\r\n        mHeadView = null;\r\n        notifyDataSetChanged();\r\n    }\r\n\r\n    public void removeFootView() {\r\n        if (!hasFootView()) return;\r\n\r\n        mFootView = null;\r\n        notifyDataSetChanged();\r\n    }\r\n\r\n    @Override\r\n    public int getItemCount() {\r\n        int count = super.getItemCount();\r\n\r\n        if (mHeadView != null)\r\n            count++;\r\n\r\n        if (mFootView != null)\r\n            count++;\r\n\r\n        return count;\r\n    }\r\n\r\n    public int getRealCount() {\r\n        return super.getItemCount();\r\n    }\r\n\r\n    public int getRealPosition(int position) {\r\n        if (mHeadView != null) {\r\n            position--;\r\n        }\r\n\r\n        return position;\r\n    }\r\n\r\n    @Override\r\n    public int getItemViewType(int position) {\r\n        if (mHeadView != null && position == 0) {\r\n            return HEAD_VIEW_TYPE;\r\n        }\r\n\r\n        if (mFootView != null && position == getItemCount() - 1) {\r\n            return FOOT_VIEW_TYPE;\r\n        }\r\n\r\n        return super.getItemViewType(position);\r\n    }\r\n\r\n    @Override\r\n    public EfficientViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {\r\n        if (viewType == HEAD_VIEW_TYPE && mHeadView != null) {\r\n            return new EfficientViewHolder(mHeadView) {\r\n                @Override\r\n                protected void updateView(Context context, Object object) {\r\n\r\n                }\r\n            };\r\n        }\r\n\r\n        if (viewType == FOOT_VIEW_TYPE && mFootView != null) {\r\n            return new EfficientViewHolder(mFootView) {\r\n                @Override\r\n                protected void updateView(Context context, Object object) {\r\n\r\n                }\r\n            };\r\n        }\r\n\r\n        return super.onCreateViewHolder(parent, viewType);\r\n    }\r\n\r\n    @Override\r\n    public void onBindViewHolder(EfficientViewHolder viewHolder, int position) {\r\n        int viewType = getItemViewType(position);\r\n\r\n        if (viewType == HEAD_VIEW_TYPE || viewType == FOOT_VIEW_TYPE) return;\r\n\r\n\r\n        position = getRealPosition(position);\r\n        super.onBindViewHolder(viewHolder, position);\r\n    }\r\n}\r\n\r\n\r\n```"}}
{"actor":{"display_login":"xiaobaDev"}}