package com.soundapp.soundgags.setting

import android.content.Context
import android.content.Intent
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.soundapp.soundgags.datame.Familiar
import com.soundapp.soundgags.databinding.ItemHomeTransBinding
import com.soundapp.soundgags.ui.OpenSetActivity
import com.bumptech.glide.Glide
import java.util.Random

class HomeTransAdapter: RecyclerView.Adapter<HomeTransAdapter.DoubleViewHolder>() {
    private lateinit var context:Context
    private var beanList :List<Familiar> = arrayListOf()


    class DoubleViewHolder(val binding: ItemHomeTransBinding): RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DoubleViewHolder {
        context=parent.context
        val binding=ItemHomeTransBinding.inflate(LayoutInflater.from(context),parent,false)
        return DoubleViewHolder(binding)
    }
    override fun getItemCount(): Int {
        return beanList.size
    }
    override fun onBindViewHolder(holder: DoubleViewHolder, position: Int) {
        val minHeight = 200
        val maxHeight = 280
        val random = Random()
        val myBean = beanList[position]
        val covert: String = myBean.convert
        Log.d("covert",covert)
        Glide.with(context).load(covert).into(holder.binding.image)
        holder.binding.title.text = myBean.name
        holder.binding.imgRelay.setOnClickListener {
            val intent = Intent(context, OpenSetActivity::class.java)
            intent.putExtra(OpenSetActivity.KEY_LIST_DATA, myBean)
            context.startActivity(intent)
        }
    }
    fun setList(list: List<Familiar>){
        this.beanList=list
    }
}