https://kotlinlang.org logo
#android
Title
# android
e

Eric Martori

08/22/2019, 3:43 PM
In your opinion what is the best library for loading images to use with kotlin?
g

gildor

08/22/2019, 3:44 PM
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

Casey Brooks

08/22/2019, 3:45 PM
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

jw

08/22/2019, 3:45 PM
ImageView.setImageBitmap
😂 18
a

Alejandro Rios

08/22/2019, 3:46 PM
Agree with @gildor but i'm also checking
Coil-kt
, looks promising
g

gildor

08/22/2019, 3:47 PM
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

Eric Martori

08/22/2019, 3:58 PM
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

pavi2410

08/22/2019, 4:38 PM
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

gildor

08/23/2019, 12:43 AM
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

jw

08/23/2019, 1:09 AM
I've been meaning to do an API review
👍 2