Skip to content

Instantly share code, notes, and snippets.

@feresr
Created July 21, 2021 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feresr/b4c3edb44225fbf970bdfd1ee751a9cc to your computer and use it in GitHub Desktop.
Save feresr/b4c3edb44225fbf970bdfd1ee751a9cc to your computer and use it in GitHub Desktop.
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