Download
Fetching issues onto the device so they can be read offline, and following what the fetching is doing.
Obtained from CGS.download. An issue is addressed by its id and handed back as an Item that both reports its state and controls it:
val item = CGS.download().issue(issueId)
item.start()
item.state.collect { state ->
when (state) {
is Download.Item.State.Downloaded -> showReadyToRead()
is Download.Item.State.Failed -> offerRetry()
else -> Unit
}
}Item.progress is a second flow, from 0.0 to 1.0: collect it separately for a progress bar, as it moves while Item.state stays on Downloading. Progress is persisted: a download cut off by a lost connection stops on Failed, one interrupted by the app being killed comes back Paused, and either one, started again, picks up from the files it already has rather than starting over.
Reading does not wait on any of this: Reader.open takes the issue id and fetches whatever is missing itself. This service is for downloading ahead of time — for offline reading — and for following what a download is doing.