Skip to content

A sample application demoing some of the latest and greatest Android patterns, practices, and tools such as Android Jetpack.

Notifications You must be signed in to change notification settings

trevorhalvorson/star-wars-explorer

Repository files navigation

Star Wars Explorer

A sample application demoing some of the latest and greatest Android patterns, practices, and tools such as Android Jetpack.

Star Wars data provided by SWAPI.

Architecture

This app follows Android's guide to app architecture by implementing strong separation of concerns and a model-driven UI. More specifically, the UI (view) is separated from the data (model) layer with an Android ViewModel.

As an example, the following diagram outlines how the people list screen functions:

                    PeopleListFragment
                            |
                            v
                    PeopleListViewModel
                            |
                            v
                -----PeopleRepository-----
                |                        |
                v                        v
            Room/SQLite                SWAPI
                            

PeopleListFragment listens for UI state updates emitted by PeopleListViewModel via a StateFlow. PeopleListFragment listens for these updates in a coroutine tied to it's lifecycle to ensure updates are only processed when the UI is visible (LifecycleScope).

PeopleListViewModel listens for data updates emitted by PeopleRepository via a Flow. It does this in a coroutine tied the ViewModel ensuring the coroutine will be canceled when the ViewModel is no longer in use (ViewModelScope).

As the interface to our data sources, PeopleRepository is responsible for fetching the underlying people data. Our data sources are a SQLite DB and an HTTP web service. As described previously, PeopleRepository will return a Flow to the ViewModel. This Flow will come directly from our database. This pattern allows us to treat our database as the single source of truth where the ViewModel will listen for changes to our database which may be updated asynchronously with data fetched from the network.

Additionally, this application uses a single-activity/multiple fragment architecture with navigation managed by the Navigation component.

Dependencies (selected)

This project uses a Gradle buildSrc directory to simplify our dependency management and versioning. (see buildSrc in the root of the project)

Tools/other

About

A sample application demoing some of the latest and greatest Android patterns, practices, and tools such as Android Jetpack.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages