pablisco
09/15/2017, 10:47 AMdata class LoadedImage(val url: String, val placeholder: Int = 0) {
companion object {
operator fun invoke(url: String, config: LoadedImage.() -> Unit) =
LoadedImage(url).apply(config)
val LOADED_IMAGE_ID = View.generateViewId()
}
}
var ImageView.image: LoadedImage
get() = getTag(LoadedImage.LOADED_IMAGE_ID) as LoadedImage
set(value) {
setTag(LoadedImage.LOADED_IMAGE_ID, value)
Glide.with(this)
.load(value.url)
.apply(RequestOptions().fallback(value.placeholder))
.into(this)
}
This let’s you move the logic out of the core code and if decide to move to another loading library don’t have to change the whole app. And a bit more convenient than using injection 😉