In your opinion what is the best library for loadi...
# android
e
In your opinion what is the best library for loading images to use with kotlin?
g
Any Java library works fine. Choose by real differences, pros and cons, after all with extension function you can make API of any library more Kotlin friendly
c
Coil was just released, make by the folks at Instacart https://github.com/coil-kt/coil. I haven’t actually used it yet, but it looks really nice
j
ImageView.setImageBitmap
😂 18
a
Agree with @gildor but i'm also checking
Coil-kt
, looks promising
g
Yes, looks promising, but I think that design of some APIs is not good
For example was pretty confused by mappers API https://coil-kt.github.io/coil/image_pipeline/#mappers
Essentially it encourages to use non safe loadAny function which exposed on API of the library instead of just writing simple extension function that would encapsulate this mapping and will be perfectly type safe and will not blow up on runtime
1
🤔 1
e
The point was: for most usecases the differences with the main image loading libraries (Glide and Picasso) are pretty minor, but we always end up creating a lot of extension functions to make them more comfortable to use in kotlin. I was asking for personal experience and opinions on the matter. I didn't know about
coil
so will definitely check that one out.
👍 1
p
I agree with @gildor regarding `Mapper`s and
loadAny
in Coil. They seem useless to me. Like the example they presented
Copy code
data class Item( val id: Int, val imageUrl: String, val price: Int, val weight: Double )
Copy code
class ItemMapper : Mapper<Item, HttpUrl> {
    override fun map(data: Item): HttpUrl = HttpUrl.get(data.imageUrl)
}
Copy code
ImageView.loadAny(item)
could be simply written as
Copy code
ImageView.load(item.imageUrl)
I don't understand why they convert the
imageUrl
to
HttpUrl
object. Am I missing something?
g
I think it's just an URL abstraction. Their example can be also replaced with one single extension:
Copy code
fun ImageLoader.load(item: Item) = load(item.imageUrl)
And if you really want to abstract image loading details, better than abstract togethether with image loading library, if it's really necessary
3
j
I've been meaning to do an API review
👍 2