xuxiuxi
2017-03-20 fe0d3cbc02c0db8e7b18b06e3d027c5502d7fe59
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package com.bsk.zhangbo.demoforbsk.adapter;
 
import android.content.Context;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
 
import com.bsk.zhangbo.demoforbsk.R;
import com.bsk.zhangbo.demoforbsk.util.Constant;
import com.camnter.easyrecyclerview.adapter.EasyRecyclerViewAdapter;
import com.camnter.easyrecyclerview.holder.EasyRecyclerViewHolder;
 
import java.util.List;
 
/**
 * Created by Sinoe on 2017/2/23.
 */
 
public class VisitorRecyclerViewAdapter extends EasyRecyclerViewAdapter {
    private Context mContext;
    private int type, mTypeColor;
    private List list;
    private TextView mTvName, mTvDepartment;
    public static final int TYPE_NAME = 10000;
    public static final int TYPE_DEPARTMENT = 10001;
 
    public VisitorRecyclerViewAdapter(Context mContext, int type) {
        this.mContext = mContext;
        this.type = type;
    }
 
    @Override
    public int[] getItemLayouts() {
        return new int[]{R.layout.item_visitor_from, R.layout.item_visitor_to};
    }
 
    @Override
    public void onBindRecycleViewHolder(EasyRecyclerViewHolder viewHolder, int position) {
        switch (type) {
            case Constant.VISITOR_FROM:
                VisitorFromViewHolder(viewHolder, position);
                break;
            case Constant.VISITOR_TO:
                VisitorToViewHolder(viewHolder, position);
                break;
        }
    }
 
    @Override
    public int getRecycleViewItemType(int position) {
        switch (type) {
            case Constant.VISITOR_FROM:
                return 0;
            case Constant.VISITOR_TO:
                return 1;
            default:
                return 1;
        }
    }
 
    /**
     * 来访人Holder
     *
     * @param holder
     * @param posistion
     */
    private void VisitorFromViewHolder(EasyRecyclerViewHolder holder, int posistion) {
        LinearLayout mLayout = holder.findViewById(R.id.item_visitor_from_base);
        ViewGroup.LayoutParams layoutParams = mLayout.getLayoutParams();
        mLayout.setLayoutParams(layoutParams);
    }
 
    /**
     * 被访问Holder
     *
     * @param holder
     * @param posistion
     */
    private void VisitorToViewHolder(EasyRecyclerViewHolder holder, int posistion) {
        mTvName = holder.findViewById(R.id.item_visitor_to_name);
        mTvDepartment = holder.findViewById(R.id.item_visitor_to_department);
        if (mTypeColor == TYPE_DEPARTMENT) {
            mTvName.setTextColor(mContext.getResources().getColor(R.color.colorText_b));
            mTvDepartment.setTextColor(mContext.getResources().getColor(R.color.colorText_5));
        } else {
            mTvName.setTextColor(mContext.getResources().getColor(R.color.colorText_5));
            mTvDepartment.setTextColor(mContext.getResources().getColor(R.color.colorText_b));
        }
    }
 
    public void setVisitorToColor(int type) {
        this.mTypeColor = type;
    }
//    public void setVisitorToTextColor(int type){
//        switch (type){
//            case TYPE_DEPARTMENT:
//                mTvName.setTextColor(mContext.getResources().getColor(R.color.colorText_b));
//                mTvDepartment.setTextColor(mContext.getResources().getColor(R.color.colorText_5));
//                notifyDataSetChanged();
//                break;
//            case TYPE_NAME:
//                mTvName.setTextColor(mContext.getResources().getColor(R.color.colorText_5));
//                mTvDepartment.setTextColor(mContext.getResources().getColor(R.color.colorText_b));
//                notifyDataSetChanged();
//                break;
//        }
//    }
}