Kotlin extensions for Picasso image loader
Switch branches/tags
Nothing to show
Clone or download
Latest commit 4963ce4 Nov 25, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea Single package Nov 25, 2018
art Remove mp4s Jul 14, 2018
buildSrc Single package Nov 25, 2018
demo Single package Nov 25, 2018
gradle/wrapper Website module Nov 25, 2018
pikasso-commons Single package Nov 25, 2018
pikasso-palette Single package Nov 25, 2018
pikasso-transformations Single package Nov 25, 2018
pikasso Single package Nov 25, 2018
testing Website module Nov 25, 2018
website Single package Nov 25, 2018
.gitignore 0.6.1 Mar 24, 2017
.travis.yml Removed pikasso-placeholders Jun 24, 2018
LICENSE updated LICENSE May 25, 2017
README.md Update README.md Jul 24, 2018
build.gradle.kts Website module Nov 25, 2018
gradle.properties 0.1.0 - first release Jan 18, 2017
gradlew renamed to pikasso Feb 15, 2018
gradlew.bat renamed to pikasso Feb 15, 2018
settings.gradle.kts Website module Nov 25, 2018

README.md

Pikasso

bintray download build license

demo_transformations demo_palette

Kotlin extensions for Picasso image loader.

Consists of several parts:

  • Pikasso Commons: invoke callback and target with Kotlin DSL.
  • Pikasso Transformations: pre-loaded transformations.
  • Pikasso Palette: use support library Palette alongside Picasso.

Download

All artifacts are hosted on jcenter. To download all of them, use main library:

dependencies {
    compile "com.hendraanggrian.pikasso:pikasso:$version"
}

Or download separate library if only specific feature is desired:

dependencies {
    compile "com.hendraanggrian.pikasso:pikasso-commons:$version"
    compile "com.hendraanggrian.pikasso:pikasso-transformations:$version"
    compile "com.hendraanggrian.pikasso:pikasso-palette:$version" 
}

Pikasso Commons

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)
    }
}

Pikasso 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()

Pikasso Palette

Get a palette synchronously from RequestCreator.

val palette = picasso.load(url).palette
val vibrant = palette.getVibrantColor(defaultColor)

Or asynchronously.

picasso.load(url).palette {
    onLoaded { bitmap, from ->
        useVibrant {
            title.setTextColor(it)
        }
    }
}

Alternatively, you can also load image to target image and extract its palette.

picasso.load(url).palette(imageView) {
    onSuccess {
        useMuted {
            layout.setBackgroundColor(it)
        }
    }
}

License

Copyright 2018 Hendra Anggrian

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.