package com.zj365.dc.adapter.shop

import android.widget.LinearLayout
import android.widget.TextView
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.ruffian.library.widget.RImageView
import com.xty.base.adapter.BaseAdapter
import com.xty.common.setImage
import com.xty.network.model.ShopCategoryBean
import com.zj365.dc.R
import de.hdodenhof.circleimageview.CircleImageView

class ShopCategoryAdapter : BaseAdapter<ShopCategoryBean>(R.layout.item_shop_categroy) {
    override fun convert(holder: BaseViewHolder, item: ShopCategoryBean) {

        if (data.size != 8){
            var screenWidth = context.resources.displayMetrics.widthPixels
            val layoutParam = holder.getView<LinearLayout>(R.id.root).layoutParams
            layoutParam.width = screenWidth /4
            holder.getView<LinearLayout>(R.id.root).layoutParams = layoutParam
        }

        var img = holder.getView<RImageView>(R.id.img_category)
        var categoryName = holder.getView<TextView>(R.id.tv_category)
        if (item.isChecked){
            img.borderColor = context.getColor(R.color.col_02c)
            categoryName.setTextColor(context.getColor(R.color.col_02c))
        }else{
            img.borderColor = context.getColor(R.color.white)
            categoryName.setTextColor(context.getColor(R.color.col_313))

        }
        item.pic?.let {
            img.setImage(context,it)

        }
        holder.setText(R.id.tv_category,item.categoryName)

    }
}