This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |