Skip to content

Instantly share code, notes, and snippets.

@lucaslabs
Created July 29, 2020 17:13
Show Gist options
  • Save lucaslabs/345a741c3dfcba1c7ddd9391142c49de to your computer and use it in GitHub Desktop.
Save lucaslabs/345a741c3dfcba1c7ddd9391142c49de to your computer and use it in GitHub Desktop.
Binding Adapters as top level functions in Kotlin
package com.example.datamerge.presentation.binding
import android.graphics.drawable.Drawable
import android.widget.ImageView
import android.widget.TextView
import androidx.databinding.BindingAdapter
import com.bumptech.glide.request.RequestListener
import com.example.datamerge.presentation.base.GlideApp
// Top Level Functions
@BindingAdapter("android:text")
fun setTextViewResource(view: TextView, resId: Int) {
view.setText(resId)
}
@BindingAdapter(value = ["imageUrl", "imageRequestListener"], requireAll = false)
fun setImageUrl(imageView: ImageView, url: String?, listener: RequestListener<Drawable?>?) {
GlideApp.with(imageView)
.load(url)
.listener(listener)
.into(imageView)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment