package com.ewei.demo.ticket.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.ewei.demo.R;
import com.ewei.sdk.base.BaseListAdapter;
import com.ewei.sdk.constants.TicketValue;
import com.ewei.sdk.entity.Ticket;
import com.ewei.sdk.utility.DateUtils;

/**
 * Created by Administrator on 2016/7/18.
 */
public class TicketListAdapter extends BaseListAdapter<Ticket> {

    public TicketListAdapter(Context context) {
        super(context);
    }

    @Override
    protected int getLayout() {
        return R.layout.listview_item_ticketlist;
    }

    @Override
    protected AbstractViewHolder getViewHolder(View convertView) {
        ItemViewHolder ivh = new ItemViewHolder();
        ivh.mTvStatus = (TextView) convertView.findViewById(R.id.tv_ticket_status);
        ivh.mTvTitle = (TextView) convertView.findViewById(R.id.tv_ticket_title);
        ivh.mTvUpdateTime = (TextView) convertView.findViewById(R.id.tv_ticket_updatetime);
        return ivh;
    }

    @Override
    protected void bindView(AbstractViewHolder viewHolder, Ticket ticket, int position) {
        ItemViewHolder ivh = (ItemViewHolder) viewHolder;
        switch (ticket.getStatus()) {
            case TicketValue.TICKET_STATUS_NEW:
                //未分派的
                ivh.mTvStatus.setBackgroundResource(R.drawable.shape_ticket_status_new);
                ivh.mTvStatus.setTextColor(getmContext().getResources().getColor(R.color.white));
                ivh.mTvStatus.setText("N");
                break;
            case TicketValue.TICKET_STATUS_OPEN:
                //进行中的
                ivh.mTvStatus.setBackgroundResource(R.drawable.shape_ticket_status_open);
                ivh.mTvStatus.setTextColor(getmContext().getResources().getColor(R.color.white));
                ivh.mTvStatus.setText("O");
                break;
            case TicketValue.TICKET_STATUS_SOLVED:
                //处理完毕的
                ivh.mTvStatus.setBackgroundResource(R.drawable.shape_ticket_status_solved);
                ivh.mTvStatus.setTextColor(getmContext().getResources().getColor(R.color.white));
                ivh.mTvStatus.setText("S");
                break;
            case TicketValue.TICKET_STATUS_CLOSED:
                //已关闭的
                ivh.mTvStatus.setBackgroundResource(R.drawable.shape_ticket_status_closed);
                ivh.mTvStatus.setTextColor(getmContext().getResources().getColor(R.color.white));
                ivh.mTvStatus.setText("C");
                break;
            case TicketValue.TICKET_STATUS_PENDING:
                //暂停的
                ivh.mTvStatus.setBackgroundResource(R.drawable.shape_ticket_status_pending);
                ivh.mTvStatus.setTextColor(getmContext().getResources().getColor(R.color.white));
                ivh.mTvStatus.setText("P");
                break;
            case TicketValue.TICKET_STATUS_DELETED:
                //回收站的
                ivh.mTvStatus.setBackgroundResource(R.drawable.shape_ticket_status_deleted);
                ivh.mTvStatus.setTextColor(getmContext().getResources().getColor(R.color.et_text_color));
                ivh.mTvStatus.setText("D");
                break;
            case TicketValue.TICKET_STATUS_SUSPENDED:
                //隔离区的
                ivh.mTvStatus.setBackgroundResource(R.drawable.shape_ticket_status_suspend);
                ivh.mTvStatus.setTextColor(getmContext().getResources().getColor(R.color.white));
                ivh.mTvStatus.setText("S");
                break;
            case TicketValue.TICKET_STATUS_ASSIGN:
                //已分派
                ivh.mTvStatus.setBackgroundResource(R.drawable.shape_ticket_status_assigned);
                ivh.mTvStatus.setTextColor(getmContext().getResources().getColor(R.color.white));
                ivh.mTvStatus.setText("A");
                break;
            default:
                break;
        }

        ivh.mTvTitle.setText(ticket.subject);

        if (!TextUtils.isEmpty(ticket.updatedAt)) {
            ivh.mTvUpdateTime.setText(DateUtils.getIntervalTime(ticket.updatedAt));
        }
    }

    private class ItemViewHolder extends AbstractViewHolder {
        TextView mTvStatus;
        TextView mTvTitle;
        TextView mTvUpdateTime;
    }
}
