The small download queue screen stores a list of files and lets you start their sequential preparation before sending. After one of the PRs, the screen began behaving unstably: sometimes item status updates in jumps, and part of the data can be lost if the user quickly adds a new file while processing is running.
UploadViewModel.addFile(name) must add a new item to the end of the queue.UploadViewModel.startProcessing() must:
processing;StateFlow state updates only from the main thread.UploadUiState.items must always contain the current file list.UploadViewModel in a test or local run.viewModel.addFile("report.pdf")
viewModel.startProcessing()
viewModel.addFile("photo.jpg")
startProcessing() to finish.state.value.items and the item statuses.report.pdf gets the processing status.photo.jpg, added after launch, remains in the list with the queued status.StateFlow updates are not performed from a background dispatcher.org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4androidx.lifecycle:lifecycle-runtime-ktx:2.8.4ViewModel without Compose and without RoomviewModelScope uses the main thread, and heavy file preparation must run on Dispatchers.DefaultUse line comments to explain the problem, its impact, the fix and how to test it.