package com.wd.workoffice.ui.adapter;


import android.content.Context;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wd.workoffice.R;
import com.wd.workoffice.bean.ProPriceBean;
import com.wd.workoffice.bean.mesBean.ImageBean;
import com.wd.workoffice.bean.mesBean.LogBean;
import com.wd.workoffice.ui.activity.mes.ticket.MesTicketLogActivity;
import com.wd.workoffice.util.WorkUtils;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import cn.jzvd.JzvdStd;

/**
 * Created by flexible on 2018/8/13.
 */

public class MesTicketLogAdapter extends BaseQuickAdapter<LogBean, BaseViewHolder> {
    Context context;
    public MesTicketLogAdapter(int layoutResId, List data) {
        super(layoutResId, data);
    }

    public MesTicketLogAdapter(int layoutResId, @Nullable List<LogBean> data, Context context) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, LogBean item) {
        RecyclerView rvImg = helper.getView(R.id.rv_img);
        rvImg.setLayoutManager(new LinearLayoutManager(helper.getConvertView().getContext(), RecyclerView.HORIZONTAL
                , false));
        List<ImageBean> imgList = item.getAttachments();
        ImgAdapter imgAdapter = new ImgAdapter(R.layout.item_mes_ticket_img, imgList);
        imgAdapter.bindToRecyclerView(rvImg);
        imgAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                if (!WorkUtils.isImg(imgList.get(position).getType())) {
                    JzvdStd.startFullscreenDirectly(context,
                            JzvdStd.class, imgList.get(position).getUrl(), "");
                }
            }
        });
        helper.setText(R.id.tv_time, item.getLogDateTime());
        helper.setText(R.id.tv_name, item.getWriteUserName());
        helper.setText(R.id.tv_content, item.getJobContent());
        helper.setText(R.id.tv_desc, item.getProblemDescription());
        helper.setText(R.id.tv_apply, item.getCustomerDemand());
    }
}

