package com.sheep.gamegroup.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sheep.gamegroup.model.entity.TaskChild;
import com.sheep.gamegroup.util.CommonUtil;
import com.sheep.jiuyan.samllsheep.R;

import java.util.List;

/**
 * Created by ljy on 2018/5/10.
 */

public class AdpTaskDetailChildListview extends BaseAdapter {
    private List<TaskChild> taskChildList;
    private Context context;

    public AdpTaskDetailChildListview(List<TaskChild> taskChildList, Context context) {
        this.taskChildList = taskChildList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return taskChildList.size();
    }

    @Override
    public Object getItem(int position) {
        return taskChildList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Object tag = convertView == null ? null : convertView.getTag();
        ViewHolder holder;
        if(tag instanceof ViewHolder){
            holder = (ViewHolder) tag;
        }else {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adp_taskdetail_child_listview, null);
            holder.item_name_tv = convertView.findViewById(R.id.item_name_tv);
            holder.item_detail_tv = convertView.findViewById(R.id.item_detail_tv);
            holder.state_task_tv = convertView.findViewById(R.id.state_task_tv);
            convertView.setTag(holder);
        }
        TaskChild taskChild = (TaskChild) getItem(position);
        if(taskChild == null){
            return convertView;
        }
        holder.item_name_tv.setText("·" + taskChild.getName()+"");
        holder.item_detail_tv.setText(taskChild.getAmount()+"元");
        switch (taskChild.getStatus()){
            case 1:
            default:
                holder.state_task_tv.setText("即将开始");
//                holder.state_task_tv.setCompoundDrawablesWithIntrinsicBounds(
//                        context.getResources().getDrawable(R.mipmap.task_dec_begin_open),
//                        null,
//                        null,
//                        null
//                );
                CommonUtil.getInstance()
                        .setDraw2View(
                                context,
                                holder.state_task_tv,
                                R.mipmap.task_dec_begin_open,
                                R.color.black_191919
                        );
                break;
            case 2:

                holder.state_task_tv.setText("可领取 ");
                CommonUtil.getInstance()
                        .setDraw2View(
                                context,
                                holder.state_task_tv,
                                R.mipmap.task_dec_receive,
                                R.color.blue_end
                        );
                break;
            case 3:

                holder.state_task_tv.setText("进行中 ");
                CommonUtil.getInstance()
                        .setDraw2View(
                                context,
                                holder.state_task_tv,
                                R.mipmap.task_dec_ing,
                                R.color.txt_red_ff4a5f
                        );
                break;
            case 4:

                holder.state_task_tv.setText("待审核 ");
                CommonUtil.getInstance()
                        .setDraw2View(
                                context,
                                holder.state_task_tv,
                                R.mipmap.task_dec_to_audit,
                                R.color.yellow2_end
                        );
                break;
            case 5:

                holder.state_task_tv.setText("已完成 ");
                CommonUtil.getInstance()
                        .setDraw2View(
                                context,
                                holder.state_task_tv,
                                R.mipmap.task_dec_approved,
                                R.color.green_60BE5E
                        );
                break;
            case 6:

                holder.state_task_tv.setText("审核失败");
                CommonUtil.getInstance()
                        .setDraw2View(
                                context,
                                holder.state_task_tv,
                                R.mipmap.task_dec_faile,
                                R.color.txt_red_ff4a5f
                        );
                break;
            case 7:

                holder.state_task_tv.setText("已过期 ");
                CommonUtil.getInstance()
                        .setDraw2View(
                                context,
                                holder.state_task_tv,
                                R.mipmap.task_dec_overdue_audit,
                                R.color.black_191919
                        );
                break;
        }

        return convertView;
    }

    class ViewHolder{
        TextView item_name_tv, item_detail_tv, state_task_tv;
    }
}
