Skip to content

An Android architecture using Retrofit, Coroutines, dependency inversion (Api Service), LiveData, ViewModel, LCE, Activity

Notifications You must be signed in to change notification settings

aidanmack/android_coroutine-_livedate_architecture

Repository files navigation

Android - Coroutine Livedate architecture

An Android architecture using Retrofit, coroutines, dependency inversion, LiveData, ViewModel, LCE, Activity, Last Adapter.

To demonstrate this architecture it uses the publicly available SpaceX API to list SpaceX rockets and landing pads.

Space X demo

The flow of data in this Android architecture from top to bottom can be summarized as:

Top

⬇️

  • Coroutines - To make the above API calls they must be run asynchronously off the main thread. This is done by running a Deferred task created by Retrofit within a CoroutineScope

⬇️

  • Dependency Inversion - Dependency Inversion is used for the service that supplies the LiveDataApiModels. This should help to make the ViewModels easier to test.

⬇️

  • LiveData - LiveData objects can be created in the concrete service class that implements interface for inversion.

⬇️

  • ViewModel - The project uses the ViewModel class (part of the Android Jetpack suite of libraries) to store and manage UI - related data in a lifecycle conscious way. The relevant service using inversion is injected into the ViewModel

⬇️

  • LCE - In alot of cases when an apps UI is working with HTTP data it needs to know about 3 different states (Loading, Content, Error). The LCE is a wrapper for the SpaceX content and reflects the states that this data could be in.

⬇️

  • Activity - Observers a LiveData object in the ViewModel called show of type LCE. The Activity uses the emited object from the LiveData to update relevant UI views.

⬇️

  • LastAdapter - The app then need to display lists of either rockets or Landing pads. To do so the app uses a RecyclerView. To create the adapters for these RecyclerViews the app uses a library called LastAdapter for a simple approach.
Bottom

About

An Android architecture using Retrofit, Coroutines, dependency inversion (Api Service), LiveData, ViewModel, LCE, Activity

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages