The app aims to demonstrate the power of a new coroutine combined with data-binding and superior architecture in android app development.
Common contains standard error adapters and UI. Data has models, repo and pagination logics. DI Hilt dependency injection Network has retrofit request apis. UI has activity, adapters, and UI state for handling data and connection status. ViewModels logics to handle data get from repository.
For parallel downloading of images we can use async/await coroutine which will block threads till await completes
val moreUsersFromApiDeferred =async { userRepository.getImages(2)}
val moreUsersFromApisDeferred =async { userRepository.getImages(3)}
val usersFromApi = usersFromApiDeferred.await()
val moreUsersFromApi = moreUsersFromApiDeferred.await()
val moreUsersFromApis = moreUsersFromApisDeferred.await()
For sequential downloading of images we can use async coroutine which will chain one by one api calls
val moreUsersFromApi =userRepository.getImages(2)
val moreUsersFromApis=userRepository.getImages(3)
##For optimization of code
approach:
0. resize image to set exactly in image view by override
in glide.
We have images to load , which are the main cause of memory consumption, we need to optimize bitmap of images.
- clear recycler view holder on onViewRecycled(). This helps in deep activity stack where activities are not destroyed after navigation glide will hold objects.
- use RGB_565 instead of ARGB_8888 in glide to load images(has visual impact).
- fix height of viewholder if view holder has fixed size. we used
binding.rvImages.setHasFixedSize(true)
, since we had view holder with fix height.
Results:
Before | After | |
---|---|---|
sequential | 64 mb | 49 mb |
parallel | 84 mb | 61 mb |
sequential image:
parallel image: