MVP with Architecture Components?

Google provides two basic sample apps and a advanced MVVM-based app on their Github repository. It is a really good resource to learn about new arch components.

However, as we discussed above, any app can take advantages from LifeCycle and Room. So, I would like to bring it into existing Android MVP projects.

To demonstrate it, I have created a sample app which loads newest Android questions from StackOverflow.

As normally, this sample uses:

Retrofit + OkHttp to consume StackOverflow APIs.

+ to consume StackOverflow APIs. UI components: RecyclerView + CardView + ConstraintLayout .

+ + . Dagger2 for dependency injection.

for dependency injection. RxJava to handle data stream.

With new Architecture Components, two main changes are added:

Lifecycle-aware Presenter created with support from LifeCycle .

created with support from . For local data persistence, it is relatively easy to handle by using Room .

For data layer, this project followed repository pattern. If your project grows as a big, you can consider to separate this layer as a independent module instead of a package to decouple it with other parts and easily to extend and maintain.

This project can be used as a boiler plate app for your next MVP apps which adapts with Android new Architecture Components.

All of codes can be found on Github repository.

What’s next?

It is just a starting point for us to see the benefits of new arch components, especially for MVP projects and how popular frameworks cooperates together.

So, I am certainly going to update it with better approaches. Besides, any PR(pull request) is highly appreciated. Let’s learn together in our long journey.