This is a project using the latest architecture components and the Paging Library to retrieve some data from this public api.
It's based in a [Activity - Fragment] architecture, also on a RecyclerView and Adapter view based on the data that has to be shown. The Recipes Adapter implements PagedListAdapter to be able to handle the pagination.
Recipe ViewModel handling the Repo and the DataSource to be able to obtain the data paginated. Favourites ViewModel handles only the repo, because the data is not being obtained in pagination, only from Persistence(Room)
The model is the one who is managing the repo and where the data is coming from. In the case of the Recipe search flow, the data is coming from the Network in a pagination mode. The RecipeDataSource is the heart of the Pagination. The one listening for query changes and making query request to the repo api. Also listening for the pagination when scrolling the RecyclerView to get more data and managing the NetwrokState for UI purposes (RUNNING,SUCCESS,FAILED).
The repo has the ApiService and the Room Service.
- We get the search data from the ApiService.
- We save data to the Room Service.
- We delete the data to the Room Service.
- We get the saved data from the Room Service.
We use Koin for the dependency injection, it's a very simple library for DI for Kotlin. Very easy to understand and to use. We have 4 major modules:
- networkModule > Retrofit, OkHttpClient, Gson...
- repoModule > Provides the ApiService and the Room Service to the RepoModule.
- roomModule > Provides the instance of the DataBase and the Dao Interface.
- viewModelModule > Provides the Repository instance to both viewmodels.
- For Repo Unit testing I have been using MockWebServer to mock the response from the API.
- The DAO is tested as well.
- Kotlin ❤️
- Koin (DI)
- MVVM (Architecture)
- Paging Library (Paging)
- Room (Persistence)
- Retrofit (Network)
- Coroutines
- Instrumented Test
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.