This project is written in Kotlin and following MVVM Clean Architecture principles, with Room/StateFlow/LiveData/Coroutines/DataBinding.
Simply clone the project, import into Android Studio and run.
It contains 4 modules in total:
- app: Contains the views fragment/activity and the adapters, as well as custom views, view helper classes, extensions and data binding adapters.
- presentation: Contains the ViewModel declaration
- domain: Contains the Repository interface and UseCases
- data: Contains the Repository implementation, the retrofit api calls and room database
Each module contains a set of unit tests
- Coroutines
- Koin
- Jetpack (Navigation, Room, Data Binding, Lifecycle, LiveData, ViewModel)
- Kotlinx Serialization
- Jakewharton retrofit2-kotlinx-serialization-converter
- Retrofit
- Picasso
- JUnit
- Mockk
this BaseFragment takes <BINDING : ViewDataBinding, VIEW_MODEL : BaseViewModel> and injects the ViewModel automatically and binds it with the view, this way the Fragments won't need to worry about injecting ViewModels.
A generic class that holds a value with its loading status.
This file contains one important functions:
resultFlow() will execute the given selectQuery and return the cache data, networkCall to call the api, and save into room using insertResultQuery all while mapping between appropriate models, returning a Flow to observe in the view model.
getRemoteResult will execute the call function, generally coming from a retrofit service, and map it using the transform function. This method automatically checks on network state and handles errors, and returns the right SourceResultHolder wrapper.
getRoomResult will execute the call function, generally a database call, and map it using the transform function.
All of these files can be put together with Retrofit services and have a seamless Repository implementation for use cases.
https://www.dropbox.com/s/ip4rkw02j7z2cix/marleyspoons.webm?dl=0