Implementing a sample Android Application using MVP , RxJava , Dagger 2 , Retrofit2 , Test , and all the brand new modern methods and libraries I found some unanswered questions about using on which encouraged my strong interest to write a series of articles, providing a sample project (i.e a practical experiences of my own…) MVP StackOverflow Last year I get familiar with a tuxedo development, and looked at samples and tutorials. I spent a long time processing and connecting different parts of this unknown big puzzle. The most useful website which I can mention was which is always full of new video tutorials. MVP, caster.io Android Explaining about itself might look odd! cause there are many articles explaining how it works and how to break layers and so on, but there are few samples with enough comments which help newer in this methodology. MVP How change begins… It all begins with (object-oriented design principles), thanks to dear . SOLID Robert C. Martin according to the article on , it stands for: SOLID Wikipedia (SRP): Single responsibility principle - S (OCP): Open/closed principle - O (LSP): Liskov substitution principle - L (ISP): Interface segregation principle - I (DIP): Dependency inversion principle - D somehow try to follow all the five principles. I would try my best to pinpoint one by one in my sample project to make it more transparent. MVP according to this perfect , it stands for: MVP article - The is the data that will be displayed in the view (user interface). Model - The is an interface that displays data (the model) and routes user commands (events) to the Presenter to act upon that data. The view usually has a reference to its Presenter. View - The is the “middle-man” (played by the controller in MVC) and has references to both, view and model. Presenter Model?!!! is misleading!!! Please note that the word “Model” It should rather be . business logic that retrieves or manipulates a Model For instance: If you have a database storing in a database table and your View wants to display a list of users, then the Presenter would have a reference to your database business logic (like a DAO) from where the Presenter will query a list of Users. User Would you explain a little more about MVP? Noooooo!! just and you will find all theories about this new method (or at least take a look at this .) google article What’s this sample project about? This application is a Marvel’s characters searching app which is a simple Android client for the . This application was created by me, as a part of the technical assessment by the technical team. Marvel.com smava GmbH Marvel Android Application screenshot The app must search character, view information and cache last searches. This project implemented using and contains modern Android development concepts and libraries which can really change your professional life! MVP I will try my best to explain everything in different parts of this continues article namely: Dagger, Retrofit, RxJava, and Tests. The project also had Continues Integration(CI) using & and code coverage reports using and also using new Firebase service which you can study by yourself and it is off topic for this article somehow. Circleci.com Travis-ci.org Codecov.io google You can get more familiar with the project by reading and files before getting start. README Task Okay, Show me what you got: _marvel - Marvel Characters Android Application Assigned by smava GmbH_github.com mohsenoid/marvel Let’s take a look at the project’s structure. I personally enjoy working on a clean code, so I really enjoy breaking a project into some meaningful parts that help me and the whole team with keeping more clear with tasks. Modules: Project consist of two main and a java console sample modules: : Android Application module app (marvel-app) : Core Library module core-lib (marvel-core) : a java console sample module console (marvel-console) The module contains the Android layer of , while the other layers ( & ) are all placed in the which is pure java and after compile it would be a jar library. app View MVP Model Presentation core What’s the use of breaking code into modules?! First of all, separating the Android Application module reminds you that you should not pass or any Android related objects to or Context Presenter Model! …so please stop doing it!!! Secondly, you can make sure that the part is that much complete that you can use it with even another (namely: , Web Applet or as a prediction even someday in near future an iOS app using java!!) core UI Java Console sample Finally, I and our team really enjoy developing Applications like this! and whole team members benefit from having apart, and even we put the in a git submodule and use it in different projects with the same and different . core core core UI The result of java console sample module which works the same as Android Application with the core A little module’s name cleanup: to make modules look more convenient and nice you can edit file like this: settings.gradle which gives you this clean look: and also cause a relevant name for output APK file. How to avoid version conflicts and redundant in different modules? using a Gradle feature could come handy for a clean file and avoiding version conflicts and redundant in your project’s modules. build.gradle First of all, place all your project’s dependencies inside a Gradle file like : libraries.gradle then add it to your project file (take care of the last line): main build.gradle and finally, use it like a charm in your module file (take care of dependencies part): app build.gradle and your module file: core build.gradle What’s going on inside the core module? core module’s files structure holds all base interfaces which contain general methods for all , and . base package : Interactors Presenters, Views holding the main feature of the application which is searching and caching Marvel characters info. character package : Caching characters data is done using in this sample which I will not explain too much about it, because it is off topic, but you can take your time looking all codes! database package : OrmLite contain codes to connect to network API using retrofit2 and RxJava library. domain package : full of useful classes which are required for the project, namely: which holds all core const variables, which is being used for Marvel’s API calls hash parameter and which is a Scheduler interface that helps with and multi-threading (I will explain more in this article’s relevant parts). util package : Constants HashGenerator SchedulerProvider RxJava RxAndroid “You wouldn’t wire a lamp directly to your house”, — Novoda Referencing to of , reference !, all links between two modules ( & ) are implemented using interfaces and wired up with dagger. Dependency inversion principle SOLID “one should Depend upon Abstractions and Do not depend upon concretions” or to this fantastic article by Novoda “You wouldn’t wire a lamp directly to your house” app core , and what’s going on inside app module? app module’s files structure holds 3 activities that are the back bone of the Android Application UI. activity package : holds 2 base abstract classes of Activity and Fragment which contain general methods for injection and could be used for other general methods. base package : is holding the main feature of the application which has been implemented using two & fragments. character package : Search Cache contains Android-side database codes using which is off topic! database package : OrmLite full of useful Android-side classes which are required for the project, namely: which extends ’s class and contains Application const variables, which implement ’s and provides Schedulers, which helps with new Android DataBinding plugin for loading images using library and which helps with RecyclerView grid item spacing. (It was a brief information which I will explain more in this article’s relevant parts). util package : AppConstants core Constants AppSchedulerProvider core SchedulerProvider RxAndroid CustomBindingAdapter Picasso GridSpacingItemDecoration That’s it for now… Please clone the and get more familiar with it because in next part I will explain more about dagger and how it helps with wiring up modules and layer’s different objects. project repo from GitHub I look forward to your comments and helping for more improvements with this article. Share this article if you think it is useful, and follow me for more articles . Mohsen Mirhoseini To be continued… _Implementing a sample Android Application using MVP, RxJava, Dagger 2, Retrofit2, Test, and all the brand new modern…_hackernoon.com Yet another MVP article — Part 2: How Dagger helps with the project