package com.mq.zhicang;

import android.support.annotation.Nullable;
import android.text.Html;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mq.mylibrary.ChannelTool;
import com.mq.zhicang.db.ZhiCangEntity;

import java.util.List;

/**
 * 创建人 mQ
 * 创建时间 2019/8/14 0014 19:29
 * 文件名称 LogAdapter
 * 说明:
 **/
public class LogAdapter extends BaseQuickAdapter<ZhiCangEntity, BaseViewHolder> {

    public CallBack mCallBack;

    public LogAdapter(@Nullable List<ZhiCangEntity> data) {
        super(R.layout.item_log, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ZhiCangEntity item) {
        helper
                .setText(R.id.tv_car, item.car)
                .setText(R.id.tv_number, item.work_number)
                .setText(R.id.tv_food_type, item.grain)
                .setText(R.id.tv_house, item.real_house)
                .setText(R.id.tv_position, item.real_position)
                .setText(R.id.tv_keeper, item.keeper)
                .setText(R.id.tv_start_time, item.start_time)
                .setText(R.id.tv_end_time, item.end_time)
        ;


        if (App.mChannelName.equals(ChannelTool.C_SHAN_XI)) {
            // 山西隐藏开始和结束时间
            helper.setGone(R.id.tv_start_time, true)
                    .setGone(R.id.tv_end_time, true);
        } else {
            helper.setGone(R.id.tv_start_time, false)
                    .setGone(R.id.tv_end_time, false);
        }

        helper.getView(R.id.layout_item).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //查看
                if (mCallBack != null) {
                    mCallBack.onLookListener(item);
                }
            }
        });
        helper.getView(R.id.btn_look).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //查看
                if (mCallBack != null) {
                    mCallBack.onLookListener(item);
                }
            }
        });
        helper.getView(R.id.btn_card).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //补卡
                if (mCallBack != null) {
                    mCallBack.onCardListener(item);
                }
            }
        });

    }

    public void setCallBack(CallBack callBack) {
        mCallBack = callBack;
    }

    public interface CallBack {
        public void onLookListener(ZhiCangEntity entity);

        public void onCardListener(ZhiCangEntity entity);
    }
}
