package com.hanwha.morakmorak.util

import android.view.View
import androidx.databinding.BindingAdapter

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

@BindingAdapter("onClickFunction")
fun setOnClickFunction(view: View, onClick: (v: View) -> Unit) {
    view.setOnClickListener { onClick(view) }
}

@BindingAdapter("onSelected")
fun setOnSelected(view: View, isSelected: Boolean) {
    view.isSelected = isSelected
}

//@InverseBindingAdapter(attribute = "onSelected", event = "onSelectChanged")
//fun getOnSelected(view: View) = view.isSelected
//
//@BindingAdapter("onSelectChanged")
//fun setSelectChangedListener(view: View, inverseBindingListener: InverseBindingListener) {
//    view.viewTreeObserver.addOnGlobalLayoutListener {
//        inverseBindingListener.onChange()
//    }
//}

@BindingAdapter("android:visibility")
fun setVisibility(view: View, visibility: Boolean) {
    view.visibility = if (visibility) View.VISIBLE else View.GONE
}