A kotlin extension to load easily remote images in your ImageView.

the android arsenal - image loaders -  - The Android Arsenal – Image Loaders

Add to gradle in allprojects

maven { url 'https://jitpack.io' }

then add this

compile 'com.github.matteocrippa:Parrot:0.0.6'

Parrot needs to be init once, passing the app context:

then provides you a simple function to tame all your needs:

ImageView.load

This function has the following parameters:

  • url, optional string with current remote url
  • placeholder, optional bitmap placeholder or resource Id
  • caching, you can set your favorite caching , see below
  • manipulate, optional callback returns the image before setting to your imageview, here you can tweak the image
  • onPlaceholder, optional callback returns if a placeholder has been set
  • onComplete, optional callback returns when the image has been applied to the imageview

Caching

Parrot provide an easy way to handle images caching:

  • NetOnly, default option, force always reloading from net
  • NetThenDisk, once and use local version

Simple usage

imageView.loadImage("http://the-most-awesome-image.png")

Callback usage

imageView.loadImage("http://the-most-awesome-image.png", 
    manipulate = { bitmap ->
        // alter bitmap
        bitmap
    }, onComplete = { completed ->
        // do something
    }                                        

Credits

Icon is taken by emojii set by Vincent Le Moign



Source link

LEAVE A REPLY

Please enter your comment!
Please enter your name here