Android Clean Architecture MVP RESTful client template app
This projects aims to be:
Specification summary:
Here is its counterpart server api from where this app consumes the data -> rails-api-base
Install your favourite IDE or just the Android sdk
(buildTools 23.0.2 and compileSdk 23,
or define your own versions in the dependencies.gradle
).
I use
Android Studio.
Clone the repository and get inside it:
git clone git://github.com/jordifierro/android-base.git --origin android-base YourProjectName
cd YourProjectName
./bin/remove_notes
./bin/rename_project YourProjectName your.package.name
./gradlew clean build cAT
./bin/reset_git https://github.com/yourusername/YourProjectName.git
That's it, you can now start developing your own app!
Note: To run the app (you can run only the tests now)
remember to setup an api server
(rails-api-base
is already developed to serve this app,
but you can also make your own)
and configure the RestApi
to connect to it
(simply modify
RestApi.java
params).
The application itself is almost empty, it only aims to provide some basic modules, implement the structures with some patterns and give sample code. Here are the specifications:
The main goal of this application is to avoid writing app basic boilerplate code, so the following functionalities are already implemented:
This can be used from now, and it also provides a structured way to add more code.
To provide more sample code, it has been developed code to manage notes
(like handwritten paper notes representation),
composed by a title
and a content
.
Thus, the app has notes index, detail, create and edit screens.
Its unique purpose is to be a sample code,
so it will be deleted when you run ./bin/remove_notes
script.
The code has been structured following the Clean Architecture approach and the model-view-presenter (MVP) pattern. Check this and this posts, and also this project, for more information about it.
Dependency Inversion Principle is used on the app basically to make testing easier and make the components decoupled and reusable. It also reduces boilerplate code and helps with the management of the instance scopes. The library used to achieve that is Dagger 2. Butterknife is used for view injection.
Clean architecture makes you create different layers and, in order to avoid a callback hell, reactive programming paradigm is applied using ReactiveX library.
As a client app, its main goal is to let the user interact with data from a server api. The project shows how to deal with that easily. Retrofit library is used to implement the api call methods. Authentication, api version and internationalization are included to the requests.
One of the most interesting things of this project is that it has full unit testing coverage, from data modules to android views, including all intermediate layers. That is the result of the usage of clean architecture, dependency inversion and good testing practices. One example of that is the view testing, where the view presenter is mocked by mockito and injected by testing dagger component, provided by a custom junit runner.
Here you can find tutorials that explain some of this tests:
Another patterns and good practices are used in the project such as implement activities and fragments common behavior with inheritance, use fragments and define the navigation in the activities to make screen remodeling painless, use interfaces to decouple components... Android specific good practices like string internationalization, usage of style sheet and other little methodologies are followed too. Here one of the used resources -> android best practices.
Travis-CI has been added as a continous integration system to run all the test on each push (both java and android tests).
To run the tests locally, simply connect a device or run the emulator and execute:
./gradlew clean build cAT
That will run both java and Android tests.
There are some scripts under /bin
folder to make really easy start a new
project from scratch using this template.
Just follow the 'Quick start' section placed above.
All shell scripts are verified by ShellCheck tool.
Here is its counterpart server api from where this app consumes the data -> rails-api-base.
All suggestions and contributions are more than welcome!
./gradlew clean build cAT
Unfortunately, there are no contributors yet.