package com.hongyegroup.cpt_parttime.adapter

import android.text.Html
import android.text.TextUtils
import android.view.ViewGroup
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.guadou.lib_baselib.engine.extLoad
import com.guadou.lib_baselib.ext.checkEmpty
import com.guadou.lib_baselib.utils.CommUtils
import com.hongyegroup.cpt_parttime.R
import com.hongyegroup.cpt_parttime.bean.HowToReportBean

class How2ReportAdapter(data: MutableList<HowToReportBean>) :
    BaseQuickAdapter<HowToReportBean, BaseViewHolder>(R.layout.item_part_job_how_report, data) {

    override fun convert(holder: BaseViewHolder, item: HowToReportBean) {
        holder.setIsRecyclable(false)  //设置不回收

        holder.setText(R.id.tv_how_report_title, item.title)
            .setGone(R.id.tv_how_report_title, item.title.checkEmpty())

        val llHowReportBox = holder.getView<ViewGroup>(R.id.ll_how_report_box)

        llHowReportBox.removeAllViews()
        if (!item.img.checkEmpty()) {
            item.img.forEach { url ->
                val inflaterView = CommUtils.inflate(R.layout.view_how_to_report_image)
                val imageView = inflaterView.findViewById<ImageView>(R.id.iv_view_how_to_report_image)
                imageView.extLoad(url)
                llHowReportBox.addView(inflaterView)
            }
        }

        //设置文本
        if (!TextUtils.isEmpty(item.important_notice)) {
            //显示富文本
            val spanned = Html.fromHtml(item.important_notice)
            holder.setText(R.id.tv_how_report_des, spanned)
                .setGone(R.id.tv_how_report_des, false)
        } else {
            //显示文本
            holder.setGone(R.id.tv_how_report_des, item.text.checkEmpty())
            holder.setText(R.id.tv_how_report_des, item.text)
        }
    }

}