Created
March 15, 2019 12:46
-
-
Save alz-ahm/12d29f8fdddefd9a331fb0e5091301e2 to your computer and use it in GitHub Desktop.
This file contains 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
//Withoug extension | |
Picasso.get().load(/* image url */).placeholder(/* placeholder */).into(myImageView) | |
//With extension | |
myImageView.load(/* image url */) | |
//Extension definition | |
fun ImageView.load(path: String) { | |
val placeholder = R.id.whatEver | |
var fullPath = path | |
if(path.isBlank()){ | |
setImageResource(placeholder) | |
return | |
} | |
//if its not from the server, it a file from file system and we have to append file prefix otherwise | |
//picasso won't be able to load the image. | |
if(!path.startsWith("http", true)) | |
fullPath = "file://$path" | |
Picasso.get().load(fullPath).placeholder(placeholder).into(this) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment