Darryl Pierce
04/17/2025, 2:37 PMDarryl Pierce
04/17/2025, 2:39 PMcoroutineScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
comicBookViewModel.download(server, serverLink)
}
The download() method is:
fun download(server: Server, serverLink: ServerLink) {
viewModelScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
<http://Log.info|Log.info>(TAG, "Downloading ${serverLink.downloadLink} => ${serverLink.filename}")
doAddDownload(serverLink.downloadLink)
downloadFile(
server,
serverLink.downloadLink,
"${libraryDirectory.value}/${serverLink.filename}",
onProgress = { current, total ->
Log.debug(
TAG,
"Downloaded ${current} of ${total} for ${serverLink.downloadLink}"
)
doUpdateDownload(serverLink.downloadLink, current, total)
})
doRemoveDownload(serverLink.downloadLink)
}
}
And the method to update the view model state is:
private fun doUpdateDownload(downloadLink: String, current: Long, total: Long) {
val currentDownloads = _currentDownloads.value
val entry = currentDownloads.first { it.downloadLink == downloadLink }
currentDownloads.remove(entry)
if (total > 0) {
entry.progress = ((current / total).toFloat())
} else {
entry.progress = 0.0f
}
currentDownloads.add(entry)
_currentDownloads.tryEmit(currentDownloads)
}
I'm using com.rickclephas.kmp.observableviewmodel.MutableStateFlow for the state flow since it's a KMP project, and the other uses for it work correctly, but the progress updates never happen. Any ideas or suggestions?Chrimaeon
04/17/2025, 2:43 PMtryEmit
Darryl Pierce
04/17/2025, 2:46 PMChrimaeon
04/17/2025, 2:47 PMDarryl Pierce
04/17/2025, 2:47 PMChrimaeon
04/17/2025, 2:48 PMDarryl Pierce
04/17/2025, 2:50 PMChrimaeon
04/17/2025, 2:51 PMDarryl Pierce
04/17/2025, 2:51 PMChrimaeon
04/17/2025, 2:52 PMCommon
in the upper right corner indicates the platform a class is available onDarryl Pierce
04/17/2025, 2:56 PMDarryl Pierce
04/17/2025, 2:57 PMChrimaeon
04/17/2025, 2:59 PMupdate
lambda instead of tryemit
Chrimaeon
04/17/2025, 2:59 PMDarryl Pierce
04/17/2025, 3:01 PMDarryl Pierce
04/17/2025, 3:02 PMval progress = when (total) {
0L -> 0.0f
else -> (current / total).toFloat()
}
Log.debug(TAG, "Progress was calculated to ${progress} from ${current} and ${total}")
is always producing this log output:
2025-04-17 11:00:00.457 7167-7246 ComicBookViewModel org.comixedproject.variant.android D Progress was calculated to 0.0 from 816453 and 9944836
Darryl Pierce
04/17/2025, 3:03 PMDarryl Pierce
04/17/2025, 3:04 PMChrimaeon
04/17/2025, 3:06 PMDarryl Pierce
04/17/2025, 3:07 PMChrimaeon
04/17/2025, 3:08 PMDarryl Pierce
04/17/2025, 3:26 PM