package com.ysnows.base.binding

import android.graphics.drawable.Drawable
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import coil.load

object ImageBindingAdapter {

    @BindingAdapter(value = ["url", "drawable"], requireAll = false)
    @JvmStatic
    fun setUrlWithDrawable(view: ImageView, url: String?, drawable: Drawable?) {
        if (!url.isNullOrEmpty()) {
            view.load(url)
        }

        if (drawable != null) {
            view.load(drawable)
        }


    }

    @BindingAdapter("android:src")
    @JvmStatic
    fun setImageDrawable(view: ImageView, drawable: Drawable?) {
        view.setImageDrawable(drawable)
    }

    @BindingAdapter("android:src")
    @JvmStatic
    fun setImageResource(imageView: ImageView, resource: Int) {
        imageView.setImageResource(resource)
    }
}
