Coder Social home page Coder Social logo

download-images-grid's Introduction

API with chain of calls

The app aims to demonstrate the power of a new coroutine combined with data-binding and superior architecture in android app development.

File Structure

File Structure in Android Studio

Folders-

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.

How Does it Work?

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.

  1. clear recycler view holder on onViewRecycled(). This helps in deep activity stack where activities are not destroyed after navigation glide will hold objects.
  2. use RGB_565 instead of ARGB_8888 in glide to load images(has visual impact).
  3. 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:

download-images-grid's People

Contributors

pranimation avatar upendra-bajpai avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.