diff --git a/app/src/main/java/com/vitorpamplona/amethyst/model/Account.kt b/app/src/main/java/com/vitorpamplona/amethyst/model/Account.kt index fe369239e..a235212f3 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/model/Account.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/model/Account.kt @@ -22,8 +22,10 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Job +import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import nostr.postr.Contact import nostr.postr.Persona import nostr.postr.Utils @@ -424,9 +426,14 @@ class Account( handlerWaiting.set(true) val scope = CoroutineScope(Job() + Dispatchers.Default) scope.launch { - delay(100) - live.refresh() - handlerWaiting.set(false) + try { + delay(100) + live.refresh() + } finally { + withContext(NonCancellable) { + handlerWaiting.set(false) + } + } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/model/User.kt b/app/src/main/java/com/vitorpamplona/amethyst/model/User.kt index 7b98739c0..33a8656cb 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/model/User.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/model/User.kt @@ -298,9 +298,14 @@ class UserLiveData(val user: User): LiveData(UserState(user)) { handlerWaiting.set(true) val scope = CoroutineScope(Job() + Dispatchers.Main) scope.launch { - delay(100) - refresh() - handlerWaiting.set(false) + try { + delay(100) + refresh() + } finally { + withContext(NonCancellable) { + handlerWaiting.set(false) + } + } } }