Hello there. This is an Android-related question. ...
# coroutines
u
Hello there. This is an Android-related question. I need to load images from some remote source. These images are
BLOB
objects. I implemented a service that fetches these images by leveraging the power of Kotlin
Coroutines
. This service is quite simple, it just exposes a
suspend fun
. I used it as one-shot operation inside a
ViewModel
, so the scoping here was easy. Now I need to use this image loader inside a
RecycerView
. So the scoping there gets tricky: how do I manage a
CoroutineScope
inside a
RecyclerView
? As far as I understand, I cannot use
Glide
,
Picasso
or
Coil
, since it is bound to uri/url image sources. So I need to implement it myself. Where do I start? Should I somehow use a
LifecycleOwner
in order to get that scoping feature? Any help will be very appreciated. 🏅
w
My first guess would be your adapter
or rather, that's what my gut says
a
Correct me if I’m wrong. Since you already have a service that is already doing its “loading” thing, I suggest to let the View (e.g. some Adapter) to only observe the data updates via your AAC ViewModel. Otherwise, you are exposing business scope which is not something the View layer should handle (or be aware of).
u
@Amirul Zin, it could introduce a lot of complexity given that there is a lot of images to load. I would prefer something like
Glide
or
Coil
, but with my custom loading.