Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Matan Abravanel mcmatan

🎯
Focusing
  • Platterz
  • Tel Aviv
Block or report user

Report or block mcmatan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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)
}
}
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 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 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 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) {
You can’t perform that action at this time.