package com.hanwha.morakmorak.ui.main.home.detail.info

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.BindingAdapter
import androidx.databinding.DataBindingUtil
import com.hanwha.morakmorak.R
import com.hanwha.morakmorak.data.remote.model.Participant
import com.hanwha.morakmorak.databinding.ViewHomeDetailMemberBinding

/**
 * Created by aaron on 10/09/2019
 */

@BindingAdapter("participants")
fun setParticipants(view: View, participants: List<Participant>?) {
    (view as? ViewGroup)?.removeAllViews()
    participants?.let {
        for (p in participants) {
            val binding = DataBindingUtil.inflate<ViewHomeDetailMemberBinding>(
                    LayoutInflater.from(view.context),
                    R.layout.view_home_detail_member,
                    view as ViewGroup, false)
            binding.participant = p
            view.addView(binding.parentConstraintLayout)
        }
    }
}