package cn.flightfeather.thirdapp.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.thirdapp.R;
|
import cn.flightfeather.thirdapp.bean.Task;
|
import cn.flightfeather.thirdapp.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);
|
}
|
}
|
}
|