Skip to content

Instantly share code, notes, and snippets.

View suryachintu's full-sized avatar

Surya Teja suryachintu

  • Fidelity International
  • New Delhi
View GitHub Profile
/**
* Class connecting the Realm lifecycle to that of LiveData objects.
* Realm will remain open for as long as any LiveData objects are being observed.
*/
abstract class LiveRealmData<T: RealmModel>(val config: RealmConfiguration) : LiveData<RealmResults<T>>() {
private val listener = RealmChangeListener<RealmResults<T>> { results -> value = results }
private lateinit var realm: Realm
private var results: RealmResults<T>? = null