Created
July 21, 2021 14:23
-
-
Save feresr/b4c3edb44225fbf970bdfd1ee751a9cc to your computer and use it in GitHub Desktop.
ImageView
This file contains hidden or 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
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