This example is created to demonstrate a custom architecture idea and usage of a multiple tools.
Main reason of view and logic separation is done to make logic testable on a pure JVM, without running an Android emulator.
This app is created to show the idea of the architecture scheme that is:
- easy to test automatically
- modular
- well divided to layers
- cool
Utils used:
- Kotlin Flows - for communication between modules
- Kotlin Coroutines - for doing time consuming jobs in logic
- Kotest - for unit tests of logic module
- Retrofit & okhttp - for network communication
- Hilt & Dagger - for dependency injection
- Leak Canary - for memory leaks detection
- Android view binding, because Kotlin synthetics got deprecated Info
Good class to get an overall overview is ListFragment.kt
The app shows list of Github repositories for a given user.
After choosing a repository, app shows it's details.
It supports bigger screens
Communication from the app to the logic module:
- via method calls and setting its variables.
logic.loadNextPage()
Communication from the logic module to the app:
- via exposed Flows
val list: SharedFlow<List<Repository>>
Example: ListLogic.kt
Example: ListLogic tests
It uses kotest framework that allows to write unit tests efficiently.
Setting isolationMode = IsolationMode.InstancePerLeaf
allows to run whole separate flow for each leaf of a tests tree.
For example to write tests On download 2nd page
and On error downloading 2nd page
without taking care of preparing previous steps like On started and download 1st page
.
Whole path is executed for every leaf.
Suggested method of running tests (because of nice UI output) is to run from Android Studio Gradle menu logic/Tasks/verification/test
.
Example: ListScreen.kt
Views are built using reusable components and composed in xmls.