From e580ced066a78092ddcbfb28e7a8ce7bc4c03aba Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Wed, 14 May 2025 00:25:37 -0500 Subject: [PATCH] Fix handling multiple shared attachments --- .../main/java/com/todoroo/astrid/files/FilesControlSet.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/todoroo/astrid/files/FilesControlSet.kt b/app/src/main/java/com/todoroo/astrid/files/FilesControlSet.kt index e36686347..6ad75e563 100644 --- a/app/src/main/java/com/todoroo/astrid/files/FilesControlSet.kt +++ b/app/src/main/java/com/todoroo/astrid/files/FilesControlSet.kt @@ -14,7 +14,9 @@ import androidx.compose.ui.platform.LocalContext import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.lifecycleScope import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import org.tasks.R import org.tasks.Strings import org.tasks.compose.edit.AttachmentRow @@ -108,16 +110,16 @@ class FilesControlSet : TaskEditControlFragment() { ) } - private fun newAttachment(output: Uri) { + private suspend fun newAttachment(output: Uri) { val attachment = TaskAttachment( uri = output.toString(), name = FileHelper.getFilename(requireContext(), output)!!, ) - lifecycleScope.launch { + withContext(Dispatchers.IO) { taskAttachmentDao.insert(attachment) viewModel.setAttachments( viewModel.viewState.value.attachments + - (taskAttachmentDao.getAttachment(attachment.remoteId) ?: return@launch)) + (taskAttachmentDao.getAttachment(attachment.remoteId) ?: return@withContext)) } }