Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Matan Abravanel mcmatan

🎯
Focusing
  • Melio
  • Tel Aviv
View GitHub Profile
View kt
class RealmLock {
 private var _uiRealm: Realm? = null
fun getRealm(runningFromTransaction: Boolean = false): Realm {
 return if (MainThread.isMainThread()) {
 if (_uiRealm == null) {
 _uiRealm = Realm.getDefaultInstance()
 }
 _uiRealm!!
 } else {
 if (!runningFromTransaction) {
View kt
class RealmLock {
private var _uiRealm: Realm? = null
fun getRealm(runningFromTransaction: Boolean = false): Realm {
return if (MainThread.isMainThread()) {
if (_uiRealm == null) {
_uiRealm = Realm.getDefaultInstance()
}
_uiRealm!!
} else {
View realmLock.kt
class RealmLock {
private var _uiRealm: Realm? = null
fun getRealm(runningFromTransaction: Boolean = false): Realm {
return if (MainThread.isMainThread()) {
if (_uiRealm == null) {
_uiRealm = Realm.getDefaultInstance()
}
_uiRealm!!
} else {
View dataBaseUsingLock.kt
class DataBase @Inject constructor() {
private val realmLock = RealmLock()
//Home feed items
private fun getFeedItem(id: String): HomeFeedItem? {
return realmActions.getRealm()
.where<HomeFeedItem>().equalTo("_id", id).findFirst()
}
override fun deleteHomeFeedItem(id: String) {
View dataBaseUsingLock.kt
class DataBase @Inject constructor() {
private val realmLock = RealmLock()
//Backround thread transaction
override fun saveLanguage(jsonArray: JSONArray) {
this.realmLock.transaction {
it.createAllFromJson(Language::class.java, jsonArray)
}
}