This sample code that implement MVVM architecture using Android architecture component intensively and some RxJava
I create this repo for a few reasons:
- Help others to understand architecture component in sample way
- Understand paging library with RxJava
- To use as starting point for future projects
- Get feedback from other developers to improve my code
- Android Support Libraries
- Paging
- LiveData
- ViewModel
- RxJava2
- RxAndroid
- Dagger
- Glide
- Retrofit
- OkHttp
- AutoValue
- AutoValueGson
- Timber
- JDK 1.8
- Android SDK
- Latest Android SDK Tools and build tools.
The sample app when run will show you a simple list of Github users
So the app using Paging library from architecture component at it's core to handle loading and displaying the users list. like this image from official docs
At this sample the data source get it's data from Retrofit Service
and the data source handle loading the new data from the API
The Repository is responsible for mange he connection between view model and the data source so the view model doesn't know any thing about the data source it's only consume data from the repository whatever that data source is. also create the PagedList to bass it to the PagedListAdapter to consume and display it. The Activity is only consume the data so it's pretty lightweight and change can handled easily configuration
Databinding is used to bind the data to views to avoid boilerplate code and add more layer of abstraction
RxJava2 is used to get the data from API and do some mapping from Raw data to safe Databinding and give the final result to the data source. Your case maybe more complex or simpler so i prefer using RxJava because it provide powerful thread and error handing and go with you from simplest solution to complex one
Dagger is used for dependency injection of course to make the code more testable and robust
This architecture is similar to what google used in Guide to App Architecture
But enhanced with paging , RxJava2 and Databinding
contribution to improve this architecture is open just make a PR :D
- Enable caching
- Add unit test
- Add instrumentation test
A special thanks to the authors involved with these two repositories, they were a great resource during our learning!