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
package cn.flightfeather.thirdappmodule.adapter;
 
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
 
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
 
import cn.flightfeather.thirdappmodule.R;
import cn.flightfeather.thirdappmodule.bean.entity.Task;
import cn.flightfeather.thirdappmodule.util.Constant;
 
 
/**
 * Created by note_ff_1602 on 2017/9/14.
 * dayWeekMonthTaskActivity&TasKList1Fragment用于显示任务列表的adapter
 */
 
public class TopClassTaskAdapter extends RecyclerView.Adapter<TopClassTaskAdapter.TopClassTaskHolder> {
 
    private List<Task> mTopClassTaskList;
    private LayoutInflater layoutInflater;
 
    public TopClassTaskAdapter(Context context, List<Task> taskList){
        layoutInflater = LayoutInflater.from(context);
        this.mTopClassTaskList = taskList;
    }
 
    @Override
    public TopClassTaskHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.item_topclass_task,parent,false);
        return new TopClassTaskHolder(view);
    }
 
    @Override
    public void onBindViewHolder(TopClassTaskHolder holder, int position) {
        Task task = mTopClassTaskList.get(position);
        holder.tv_no.setText(String.valueOf(position+1));
        holder.tv_task_name.setText(task.getName());
        String executors = task.getExecutorrealnames();
        executors = executors.replaceAll(Constant.CONNECTOR, Constant.CONNECTOR_FOR_VIEW);
        holder.tv_executors.setText(executors);
        Calendar cal_s = Calendar.getInstance();
        cal_s.setTime(task.getStarttime());
        Calendar cal_e = Calendar.getInstance();
        cal_e.setTime(task.getEndtime());
        int year_s = cal_e.get(Calendar.YEAR);
        int yearDiff = year_s - cal_s.get(Calendar.YEAR);
        int month_s = cal_s.get(Calendar.MONTH)+1;
        int month_e = cal_e.get(Calendar.MONTH)+1;
        int monthDiff = yearDiff * 12 + month_e - month_s;
        String name;
        if (yearDiff == 0) {
            if (monthDiff == 0) {
                name = "%d年%d月";
                name = String.format(Locale.CHINA, name, year_s, month_s);
            } else {
                name = "%d年%d月-%d月";
                name = String.format(Locale.CHINA, name, year_s, month_s, month_e);
            }
        } else {
            name = "%d年%d月-%d年%d月";
            name = String.format(Locale.CHINA, name, year_s, month_s, cal_e.get(Calendar.YEAR), month_e);
        }
        holder.tv_date.setText(name);
        holder.tv_planner.setText(task.getPlannerrealname());
    }
 
    @Override
    public int getItemCount() {
        return mTopClassTaskList.size();
    }
 
    class TopClassTaskHolder extends RecyclerView.ViewHolder {
 
        TextView tv_no;
        TextView tv_task_name;
        TextView tv_executors;
        TextView tv_date;
        TextView tv_planner;
 
        TopClassTaskHolder(View itemView) {
            super(itemView);
            tv_no = (TextView) itemView.findViewById(R.id.tv_no);
            tv_task_name = (TextView) itemView.findViewById(R.id.tv_task_name);
            tv_executors = (TextView) itemView.findViewById(R.id.tv_executors);
            tv_date = (TextView) itemView.findViewById(R.id.tv_date);
            tv_planner = (TextView) itemView.findViewById(R.id.tv_planner);
        }
    }
}