package com.zj365.health.adapter

import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zj365.health.R
import com.xty.network.model.DrugHealthCare
import com.xty.network.model.ItemDrugHealthCare

class DrugCareAdapter() : BaseMultiItemQuickAdapter<DrugHealthCare, BaseViewHolder>() {

    init {
        //0文字  1 文字加图片  2文字加图片加描述
        addItemType(0, R.layout.view_type_text)
        addItemType(1, R.layout.view_type_more_img)
        addItemType(2, R.layout.view_type_more_img)
    }

    override fun convert(holder: BaseViewHolder, item: DrugHealthCare) {
        when (item.itemType) {
            0 -> {
                holder.setText(R.id.tvContent,item.message)
            }
            1 -> {
                holder.setText(R.id.tvTitle,item.message)
                var recycle = holder.getView<RecyclerView>(R.id.recycler)
                recycle.layoutManager = GridLayoutManager(context,item.items.size)
                var mAdapter = DrugImgNameAdapter()
                recycle.adapter = mAdapter
                mAdapter.setNewInstance(item.items as MutableList<ItemDrugHealthCare>)
            }
            2 -> {
                holder.setText(R.id.tvTitle,item.message)
                var recycle = holder.getView<RecyclerView>(R.id.recycler)
                recycle.layoutManager = LinearLayoutManager(context)
                var mAdapter = DrugImgDescAdapter()
                recycle.adapter = mAdapter
                mAdapter.setNewInstance(item.items as MutableList<ItemDrugHealthCare>)
            }
            else -> {}
        }
    }
}