Join Slack
Does anyone know if it's possible to get the image size from coil image loader? After loading my ima...
# android
c
Colton Idle
04/24/2020, 6:51 AM
Does anyone know if it's possible to get the image size from coil image loader? After loading my image I want to show a toast with the size in KB or MB.
c
Colin White
04/24/2020, 8:38 AM
That isn’t possible in Coil’s API, but you could probably declare an OkHttp interceptor that shows a toast with the request body size:
https://square.github.io/okhttp/interceptors/#interceptors
Colin White
04/24/2020, 8:39 AM
Also here’s how to set a custom OkHttp client on your ImageLoader instance:
https://coil-kt.github.io/coil/recipes/#using-a-custom-okhttpclient
c
Colton Idle
04/24/2020, 4:16 PM
Thanks. That's helpful!
Colton Idle
07/11/2020, 6:58 PM
@Colin White
is there any benefit to setting a custom okhttp client if you don't need any customizations on the client itself?
c
Colin White
07/14/2020, 4:18 AM
If you already have an OkHttpClient instance (say, for Retrofit) you can create a new instance using
newBuilder
and pass it to your ImageLoader. This will let your ImageLoader share connections + threads with Retrofit and save some memory:
https://square.github.io/okhttp/4.x/okhttp/okhttp3/-ok-http-client/#okhttpclients-should-be-shared
Colin White
07/14/2020, 4:18 AM
Also here’s an example:
https://coil-kt.github.io/coil/recipes/#using-a-custom-okhttpclient
👍 1
12
Views
Open in Slack
Previous
Next
kotlinlang
A modern programming language that makes developers happier.
Powered by