A Simple Android Apps with MVP, Dagger, RxJava, and Retrofit

Nur Rohman
AndroidPub
Published in
2 min readJun 28, 2016
Video Demo

A moment ago, I was learn how to develop an Android Apps with the clean architecture. So, what have I learned? I was learn how to implements MVP, Dagger, RxJava, and Retrofit on a sample project. I have made an Android Apps that’s call an API from a mock server and retrieve text and image into a RecycleView. Now I want to share step by step how to develop this apps.

Before we practice, we should understand what is MVP, Dagger, RxJava, and Retrofit. Below is a brief description of MVP, Dagger, RxJava, and Retrofit :

MVP

MVP (Model View Presenter) is a pattern thats allows separate the presentation layer from the logic, so that everything about how the interface works is separated from how we represent it on screen. Ideally the MVP pattern would achieve that same logic might have completely different and interchangeable views.

Dagger

Dagger is a dependencies injector. You can see more details about Dagger in this site.

RxJava

RxJava is a Java VM implementation of Reactive Extensions: a library for composing asynchronous and event-based programs by using observable sequences.

Retrofit

Retrofit is a REST Client for Android and Java. It makes it relatively easy to retrieve and upload JSON. Retrofit uses the OkHttp library for HTTP requests.

Ok, lets type your code!

First, create a new project and open your build.gradle then modify it as shown below :

Then, create two layout :

Create some class and organize your project as follows :

This class contains a plain old Java object (POJO) :

Then, create a network service which will be used to call API from a mock server :

Create a class that will execute our subscriber :

Create network module that contains Retrofit builder and provides NetworkService class and Service class:

Create an interface which will connecting between @Modules and @Inject :

Add Dagger builder on BaseApp class which will be extends on your activity :

Up here we’ve create some class that will be reusable when we create any activities. Next, implement it on our activity. Create a presenter, view and adapter :

Last, implement presenter, view, and adapter on our Activity :

Well done, we have completed this tutorial. I am so sorry, because I can’t explain this tutorial clearly. If you see something wrong on this tutorial or you have any question, please feel free to comment. There’s also you can download the full source code on my GitHub :

--

--