Skip to content

Instantly share code, notes, and snippets.

@hasankucuk
Created January 21, 2021 11:12
Show Gist options
  • Save hasankucuk/302bacd00efe222a1ac9f5b3032fc1d2 to your computer and use it in GitHub Desktop.
Save hasankucuk/302bacd00efe222a1ac9f5b3032fc1d2 to your computer and use it in GitHub Desktop.
class DownloadingModel {
private val _state = MutableStateFlow<DownloadStatus>(DownloadStatus.NOT_REQUESTED) val state: StateFlow<DownloadStatus> get() = _state
suspend fun download() {
_state.value = DownloadStatus.INITIALIZED initializeConnection() processAvailableContent {
partialData: ByteArray, downloadedBytes: Long, totalBytes: Long ->
storePartialData(partialData) _state.value = DownloadStatus.IN_PROGRESS } _state.value = DownloadStatus.SUCCESS
} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment