Skip to content

A dummy Android app in Kotlin that tries to demonstrate an example implementation of Model-VIew-Intent design pattern

Notifications You must be signed in to change notification settings

mrmitew/BodyLog-Kotlin

Repository files navigation

Bodylog

NOTE: For the Java version of this app, navigate to: https://github.com/mrmitew/BodyLog

The main goal of this (WIP) project is to demonstrate an implementation of the Model-View-Intent (MVI) design pattern, which aims at having a unidirectional data flow where application state is driven by the business logic.

The project follows the "clean" approach for architecting apps and is composed of several modules (both Android and pure java), namely:

  • framework (UI)
  • data (Repository)
  • adapter (UI presentation)
  • domain (Business logic)

Presenter(s) in this implementation have no lifecycle. They implement the Disposable interface and expose couple of additional methods, including bindIntents(), unbindIntents() and optionally attachView(View) and detachView().

Internally, Presenters create PublishRelay, which subscribes to the stream of View intents and serve as a gateway to the business logic of the app. Communication between Presenter and business logic is established by using *Interactor*s which can also be shared between other *Presenter*s. When there is a screen orientation change, View detaches from Presenter by unsubscribing the PublishRelay from the View. When the View attaches back to the Presenter, the PublishRelay subscribes back to the View's stream of intents.

In addition, presenters create BehaviourRelay(s) that work as a gateway from business logic to View. While a View is detached from a Presenter, say we navigate forward from Activity A to Activity B, the presenter of Activity A will be still alive and can receive updates from the business logic. When we navigate back and View reataches to Presenter, the BehaviourRelay will replay the cached model update and View will update accordingly.

In order to preserve Presenter(s) in memory during orientation change, they are injected into a PresenterHolder that extends from Android's ViewModel (https://developer.android.com/topic/libraries/architecture/viewmodel.html). Throughout the lifecycle of an activity/fragment, View(s) get detached and reatached to Presenter(s), so no memory leaks would occur. When an Activity or Fragment gets finally destroyed (not due to orientation change), Presenter is also destroyed.

Libraries used in this project

UI libraries

  • AppCompat

Reactive libraries

  • RxJava2 + RxKotlin
  • RxBinding + RxBinding-Kotlin
  • RxAndroid
  • RxRelay2
  • Lifecycle (for Android's ViewModel)

Others

  • Kotlin
  • Dagger (dependency injection)

Debugging & Inspecting

  • LeakCanary (finding memory leaks)

Testing

  • JUnit
  • Mockito

About

A dummy Android app in Kotlin that tries to demonstrate an example implementation of Model-VIew-Intent design pattern

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published