Skip to content

This repository contains a sample app that implements Android architecture with MVVM, navigation component,Glide,Retrofit

Notifications You must be signed in to change notification settings

amritlalsahu5/RandomDogsGenerator

Repository files navigation

RandomDogsGenerator

Kotlin Version AGP Gradle

This is a sample project to demostrate use of various components of Android.

Project characteristics

This project brings to table set of best practices, tools, and solutions:

Tech-stack

Min API level is set to 21, so the presented approach is suitable for over 85% of devices running Android. This project takes advantage of many popular libraries and tools of the Android ecosystem. Most of the libraries are in the stable version unless there is a good reason to use non-stable dependency.

Architecture

The modularized code-base approach provides few benefits:

  • better separation of concerns. Each module has a clear API., Feature related classes life in different modules and can't be referenced without explicit module dependency.
  • features can be developed in parallel eg. by different teams
  • each feature can be developed in isolation, independently from other features
  • faster compile time

Presentation layer

This layer is closest to what the user sees on the screen. The presentation layer is a mix of MVVM (Jetpack ViewModel used to preserve data across activity restart) and MVI (actions modify the common state of the view and then new state is edited to a view via LiveData to be rendered).

common state (for each view) approach derives from Unidirectional Data Flow

Components:

  • View (Fragment) - presents data on the screen and pass user interactions to View Model. Views are hard to test, so they should be as simple as possible.
  • ViewModel - dispatches (through LiveData) state changes to the view and deals with user interactions (these view models are not simply POJO classes).
  • ViewState - common state for a single view
  • NavManager - singleton that facilitates handling all navigation events inside NavHostActivity (instead of separately, inside each view)

Domain layer

This is the core layer of the application. Notice that the domain layer is independent of any other layers. This allows to make domain models and business logic independent from other layers. In other words, changes in other layers will have no effect on domain layer eg. changing database (data layer) or screen UI (presentation layer) ideally will not result in any code change withing domain layer.

Components:

  • UseCase - contains business logic
  • DomainModel - defies the core structure of the data that will be used within the application. This is the source of truth for application data.
  • Repository interface - required to keep the domain layer independent from the data layer (Dependency inversion).

Data layer

Manages application data and exposes these data sources as repositories to the domain layer. Typical responsibilities of this layer would be to retrieve data from the internet and optionally cache this data locally.

Components:

  • Repository is exposing data to the domain layer. Depending on application structure and quality of the external APIs repository can also merge, filter, and transform the data. The intention of these operations is to create high-quality data source for the domain layer, not to perform any business logic (domain layer use case responsibility).

  • Mapper - maps data model to domain model (to keep domain layer independent from the data layer).

  • RetrofitService - defines a set of API endpoints.

  • DataModel - defines the structure of the data retrieved from the network and contains annotations, so Retrofit (Moshi) understands how to parse this network data (XML, JSON, Binary...) this data into objects.

Application flow

Below diagram presents application app flow when a user interacts with the application:
























Design decisions

Read related articles to have a better understanding of underlying design decisions and various trade-offs.

Getting started

There are a few ways to open this project.

Android Studio

  1. Android Studio -> File -> New -> From Version control -> Git
  2. Enter https://github.com/amritlalsahu5/RandomDogsGenerator.git into URL field

Command-line + Android Studio

  1. Run git clone https://github.com/amritlalsahu5/RandomDogsGenerator.git
  2. Android Studio -> File -> Open

Author

Github
Medium

About

This repository contains a sample app that implements Android architecture with MVVM, navigation component,Glide,Retrofit

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages