This Project is build using MVVM architecture and is categorized into following layers
- UI layer
- Business layer
- Repository layer
UI Layer
All Activities,fragments,adapters or any classes that have an android UI dependency fall under this layer. UI layer is responsible for rendering UI on to the screen. UI layer will listen to data changes from corresponding ViewModel and update the UI.
In our example LandingActivity ParentActivity SearchFragment EventDetailFragment ResultsAdapter comes under UI layer.
Business Layer
Handles all the businesses logic for the application. Businesses layer will request the repository layer for any required data. These view models will not have any android UI dependency hence any Unit Test cases written on these classes can run without an android device/emulator. It acts as link between repository layer and UI layer. It is responsible for getting data from repository layer and providing data required for UI.
In our example ResultsViewModel comes under Businesses Layer.
Repository Layer
Responsible for all data related queries. Repository layer will fetch data from either the Room Database or from the API call.
Advantage of this layered architecture is that each module can be tested independently using the Mocking frameworks.
Overview of external Libraries used.
- Espresso for UI testing
- Mockito for mocking interfaces during testing.
- Hamcrest for assertions during testing.
- Room database to save favorite events.
- Dagger2 for dependency injection.
- okhttp and Retorfit for networking.
- Glide to display images.
- Stetho for debugging data in databases and shared preferences.
- MockWebServer from Square to mock responses from web server.
This project utilizes following Android Architecture Components
Live Data helps updating observers about data changes. LiveData is also used inside RoomDatabase to update UI when data inside database changes.
ViewModel helps storing data in classes which aren’t destroyed when Activity destroyed.
Room helps us focusing on writing functionality without worrying about the boiler plate code to create databases and tables. It is a Object mapping library which provides compile time checks to see if SQL statements to return LiveData observables.
DataBinding helps us injecting data directly to XML files.