View kt
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 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
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 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
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 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
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 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
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 DataBase @Inject constructor() { | |
private val realmLock = RealmLock() | |
//Backround thread transaction | |
override fun saveLanguage(jsonArray: JSONArray) { | |
this.realmLock.transaction { | |
it.createAllFromJson(Language::class.java, jsonArray) | |
} | |
} |