package com.bomostory.sceneeditmodule.layermanagement

import android.graphics.drawable.Drawable
import android.support.v7.widget.RecyclerView
import android.view.*
import com.bomostory.sceneeditmodule.basicdata.Actor
import com.example.tfat.myapplication.R
import kotlinx.android.synthetic.main.actor_item.view.*


class LayerAdapter (actorData: ArrayList<Actor>, actorListeners: ArrayList<View.OnTouchListener>) : RecyclerView.Adapter<LayerAdapter.ViewHolder>() {

    var data = actorData
    private var listeners = actorListeners
    override fun getItemCount(): Int {
        return data.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.bind(data[position],listeners[position])
    }

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

    class ViewHolder (view : View) : RecyclerView.ViewHolder(view) {
        fun bind(actor: Actor, onTouchListener: View.OnTouchListener?) {
            itemView.actor_image.setImageDrawable(Drawable.createFromPath(actor.resourcePath))
            itemView.setOnTouchListener(onTouchListener)
        }
    }
}