Created
July 29, 2020 17:13
-
-
Save lucaslabs/345a741c3dfcba1c7ddd9391142c49de to your computer and use it in GitHub Desktop.
Binding Adapters as top level functions in Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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