Essential Guide For Designing Your Android App Architecture: MVP: Part 2

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.

Here is the link to the first part:

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.

The GitHub repo of the MVP project : Link

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 structure:

The entire app is packaged into five parts:

  1. data: It contains all the data accessing and manipulating components.
  2. di: Dependency providing classes using Dagger2.
  3. ui: View classes along with their corresponding Presenters.
  4. service: Services for the application.
  5. 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.

  1. Study build.gradle and look for all the dependencies used.
  2. Explore data package and the implementations of helper classes.
  3. ui base package creates the base implementations of Activity, Fragment, SubView and Presenter. All other related components should be derived from these classes.
  4. 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
  5. Resources: Styles, fonts, drawable.

Read the part 3 of this Article series here: It covers Dialogs, ViewPager, RecyclerView and Adapters in MVP.

https://blog.mindorks.com/essential-guide-for-designing-your-android-app-architecture-mvp-part-3-dialog-viewpager-and-7bdfab86aabb

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:

https://blog.mindorks.com/android-mvp-architecture-extension-with-interactors-and-repositories-bd4b51972339

Reference resources:

Let’s become friends on Twitter, Linkedin, Github, and Facebook.

Coder’s Rock