picasso-ktx
picasso-ktx copied to clipboard
Kotlin extensions for Picasso image loader
Picasso KTX

Kotlin extensions for Picasso image loader.
- Invoke callback and target with Kotlin DSL.
- Use pre-loaded transformations with extension functions.
- Supports material components Palette alongside too.
Download
dependencies {
compile "com.hendraanggrian.appcompat:picasso-ktx:$version"
}
Snapshots of the development version are available in Sonatype's snapshots repository.
Usage
Common
Call picasso to get global instance of Picasso.
Or buildPicasso to invoke Picasso.Builder.
picasso.load(url).into(imageView)
val myPicasso = buildPicasso {
loggingEnabled(true)
memoryCache(Cache.NONE)
listener { picasso, uri, exception -> }
}
myPicasso.load(url).into(imageView)
Clean declaration of Callback when loading images into ImageView.
picasso.load(url).into(imageView) {
onSuccess {
celebrate()
}
}
Or into Target with Kotlin DSL.
picasso.load(url).into {
onLoaded { bitmap, from ->
process(bitmap)
}
}
Transformations
Transform request using Kotlin extension functions.
picasso.load(url)
.circle()
.into(imageView)
// multiple transformations are also supported
picasso.load(url)
.circle()
.grayscale()
.into(imageView)
Available transformations
| Transformations | |
|---|---|
| crop square | square() |
| crop circle | circle() |
| crop rounded | rounded(radius)rounded(radius, margin)<br> rounded(radius, margin, usedDp) |
| overlay | overlay(color, alpha)overlay(context, colorRes, alpha) |
| grayscale | grayscale() |