Moves creation of the LiveData set to a Synchronized block to avoid double creations without destruction.
This commit is contained in:
@@ -634,17 +634,30 @@ open class Note(val idHex: String) {
|
|||||||
|
|
||||||
var liveSet: NoteLiveSet? = null
|
var liveSet: NoteLiveSet? = null
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
fun createOrDestroyLiveSync(create: Boolean) {
|
||||||
|
if (create) {
|
||||||
|
if (liveSet == null) {
|
||||||
|
liveSet = NoteLiveSet(this)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (liveSet != null && liveSet?.isInUse() == false) {
|
||||||
|
liveSet?.destroy()
|
||||||
|
liveSet = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun live(): NoteLiveSet {
|
fun live(): NoteLiveSet {
|
||||||
if (liveSet == null) {
|
if (liveSet == null) {
|
||||||
liveSet = NoteLiveSet(this)
|
createOrDestroyLiveSync(true)
|
||||||
}
|
}
|
||||||
return liveSet!!
|
return liveSet!!
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearLive() {
|
fun clearLive() {
|
||||||
if (liveSet != null && liveSet?.isInUse() == false) {
|
if (liveSet != null && liveSet?.isInUse() == false) {
|
||||||
liveSet?.destroy()
|
createOrDestroyLiveSync(false)
|
||||||
liveSet = null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -359,15 +359,28 @@ class User(val pubkeyHex: String) {
|
|||||||
|
|
||||||
fun live(): UserLiveSet {
|
fun live(): UserLiveSet {
|
||||||
if (liveSet == null) {
|
if (liveSet == null) {
|
||||||
liveSet = UserLiveSet(this)
|
createOrDestroyLiveSync(true)
|
||||||
}
|
}
|
||||||
return liveSet!!
|
return liveSet!!
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearLive() {
|
fun clearLive() {
|
||||||
if (liveSet != null && liveSet?.isInUse() == false) {
|
if (liveSet != null && liveSet?.isInUse() == false) {
|
||||||
liveSet?.destroy()
|
createOrDestroyLiveSync(false)
|
||||||
liveSet = null
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
fun createOrDestroyLiveSync(create: Boolean) {
|
||||||
|
if (create) {
|
||||||
|
if (liveSet == null) {
|
||||||
|
liveSet = UserLiveSet(this)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (liveSet != null && liveSet?.isInUse() == false) {
|
||||||
|
liveSet?.destroy()
|
||||||
|
liveSet = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user