package com.sheep.gamegroup.view.adapter;

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

import com.sheep.gamegroup.model.entity.TaskState;
import com.sheep.jiuyan.samllsheep.R;

import java.util.List;

/**
 * Created by ljy on 2018/3/25.
 */

public class TaskStateAdapter extends BaseAdapter {
    private Context context;
    private List<TaskState> stateList;

    public TaskStateAdapter(Context context, List<TaskState> stateList) {
        this.context = context;
        this.stateList = stateList;
    }

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

    @Override
    public TaskState getItem(int position) {
        return stateList.get(position);
    }

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

    @SuppressLint("ResourceAsColor")
    @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.task_state_item, null);
            holder.line_view = convertView.findViewById(R.id.line_view);
            holder.name_tv = convertView.findViewById(R.id.name_tv);
            holder.point_iv = convertView.findViewById(R.id.point_iv);
            convertView.setTag(holder);
        }
        holder.name_tv.setText(getItem(position).getName()+"");
        if(getItem(position).getStatus() == 1){

            holder.point_iv.setImageResource(R.mipmap.tast_state_piont_ok_img);
            holder.line_view.setBackgroundColor(context.getResources().getColor(R.color.yellow2_end));
            holder.name_tv.setTextColor(context.getResources().getColor(R.color.yellow2_end));
        }else {

            holder.point_iv.setImageResource(R.mipmap.tast_state_piont_no_img);
            holder.line_view.setBackgroundColor(context.getResources().getColor(R.color.txt_black_9e9c9c));
            holder.name_tv.setTextColor(context.getResources().getColor(R.color.black));
        }
        if(position == getCount()-1){
            holder.line_view.setVisibility(View.GONE);
        }else {
            holder.line_view.setVisibility(View.VISIBLE);
        }

        return convertView;
    }

    class ViewHolder{
        ImageView point_iv;
        View line_view;
        TextView name_tv;
    }

}
