This is a simple android project developed using MVP pattern to achieve the clean architecture.
It is based on the article by Mindorks. Refer their blog to get a clear picture about the implementation.
"MVP is a user interface architectural pattern engineered to facilitate automated unit testing and improve the separation of concerns in presentation logic:
- The model is an interface defining the data to be displayed or otherwise acted upon in the user interface.
- The view is a passive interface that displays data (the model) and routes user commands (events) to the presenter to act upon that data.
- The presenter acts upon the model and the view. It retrieves data from repositories (the model), and formats it for display in the view."
source : wikipedia
In a nutshell : MVP is mainly used to achieve the separation of concerns and to make the code easy to test and reusable.
MVP divides the project structure into thre major components
- Model - Which is responsible for all the data handling operations
- View - Which is responsible for inflating the views and performing UI operations respective to the data received
- Presenter - Which acts like a bridge between Model and View. All the business logics will be written under presenter only
In this section, we will go through the working structure of MVP pattern
- View will layout the UI for the specific page.
- The user interactions will be send over to the Presenter, where the presenter will fetches the data from the model or perform any business logic
- Then the Presenter will instruct the view to update the UI with corrsponding to the data provided.
- Model will fetch the data required for presenter from any of the storages like Server, Database, Preference or File storage
In this scection, we will understand what is a Model, View & Presenter in an android project.
- A View will be of any element with an UI like Activity, Fragment or Custom views
- A presenter is a pure java class which doesn't have any access to Android Apis
- View communicate with presenter through an interface and vice versa
- Model consists of different elements since data can be acquired from any type of source. The main part of model is Data Manager class which is connected to four helper classes namely
- ApiHelper (For api related calls)
- PreferenceHelper (For getting data from Shared Prefernce)
- DatabaseHelper (For getting data from local DB)
- FileHelper (For getting data from local files)
- Likewise View, Presenter will communicate with model through an interface
- Dagger2 - For dependency injection
- Retrofit - For making api calls
- Butter Knife - For view bindings
- Glide - For Image loading
- Espresso - For UI testing
- MockWebServer - For testing HTTP clients
