Greenfield Template (RxJava 2 version)
This is a template that I use for new projects. It already has some basic stuff setup, such as:
- Retrofit + OKHttp
- MVP architecture
- Kotlin extensions
- JUnit tests (with Mockito)
- UI tests with Espresso (run on mockDebug variant!)
- Mock and connected variants (for offline work and tests)
- Permission dispatcher library
- CI Integration (Microsoft's AppCenter) that runs the tests on commit
The app itself connects to Flickr and displays a list of images. You can search for particular tags or you can sort the images.
- maybe have an MVI version?
- try out mosby for MVP boilerplate?
- maybe do some cool stuff with Groupie?
- Koin instead of Dagger?
- Move more towards Clean Architecture.
Note: I wrote a blog post about an old version of this architecture. It is now obsolete, but the article might be interesting for historic reasons. Remember EventBus? :)
Here is the diagram of the architecture proposed here:
The flow of events and data:
- The Activity reacts to the user input by informing the Presenter that data is required.
- The Presenter fires off the appropriate request in the service layer (and instructs the Activity to display a busy indicator).
- The Service then issues the correct REST call to the Retrofit layer.
- The Retrofit layer exchanges HTTP requests and responses with the Server and returns an
- The Service possibly inspects the
Observable, schedules it on the correct thread (in order to keep the Presenter free of Android Schedulers and thus pure JUnit testable) and returns it back to the Presenter.
- The Presenter receives the
Observable, retrieves the data or error and issues the correct commands to the Activity to update the UI (and dismiss the busy indicator).
- The Activity presents the user with the data or error message.