Skip to content

Instantly share code, notes, and snippets.

View afaucogney's full-sized avatar
🎯
Focusing

Faucogney Anthony afaucogney

🎯
Focusing
View GitHub Profile
package au.com.auspost.android
import android.arch.persistence.db.SupportSQLiteDatabase
import android.arch.persistence.room.Room
import android.arch.persistence.room.migration.Migration
import android.content.Context
import android.support.annotation.VisibleForTesting
import io.reactivex.Observable
import timber.log.Timber
import toothpick.ProvidesSingletonInScope
/**
* 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