GDG Geneva — July event

GDG Geneva is a small GDG, but we try hard 😊 Last Monday we had our July event, and, despite the tremendous heat, spent more than one hour talking about MVP on Android.

I prepared a small Android app to demonstrate how we can create an app that fetches data from a backend and shows them in a list, using two different design approaches:

  • !Good Old GOD Activity
  • MVP

Both versions are identical from a user point of view: same UI, same UX. What’s different is the code quality and maintainability, of course.

GOD Activity

Everything is in the Activity, because… why not!?

It’s easier and quicker to have everything in one place and if I need a Context I can use this.

The Retrofit network call is synchronous and we dodge the NetworkOnMainThread exception using an AsyncTask. The API client is created in the Activity, like every other needed component.

If you are like me, this approach keeps you awake at night or, even worse, gives you nightmares the moment you close your eyes.

MVP

Model-View-Presenter is the new standard de-facto on Android. In this version of the app, I tried to make the view as dumbest as possible, move as much as possible away from it and into a pure-Java codebase. Being pure-Java, we can easily test it without firing any Android device or emulator or using Robolectric.

I used Dagger2, RxJava, ButterKnife also to give an overview about common Android dev tools. Kotlin has been used in the test environment to show how you can start using the new language (read Our Savior) just for your tests and then move to a full Kotlin code base when you feel ready.

Source code

App source code is available here:

https://github.com/hamen/from-god-activity-to-mvp

Slides

Slides are available here:

https://docs.google.com/presentation/d/1bLpctfV1vjXUeQbjMTdPHQa2bdVP99FJnU8yQM_MnNs/edit?usp=sharing