package com.unis.sxzcl.ui.grain_check;

import android.view.View;
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.grain_check.GrainCheckBean;
import com.unis.sxzcl.R;

import org.jetbrains.annotations.NotNull;

import static com.unis.sxzcl.ui.grain_check.GrainCheckHomeFragment.BGY;

/**
 * 包名: com.unis.sxzcl.ui.grain_check
 * 类名: GrainCheckListAdapter
 * 作用描述:
 * 创建人: mQ
 * 创建时间: 2020/12/10 19:22
 * 更新人:
 * 更新时间: 2020/12/10 19:22
 * 更新说明:
 * 版本号: 1.0
 */
public class GrainCheckListAdapter extends BaseQuickAdapter<GrainCheckBean, BaseViewHolder>
        implements LoadMoreModule {

    public Callback mCallback;

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

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

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

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

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

        // 保管员可以查看详情
        if (item.checkPerson.equals(BGY)) {
            holder.getView(R.id.iv_next).setVisibility(View.VISIBLE);
            holder.itemView.setEnabled(true);
        } else {
            holder.getView(R.id.iv_next).setVisibility(View.GONE);
            holder.itemView.setEnabled(false);
        }

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

    }

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

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

}
