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
04-03 15:44:04.233 8911-8947/io.realm.test E/ProgressUpdate: /data/data/io.realm.test/cache/junit-1429296718/custom-admin-user/tests/tests -> downloaded: 0,downloadable: 0,uploaded: 0,uploadable: 0, is_fresh 0 | |
04-03 15:44:04.237 8911-8947/io.realm.test E/ProgressUpdate: /data/data/io.realm.test/cache/junit-1429296718/custom-admin-user/tests/tests -> downloaded: 0,downloadable: 0,uploaded: 0,uploadable: 0, is_fresh 0 | |
04-03 15:44:04.276 8911-8947/io.realm.test E/ProgressUpdate: /data/data/io.realm.test/cache/junit-1429296718/custom-admin-user/tests/tests -> downloaded: 0,downloadable: 0,uploaded: 0,uploadable: 8844, is_fresh 0 | |
04-03 15:44:04.279 8911-8947/io.realm.test E/ProgressUpdate: /data/data/io.realm.test/cache/junit-1429296718/custom-admin-user/tests/tests -> downloaded: 0,downloadable: 0,uploaded: 0,uploadable: 9187, is_fresh 0 | |
04-03 15:44:04.289 8911-8947/io.realm.test E/ProgressUpdate: /data/data/io.realm.test/cache/junit-1429296718/custom-admin-user/tests/tests -> downloaded: 0,downloadable: 0,upload |
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
/* | |
* Copyright 2017 Realm Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
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 |
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
// Global App variable | |
class MyApp: Application() { | |
companion object { | |
private val config = RealmConfiguration(schema = setOf(Person::class)) | |
public val REALM = Realm(config) | |
} | |
} | |
// Using dependency injection | |
val koinModule = module { |
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
// Close Realm to free native resources | |
realm.close() |
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
val jane = realm.writeBlocking { | |
val unmanaged = Person("Jane") | |
copyToRealm(unmanaged) | |
} |
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
CoroutineScope(Dispatchers.Main).launch { | |
// Write automatically happens on a background dispatcher | |
val jane = realm.write { | |
val unmanaged = Person("Jane") | |
// Add unmanaged objects | |
copyToRealm(unmanaged) | |
} | |
// Objects returned from writes are automatically frozen |
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
CoroutineScope(Dispatchers.Main).launch { | |
// Create initial object | |
val jane = realm.write { | |
copyToRealm(Person("Jane")) | |
} | |
realm.write { | |
// Find latest version and update it | |
// Note, this always involves a null-check | |
// as another thread might have deleted the |
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
val jane = getJane() | |
CoroutineScope(Dispatchers.Main).launch { | |
// Updates are observed using Kotlin Flow | |
val flow: Flow<Person> = jane.observe() | |
flow.collect { | |
// Listen to changes to the object | |
println(it.name) | |
} | |
} |
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
val jane = getJane() | |
CoroutineScope(Dispatchers.Main).launch { | |
// Run mapping/transform logic in the background | |
val flow: Flow<String> = jane.observe() | |
.filter { it.name.startsWith("Jane") } | |
.flowOn(Dispatchers.Unconfined) | |
// Before collecting on the UI thread | |
flow.collect { |