This version of the app is called todo-mvp, and provides a foundation for other samples in this project. The sample aims to:
- Provide a basic Model-View-Presenter (MVP) architecture without using any architectural frameworks.
- Act as a reference point for comparing and contrasting the other samples in this project.
Note: This project uses the following naming convention, across all repository branches, to distinguish between View classes and MVP views:
- "Android View" refers to the android.view.View class.
- The view that receives commands from a presenter in MVP, is referred to as "view".
Before exploring this sample, you might find it useful to familiarize yourself with the following topics:
- The project README
- The MVP architecture
The todo-mvp sample uses the following dependencies:
- Common Android support libraries - Packages in the com.android.support.* namespace provide backwards compatibility and other features.
- Android Testing Support Library - A framework used to support UI tests, using both Espresso, and AndroidJUnitRunner.
- Mockito - A mocking framework used to implement unit tests.
- Guava - A set of core libraries for Java by Google, commonly used in Android apps.
All versions of the Android Blueprints app include the same common features in a simple to-do type app. The app consists of four UI screens:
- Tasks - Used to manage a list of tasks.
- TaskDetail - Used to read or delete a task.
- AddEditTask - Used to create or edit tasks.
- Statistics - Displays statistics related to tasks.
In this version of the app, as well as other versions based on it, each screen is implemented using the following classes and interfaces:
- A contract class which defines the connection between the view and the presenter.
- An Activity which creates fragments and presenters.
- A Fragment which implements the view interface.
- A presenter which implements the presenter interface in the corresponding contract.
A presenter typically hosts business logic associated with a particular feature, and the corresponding view handles the Android UI work. The view contains almost no logic; it converts the presenter's commands to UI actions, and listens for user actions, which are then passed to the presenter.
Each version of the app implements the same features using a different approach to showcase and contrast a variety of architectural designs. For example, this version takes the following approaches to solving common implementation questions:
- This sample uses product flavors to replace modules at compile time, providing fake data for both manual and automated testing.
- This version uses callbacks to handle asynchronous tasks.
Notice also in the following illustration that this version of the app uses fragments, and this is for two reasons:
- The use of both activities and fragments allows for a better separation of concerns which compliments this implementation of MVP. In this version of the app, the Activity is the overall controller which creates and connects views and presenters.
- The use of fragments supports tablet layouts or UI screens with multiple views.
This version of the app includes a number of unit tests which cover presenters, repositories, and data sources. The sample also includes UI tests, that rely on fake data, and are faciliated by dependency injection to provide fake modules. For more information on using dependency injection to faciliate testing, see Leveraging product flavors in Android Studio for hermetic testing.
This sample includes classes and interfaces, such as presenters and contracts, that increase the number of lines of code compared to more traditional projects that do not make use of a particular architecture.
The table below summarizes the amount of code used to implement this version of the app. You can use it as a basis for comparison with similar tables provided for each of the other samples in this project.
Language | Number of files | Blank lines | Comment lines | Lines of code |
---|---|---|---|---|
Java | 46 | 1075 | 1451 | 3451 |
XML | 34 | 97 | 337 | 601 |
Total | 80 | 1172 | 1788 | 4052 |