This is the second part of the article series. In the first part, we developed the concept of MVP and worked out a blueprint for the android application architecture. If you haven’t read the first part then most of the following article will not make much sense. So, go through the first part before proceeding forward.
We will implement the MVP architecture by developing a full-fledged android application based on the blueprint sketched in the first part of this article series.
This project is developed to provide a proper way of structuring an android app. It contains all the code pieces required for most part of the android app.
The project will appear very complex at first but as you will spend time exploring, it will become most obvious to you. This project is built using Dagger2, Rxjava, FastAndroidNetworking and PlaceHolderView.
Take this project as a case study. Study each and every code of it. If there is some bug or you can come up with a better logical implementation then create a pull request. We are writing tests gradually, so feel free to contribute in it and create pull request for them too.
The screens of the developed app are provided below:
This app has a login screen and a main screen. Login screen implements google, facebook and server login. The google and facebook login is implemented through a dummy api. The login is based on access token retrieval and subsequent api calls are protected with this token. The main screen creates flashcards with questions relevant to MVP. This repo contains codes that demonstrate most of the possible application components in terms of skeleton for any app.
Let’s take a look at the project structuring:
The entire app is packaged into five parts:
- data: It contains all the data accessing and manipulating components.
- di: Dependency providing classes using Dagger2.
- ui: View classes along with their corresponding Presenters.
- service: Services for the application.
- utils: Utility classes.
Classes have been designed in such a way that it could be inherited and could maximize the code reuse.
project structure diagram:
Simplest ideas are most complex in their conception.
There are a lot of interesting parts. But if I try explaining all of them at once then it will become too much information at a time. So, I think best approach will be to explain the core philosophies and then the reader can make sense of the code through navigating the project repo. I advise you to take this project study spanned over at least a week. Study the main classes in reverse chronological order.
- Study build.gradle and look for all the dependencies used.
- Explore data package and the implementations of helper classes.
- ui base package creates the base implementations of Activity, Fragment, SubView and Presenter. All other related components should be derived from these classes.
- di package is the dependency providing classes for the application. To understand dependency injection, go through the two-part article published by me, Dagger2 part 1 and Dagger2 part 2
- Resources: Styles, fonts, drawable.
Read the part 3 of this Article series here: It covers Dialogs, ViewPager, RecyclerView and Adapters in MVP.
If your project is very large with many developers working on it simultaneously then read the extension of this MVP architecture with Interactors and Repositories:
- RxJava2: https://github.com/amitshekhariitbhu/RxJava2-Android-Samples
- Dagger2: https://github.com/MindorksOpenSource/android-dagger2-example
- FastAndroidNetworking: https://github.com/amitshekhariitbhu/Fast-Android-Networking
- PlaceHolderView: https://github.com/janishar/PlaceHolderView
- AndroidDebugDatabase: https://github.com/amitshekhariitbhu/Android-Debug-Database
- Calligraphy: https://github.com/chrisjenx/Calligraphy
- GreenDao: https://mindorks.com/blog/powerful-android-orm-greendao-3-tutorial
- ButterKnife: http://jakewharton.github.io/butterknife/
Coder’s Rock 🙂