package com.zj365.dc.adapter

import android.content.Context
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.WindowManager
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xty.base.adapter.BaseAdapter
import com.xty.common.LogUtils
import com.xty.common.setImage
import com.xty.network.model.HomeLayoutBean
import com.zj365.dc.R

class HomeTopLayoutAdapter(var mContext: Context): BaseAdapter<HomeLayoutBean.HomeChildBean>(R.layout.item_home_top_layout){
    override fun convert(holder: BaseViewHolder, item: HomeLayoutBean.HomeChildBean) {

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

        }else{
            layoutParam.width = screenWidth /data.size

        }

        holder.getView<LinearLayout>(R.id.root).layoutParams = layoutParam

        holder.getView<ImageView>(R.id.img_top).setImage(context,item.imageUrl)
        holder.setText(R.id.tv_top_name,item.name)
    }

}