package com.zxhyis.tools.ui.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.cbman.roundimageview.RoundImageView
import com.zxhyis.tools.R
import com.zxhyis.tools.logic.ImageAndVideoBean

class HomeAdapter(
    private val dataList:ArrayList<ImageAndVideoBean>,
) :RecyclerView.Adapter<HomeAdapter.ImageAndVideoVH>(){

    inner class ImageAndVideoVH(itemView: View) : RecyclerView.ViewHolder(itemView){
        val image: RoundImageView = itemView.findViewById(R.id.iv_image_video)
        val videoFlag : AppCompatImageView = itemView.findViewById(R.id.video_flag)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ImageAndVideoVH {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_image_video, parent, false)
        return ImageAndVideoVH(view)
    }

    override fun getItemCount(): Int = dataList.size

    override fun onBindViewHolder(holder: ImageAndVideoVH, position: Int) {
        
        val oneData=dataList[position]
        Glide.with(holder.itemView.context)
            .load(oneData.path)
            .into(holder.image)
        
        if (oneData.type==1){
            holder.videoFlag.visibility=View.GONE
        }else{
            holder.videoFlag.visibility=View.VISIBLE
        }
        
    }


}