Kotlin Boilerplates — Android Architecture Components (with Rx, Dagger & Realm)

Ahmed Rizwan
AndroidPub
Published in
3 min readOct 18, 2017

--

Some simple boilerplates for the Android Architecture Components, for an easy start.

The Boilerplate App

Just a single screen app. Nothing fancy. It simply loads Github Repositories given a username.

what it looks like!

There are 4 different ones depending on your architectural needs — all doing the same thing— & all relying on the new Android Architecture Components.

Basic

BasicRx (Rx working with Retrofit & Room… Because… Observables!)

Dagger (Basic version but with Dagger 2)

Realm (Uses Realm instead of Room)

The projects are based on Google’s Github Browser Sample but are completely written in Kotlin!

There are a lot of samples out there for Android Architecture Components, but finding one for let’s say Realm or Rx can be tricky, as the complexities differ. Some are too complex to be considered boilerplates and some are too simple. That’s why I’ve created these. I’m using only the essential classes needed for (an almost) complete yet a simple App. The app has both state-recovery implemented (thanks to ViewModels) and UI elements are network call status-aware.

Structure of the project

  • There’s only one model → Repo
Realm model — will be same for Room
  • AppDb → Contains the Room or Realm Database + Dao for Repo
  • Network package contains helper classes that are used for implementing this flow
Guide
  • ViewModel
  • Repository

All you have to do is clone, change a few things and that’s it.

Ok… So here are the actual steps…

  • Clone the project
  • Open any of the boilerplates using Android Studio 3.0 RC1 or any later version
  • In order to customize the boilerplate, click on TODO tab and you’ll see some pending ones there, go through them one by one making the project your own

Give these boilerplates a try! Or maybe simply play around with the code and see how they differ for each variation!

Happy coding!

--

--

Ahmed Rizwan
AndroidPub

Web | Android | Senior Software Engineer @QuixelTools