Skip to content

tr4n/android-sample

Repository files navigation

Android Architecture Blueprints - Use Cases/Interactors in Domain layer

Summary

This sample is written in Kotlin which uses the following Architecture Components:

  • ViewModel
  • LiveData
  • Navigation
  • Room

The layer called domain where the Use Cases (also called Interactors) live. The domain layer is where the business logic happens, which is the code that determines what the app does with the data coming from the repository before it's exposed to the UI for display.

The TMDb app is too simple to showcase a complete representation of Clean Architecture, but it adheres to some of its rules, which work well in a modern Android application: separation of concerns, high level of abstraction and the dependency rule, which in our case means that layers only know about what's directly underneath them:

  • Presentation layer knows about use cases (domain layer).
  • Domain layer knows about repository (data layer) but not the Presentation layer.
  • Data layer doesn't know about domain or presentation layers.

This allows for easier testing and maintenance and recommended for bigger projects (alongside modularization).

Differences with master

  • ViewModels don't receive a repository but a set of Use Cases, which are reused throughout the presentation layer.
  • Business logic that was present in ViewModels is moved to Use Cases. This is important because ViewModels tend to grow quickly in size in real applications.

Key files

The only relevant use case in this example is GetFavoriteMoviesUseCase. It contains some business logic that used to be in the ViewModel. It's decoupled from the view so it can be thoroughly unit tested in GetFavoriteMoviesUseCaseTest.

Built With 🛠

  • Kotlin - First class and official programming language for Android development.

  • Coroutines - For asynchronous and more..

  • Android Architecture Components - Collection of libraries that help you design robust, testable, and maintainable apps.

    • LiveData - Data objects that notify views when the underlying database changes.
    • ViewModel - Stores UI-related data that isn't destroyed on UI changes.
    • ViewBinding - Generates a binding class for each XML layout file present in that module and allows you to more easily write code that interacts with views.
    • Room - SQLite object mapping library.
  • Dependency Injection -

    • Koin - Koin is a dependency injection framework for Kotlin developers and it is written in pure Kotlin.
  • Retrofit - A type-safe HTTP client for Android and Java.

  • Gson - Gson is a Java library that can be used to convert Java Objects into their JSON representation.

  • Gson Converter - A Converter which uses Gson for serialization to and from JSON.

  • Logging-Interceptor - An OkHttp interceptor which logs HTTP request and response data.

  • Glide - Glide is a fast and efficient open source media management and image loading framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.

  • Material Components for Android - Modular and customizable Material Design UI components for Android.

  • Paging - The Paging Library makes it easier for you to load data gradually and gracefully within your app's RecyclerView.

  • Navigation - Navigation refers to the interactions that allow users to navigate across, into, and back out from the different pieces of content within your app.

  • Gradle Kotlin DSL - For writing Gradle build scripts using Kotlin.

Lint ✅

This project uses GitHub Super Linter which is Combination of multiple linters to install as a GitHub Action.

Following Linters are used internally by super linter (enabled for this project):

Detekt 🗡️

Detekt helps you write cleaner Kotlin code so you can focus on what matters the most building amazing software.

Koin DI Version 🗡️

If you want to use Koin - Dependency Injection framework in app then visit below repository.

Contributed By: JohanForce

Package Structure

.
|                       # Base Recycleview/ DiffUtil
│                       # Base UI: Activity/ Fragment/ Dialog
├── base                # Base ViewModel
│  
├── data   
│   ├── entity          # For data handling.
│   ├── local           # Local Persistence Database. Room (SQLite) database
|   │   ├── dao         # Data Access Object for Room   
│   ├── remote          # Remote Data Handlers     
|   │   ├── api         # Retrofit API for remote end point.
│   └── repository      # Single source of data.
|
├── domain             
│   ├── mapper          # converter to model
│   ├── model           # Model classes
│   ├── repository      # interface repository from data layer
│   └── usecase         # implement data flow logic
│
│
├── di                  # Dependency Injection             
│   ├── builder         # Activity Builder
│   ├── component       # DI Components       
│   └── module          # DI Modules
|
├── ui                  # Activity/View layer
│   ├── base            # Base View
│   ├── main            # Main Screen Activity & ViewModel
|   │   ├── adapter     # Adapter for RecyclerView
|   │   └── viewmodel   # ViewHolder for RecyclerView   
│   └── details         # Detail Screen Activity and ViewModel
|
└── common/utils              # Utility Classes / Kotlin extensions

Architecture

This app uses MVVM (Model View View-Model) architecture.

Contact

If you need any help, you can connect with me.

Visit:- Johan Force

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages