Marvel - A simple application to display information about the characters of the Marvel universe

Related tags

App Marvel
Overview

Marvel Characters

'Marvel characters' is a simple application to display information about the characters of the Marvel universe.

You can test the application by installing the following apk.

It uses different patterns and libraries from modern android development, such as Material 3, MVVM, unidirectional data flow, coroutines, Dagger Hilt, view binding, and others.

It contains two screens. One shows a list of characters and another with detailed information about a specific character. Both screens are implemented using fragments:

Fragments are independent, one does not know anything about the other fragment. There is a host activity in charge of managing the navigation by implementing the HomeNavigator interface. This is how the navigation is done from clicking on a character item to show the item detail.

Contents

Architecture

The architecture of this project is based on my interpretation of 'Clean Architecture', an architecture pattern focused on the separation of concerns. Finding the following modules:

The domain layer

Given the simplicity of the project, the domain layer is only made up of entities, if there were any complex business logic, it would be implemented here in the form of use cases.

These entities are used as a 'source of truth' at the boundaries of the other layers. For example, repository in the data layer exposes a list of characters that are consumed in the UI layer by the view models.

The data layer

The responsibility of the data layer is to expose character's data to other parts of the app, and to abstract the source of the data.

For simplicity, the character repository only uses one data source, which implements data extraction from the remote Marvel API.

It would be easy to implement another data source with a database or any other persistence method to enrich this layer. This is the reason why there is an interface to represent a data source.

Concrete benefit of using a repository with data sources

Given the simplicity of the project, access to the data source is implemented with a repository that uses a single data source.

The data source communicates with the Marvel API and returns the data to the repository, using a domain entity: CharacterPreview, or Character.

The detail screen shows the details of a character and a few comics where it appears. A comic, in our domain, contains an image and a portion of text.

Using the Marvel API, this is a somewhat complex task as it requires using multiple endpoints:

  1. Get the details of a character.

  2. Get every comic detail, using the links provided by the detail of a character.

Thanks to the use of data sources, the repository simply expects a list of characters. All the other implementation details related to the Marvel API are encapsulated inside the CharacterRemoteDatasource, making it easily testable.

The UI layer

The UI layer is composed with elements from the android SDK, the implementation of the views and other logic related to the user interface. it aligns with the 'UI layer' guide from official docs.

We could say that the user interface should reflect what the app wants the user to see at a specific moment in time, this could be modeled as states of the UI.

For example, the character list may be loading, displaying the characters, or displaying an error if something unexpected occurs.

In this way, we could define three UI states: Loading, Success & Failure.

  sealed class CharactersViewState {
      object Loading: CharactersViewState()
      class Failure(e: Throwable): CharactersViewState()
      class Success(val characters: List<CharacterPreview>): CharactersViewState()
  }

The view, in this case a fragment, observes a single source of states, and reacts when the viewmodel (in charge of producing states) emits a new state.

A ViewModel is a great component for storing current UI state, as it survives fragment's lifecycle and other configuration changes. Thanks to the use of StateFlow to store the state, it's trivial to restore the last state if a fragment is recreated due to a configuration change.

When a fragment receives a new view state, it's immediately bound into the UI. This way, all views in a fragment are perfectly set to the given view state atomically, avoiding issues where multiples sources or truth are used.

This concept is also known as Unidirectional Data Flow. It provides several benefits like, as the source of the view state is isolated, it's cycle of emissions can be tested easily.

// ...
viewModel.onViewState.test {
    assertThat(awaitItem()).isNull()
    assertThat(awaitItem()).isInstanceOf(Loading::class.java)
    assertThat(awaitItem()).isInstanceOf(Success::class.java)
}

Considerations

Paging

Paging has been implemented in the character list but the jetpack paging library has not been used. Paging is simply accomplished with a callback from the CharacterListAdapter that notifies when the end of the list has been reached.

The reason behind is to have prioritized the architecture, since the paging library, while providing a good experience when loading elements, is a bit aggressive in terms of architecture modeling.

Dagger - Hilt

Dagger-Hilt has been used for dependency injection. Hilt provides a very simple mechanism to inject dependencies with minimal boilerplate into android components. Helping the testability and cleanliness of the code.

Assist injection has also been used, for, among other uses, to be able to insert dynamic parameters in the creation of the view models.

Signing a Marvel Request

The Marvel API, in order to authorize a request, requires that each endpoint must include a ts parameter and a hash that is computed with the private key and a timestamp.

To avoid dirtying each endpoint or duplicating the authorization logic, a MarvelApiServiceAuthenticatorInterceptor has been implemented that adds the necessary parameters to sign each request.

In this way, the logic is encapsulated, and it's easily testable.

Mock web server in unit tests

MockWebServer it's used to test elements of the network layer, such as the signing of requests or the correct mapping of network entities to domain entities.

This library offers an easy and deterministic way to behave like a real network service, without the inconveniences of variable wait times, network problems or changes to the server. Allowing to load existing JSON payloads in the resources folder from the unit tests source root.

You might also like...
Marvel API Demo App

Marvel API Demo app How to set up the API Keys OPEN FILE: gradle.properties ADD (using valid public/private keys): MARVEL_PUBLIC_KEY = "" MARVEL_PRIV

Marvel SuperHeroes

Marvel SuperHeroes Sample app reading from the official Marvel API, containing the following features: A list of all possible superheroes in the Marve

AppUI Sample Application - display how you can create your own custom AppUI application within a few minutes
AppUI Sample Application - display how you can create your own custom AppUI application within a few minutes

AppUI Sample Application This is an open-source project to display how you can create your own custom AppUI application within a few minutes. I have a

RedditNews - A simple application to display the top news from the Reddit API site and save your favorites to a local database.
RedditNews - A simple application to display the top news from the Reddit API site and save your favorites to a local database.

RedditNews - A simple application to display the top news from the Reddit API site and save your favorites to a local database. Arch

Simple android application that consumes RAWG API to display a list of games
Simple android application that consumes RAWG API to display a list of games

Gamex Compose -Work in Progress- An android application that consumes RAWG API to display a list of popular video games built using Jetpack Compose an

An application that displays information about movies getting from The Movie DB
An application that displays information about movies getting from The Movie DB

Movie Project Part One - Display and Search Movie. Create an application that displays information about movies getting from The Movie DB.The movie in

Cryptac - Mobile application to track your favorite cryptos information. ๐Ÿš€
Cryptac - Mobile application to track your favorite cryptos information. ๐Ÿš€

What is it? ๐Ÿค” Cryptac is a mobile application that allows you to track the main important information about your favorite cryptos. It is currently av

Cryptac is a mobile application that allows you to track the main important information about your favorite cryptos
Cryptac is a mobile application that allows you to track the main important information about your favorite cryptos

Cryptac is a mobile application that allows you to track the main important information about your favorite cryptos.

โ˜๏ธ๐ŸŒค๐ŸŒงโ˜€ Weather Android application that gives you the weather information of your saved location or any region you are looking forโ˜๏ธ๐ŸŒค๐ŸŒงโ˜€
โ˜๏ธ๐ŸŒค๐ŸŒงโ˜€ Weather Android application that gives you the weather information of your saved location or any region you are looking forโ˜๏ธ๐ŸŒค๐ŸŒงโ˜€

โ˜๏ธ๐ŸŒค๐ŸŒงโ˜€ Weather Android application that gives you the weather information of your saved location or any region you are looking forโ˜๏ธ๐ŸŒค๐ŸŒงโ˜€

Owner
Saul Molinero
Software engineer
Saul Molinero
Learn about your favorite Marvel characters, super heroes, villains and watch videos from official Marvel youtube channel.

Marvel Super Heroes Android App ?? Learn about your favorite Marvel characters, super heroes, villains and watch videos from official Marvel youtube c

Lucas Cabral 5 May 24, 2022
Android app built with MVP architectural approach and uses Marvel Comics API that allows developers everywhere to access information about Marvel's vast library of comics. :zap:

Villains & Heroes Android app built with MVP architectural approach and uses Marvel Comics API that allows developers everywhere to access information

Andrรฉ Mion 53 Jul 13, 2022
App which show comic and characters using marvel apis

Marvel App App which show comic and characters using marvel apis ScreenShot Tech Room database MVVM Architecture Navigation Component How to run proje

null 2 Jan 1, 2022
Display's information about SpaceX crew members and ships by consuming a rest api and storing the data to display when the user is offline.

Space-X App Display's information about SpaceX crew members(look for โ€˜Crewโ€™ section in rest api docs) and ships (look for โ€˜Shipsโ€™ section in rest api

krishna chaitanya 2 Apr 8, 2022
Movo (Movie Information) is an android application to find out all the Movie Information and Details.

Movo About The Project Screen.Recording.2022-08-12.at.08.53.46_1.mp4 Movo (Movie Information) is an android application to find out all the Movie Info

Reihan Fatilla 4 Sep 28, 2022
Unicopy is an application for Android devices and helps users to copy useful special characters

Unicopy Android Application Unicopy is an application for Android 'Phone' Devices. This helps you to copy and paste some special and complicated Unico

Jacob Lim 1 Oct 28, 2021
โค๏ธ A sample Marvel heroes application based on MVVM (ViewModel, Coroutines, LiveData, Room, Repository, Koin) architecture.

MarvelHeroes MarvelHeroes is a demo application based on modern Android application tech-stacks and MVVM architecture. Fetching data from the network

Jaewoong Eum 1.2k Dec 19, 2022
Hanyang-ktheme-android - Kakaotalk theme with Ha-nyang and other characters from Hanyang University

ํ•œ์–‘๋Œ€ ERICA ์นด์นด์˜คํ†ก ํ…Œ๋งˆ ํ•œ์–‘๋Œ€ ERICA์˜ ์บ๋ฆญํ„ฐ(ํ•˜๋ƒฅ์ด/ํ•˜์ด๋น„๋น„)๋ฅผ ์‚ฌ์šฉํ•œ ์นด์นด์˜คํ†ก ํ…Œ๋งˆ์˜ Android ๋ฒ„์ „์ž…๋‹ˆ๋‹ค. ์บ๋ฆญํ„ฐ์˜ ์ €์ž‘๊ถŒ์€ ํ•œ์–‘๋Œ€ ERICA์— ์žˆ์Šต๋‹ˆ๋‹ค. ์ •๋ณด ์›์ €์ž‘์ž : ํ•œ์–‘๋Œ€ ERICA ๋Œ€์™ธํ˜‘๋ ฅํŒ€ ์ž‘์—…์ž : ์ด์ •์ธ (์ปดํ“จํ„ฐ์ „๊ณต 17) ์นด์นด์˜คํ†ก

Jeongin Lee 0 Jan 5, 2022
Paimondex App is an Android App that contains super mini wiki for playable characters from Genshin Impact, where you can favorite to save the character

Paimondex App is an Android App that contains super mini wiki for playable characters from Genshin Impact, where you can favorite to save the character. This could also show you the description of the each character with their talents and constellations.

Ervin Suriandi 1 Apr 13, 2022
A mobile application that allows you to get random information every time you enter the application.

Knowledge Repository A mobile application that allows you to get random information every time you enter the application. Google Play Store : Screensh

Nisa EfendioฤŸlu 2 Jul 10, 2022