package com.unis.sxzcl.ui.quantity_quality;

import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.unis.model.bean.QuantityQualityBean;
import com.unis.sxzcl.R;

import org.jetbrains.annotations.NotNull;


/**
 * 库存质量列表适配器
 * 创建人: mQ
 * 时间: 2021/2/1 17:24
 */
public class QuantityQualityListAdapter extends BaseQuickAdapter<QuantityQualityBean, BaseViewHolder>
        implements LoadMoreModule {

    public Callback mCallback;

    public QuantityQualityListAdapter() {
        super(R.layout.item_list_grain_check);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, QuantityQualityBean item) {

        holder.setText(R.id.tv_time, item.getCreateTime());

        ImageView imageView = holder.getView(R.id.iv_show);
        TextView tvStatus = holder.getView(R.id.tv_status);

        String saveState = item.getSaveState();
        if (saveState != null && saveState.equals("0")) {
            // 已完成
            imageView.setImageResource(R.drawable.ic_finish_accent);
            tvStatus.setText("已完成");
        } else {
            // 进行中
            imageView.setImageResource(R.drawable.ic_wait_blue);
            tvStatus.setText("进行中");
        }

        holder.itemView.setTag(item);
        holder.itemView.setOnClickListener(v -> {
            if (mCallback != null)
                mCallback.onItemClickListener((QuantityQualityBean) v.getTag());
        });

    }

    public void setCallback(Callback callback) {
        mCallback = callback;
    }

    public interface Callback {
        void onItemClickListener(QuantityQualityBean item);
    }

}
