xuxiuxi
2017-03-28 bea9fb61c1699079e83d6607b49b2c8d0f486fa0
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.bsk.zhangbo.demoforbsk.adapter;
 
import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
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;
 
import cn.com.basic.face.discern.query.item.VisitorQueryItem;
 
/**
 * 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);
 
        TextView nameTv = (TextView)mLayout.findViewById(R.id.item_visitor_name);
        ImageView photoIv = (ImageView)mLayout.findViewById(R.id.item_visitor_photo);
 
        nameTv.setText("");
 
        Object data = getList().get(posistion);
        if (data instanceof VisitorQueryItem) {
            VisitorQueryItem item = (VisitorQueryItem) data;
            nameTv.setText(item.getName());
        }
 
 
        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;
//        }
//    }
}