Skip to content

Instantly share code, notes, and snippets.

View afaucogney's full-sized avatar
🎯
Focusing

Faucogney Anthony afaucogney

🎯
Focusing
View GitHub Profile
@mayankmkh
mayankmkh / PrettyPrint.kt
Last active April 11, 2024 11:52
Pretty Print Kotlin Data Class
fun Any.prettyPrint(): String {
var indentLevel = 0
val indentWidth = 4
fun padding() = "".padStart(indentLevel * indentWidth)
val toString = toString()
val stringBuilder = StringBuilder(toString.length)
/**
* 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