From 73085b515eee41801d63f89114f896da6112ee44 Mon Sep 17 00:00:00 2001 From: Patrick Lang <72232737+patrickunterwegs@users.noreply.github.com> Date: Sun, 17 Nov 2024 20:26:29 +0100 Subject: [PATCH] Attempt to resolve Possible crash "Reading a state that was created after the snapshot was taken or in a snapshot that has not yet been applied" Closes #1633 --- .../at/techbee/jtx/ui/detail/DetailViewModel.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/at/techbee/jtx/ui/detail/DetailViewModel.kt b/app/src/main/java/at/techbee/jtx/ui/detail/DetailViewModel.kt index 9dea059b2..9fc6e3575 100644 --- a/app/src/main/java/at/techbee/jtx/ui/detail/DetailViewModel.kt +++ b/app/src/main/java/at/techbee/jtx/ui/detail/DetailViewModel.kt @@ -128,20 +128,21 @@ class DetailViewModel(application: Application) : AndroidViewModel(application) viewModelScope.launch { withContext(Dispatchers.Main) { changeState.value = DetailChangeState.LOADING } + mutableCategories.clear() + mutableResources.clear() + mutableAttendees.clear() + mutableComments.clear() + mutableAttachments.clear() + mutableAlarms.clear() + withContext(Dispatchers.IO) { originalEntry = databaseDao.getSync(icalObjectId) mutableICalObject = originalEntry?.property - mutableCategories.clear() mutableCategories.addAll(databaseDao.getCategoriesSync(icalObjectId)) - mutableResources.clear() mutableResources.addAll(databaseDao.getResourcesSync(icalObjectId)) - mutableAttendees.clear() mutableAttendees.addAll(databaseDao.getAttendeesSync(icalObjectId)) - mutableComments.clear() mutableComments.addAll(databaseDao.getCommentsSync(icalObjectId)) - mutableAttachments.clear() mutableAttachments.addAll(databaseDao.getAttachmentsSync(icalObjectId)) - mutableAlarms.clear() mutableAlarms.addAll(databaseDao.getAlarmsSync(icalObjectId)) }