Skip to content

Instantly share code, notes, and snippets.

@feresr
Created Jul 21, 2021
Embed
What would you like to do?
ImageView
fun ImageView.loadFromCloudinary(
resource: String,
onSuccess: () -> Unit = {},
onError: () -> Unit = {},
configure: (RequestBuilder<Drawable>) -> Unit = {},
mediaManager : MediaManager = MediaManager.get()
) = doOnLayout {
val transformation: EagerTransformation? = EagerTransformation().fetchFormat("webp")
val cloudinaryUrl = mediaManager.url().transformation(transformation)
mediaManager.responsiveUrl(ResponsiveUrl.Preset.AUTO_FILL)
.generate(cloudinaryUrl, this) { url ->
val request = Glide.with(context).load(url.generate(resource)).addListener(
object : RequestListener<Drawable> { ... },
)
configure(request)
request.into(this)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment