Kotlin demo project that uses some Android Architecture Components (ViewModel and LiveData) with Dagger 2 and Coroutines
Clone or download
Latest commit 53747df May 27, 2018

README.md

Android Architecture Components Demo

This is a Kotlin project that uses some Android Architecture Components (ViewModel and LiveData) with Dagger 2 and RxJava.

This project is a fork of official GithubBrowserSample, I converted it to kotlin and modified some architectural aspects to test ViewModel and LiveData features.

Main concepts

  • each ViewModel manages an immutable ViewState (implemented using a Kotlin data object)
  • a ViewModel can invoke actions on the ui (for example a SnackBar visualization or a navigation to another activity) using a UiActionsLiveData. ViewModels don't maintain a reference to the Activity, using the UiActionsLiveData it just schedules action on the ui
  • multi module project, thanks to Dagger Android the ui is splitted in multiple modules
  • Fragment args are managed using a companion object base class
  • JVM tests are written using Mockito and AssertK
  • Espresso tests are written using DaggerMock and Mockito
  • ViewModels are instantiated using a custom factory defined in Dagger application scope and replaced with a stub in Espresso tests
  • asynchronous tasks are managed using Coroutines (the rxjava branch contains the same example with RxJava singles instead of coroutines)