package com.example.tfat.myapplication.navigationbar.scene

import android.content.Context
import android.graphics.Bitmap
import android.support.v7.widget.RecyclerView
import android.view.*
import android.widget.ImageView
import com.example.tfat.myapplication.R
import kotlin.collections.ArrayList

class AddSceneAdapter(var context : Context, var data: ArrayList<Bitmap>, onClickListenerList: ArrayList<View.OnClickListener>) : RecyclerView.Adapter<AddSceneAdapter.ViewHolder>() {
    private var bitmapData = data
    private var onClickListenerList = onClickListenerList

    override fun getItemCount(): Int {
        return bitmapData.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.bind(bitmapData?.get(position), position, onClickListenerList)
    }

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

    class ViewHolder (view : View) : RecyclerView.ViewHolder(view) {
        fun bind(bitmap: Bitmap?, position : Int, onClickListenerList: ArrayList<View.OnClickListener>) {
            itemView.findViewById<ImageView>(R.id.new_scene_image).setImageBitmap(bitmap)
            itemView.findViewById<ImageView>(R.id.new_scene_image).setOnClickListener(onClickListenerList[position])
        }
    }
}
