RxScene

In package com.nhaarman.acorn.presentation

class com.nhaarman.acorn.presentation.RxScene

An abstract base Scene implementation that provides commonly used functionality, including some helper functions for Rx usage.

Implementers of this class gain access to the view property to get notified of view changes, and a disposables property is provided for easy clearing of Disposables.

Fields

protected disposables:

A disposable container which will be cleared when this Scene receives a call to onStop. Note that the instance will be cleared not disposed, so this instance can be reused multiple times.

This container should only be used in the onStart method. When used in other methods like attach, memory leaks may occur.

protected view:

Publishes a stream of optional V instances that are attached to this Scene.

Constructors

constructor(savedState: SceneState?)

Creates a new RxScene, restoring view state when available.

Parameters:

Methods

open fun onStart()

Called when this Scene is started.

Parameters:
  • No parameters
open fun attach(v: V)

Attaches given V to this Scene.

Parameters:
  • v: V

    The user interface that is being attached.

open fun detach(v: V)

Detaches any views from this scene.

Will always be preceded by a call to attach.

Parameters:
  • v: V
open fun onStop()

Called when this Scene is stopped.

Parameters:
  • No parameters
open fun onDestroy()

Called when this Scene will be destroyed.

After a call to this method no more calls should be made to this Scene.

Parameters:
  • No parameters
protected fun <T> whenStarted(f: ()->):

A utility function to automatically subscribe and dispose of source Observable instance when this Scene starts and stops.

Parameters:
  • f: ()->

    A function that provides the source Observable when this Scene is started. This function can be called multiple times.

protected fun <T : Any> .combineWithLatestView():

A utility function to combine an arbitrary stream of T's with the currently attached V instance.

Parameters:
  • No parameters
protected fun <R> .whenAvailable(f: (V)->):

A utility function to switchMap the stream of attached V instances to streams that V provides.

Parameters:
  • f: (V)->
protected fun <T> .autoConnect(scene: RxScene):

Returns an Observable that automatically connects at most once to the receiving ConnectableObservable when the first Observer subscribes to it. The connection will automatically be disposed of when scene is destroyed.

This can be used to keep an Observable alive for as long as the Scene lives.

Parameters: