Skip to content

Instantly share code, notes, and snippets.

@rohitjakhar
Created October 10, 2021 14:48
Show Gist options
  • Save rohitjakhar/d36b440b4b0d437d6ec646630ea4301e to your computer and use it in GitHub Desktop.
Save rohitjakhar/d36b440b4b0d437d6ec646630ea4301e to your computer and use it in GitHub Desktop.
private val onDownloadCompleteReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent == null) {
log("onDownloadComplete intent is: $intent")
return
}
if (intent.action == DownloadManager.ACTION_DOWNLOAD_COMPLETE) {
val id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)
val downloadedFileURI = mDownloadManager?.getUriForDownloadedFile(id)
viewModel.enqueuedDownloadingTasksIds.let { enqueuedTasks ->
if (!enqueuedTasks.contains(id)) {
log("downloaded file is not pcmc file")
return
} else {
enqueuedTasks.remove(id)
if (enqueuedTasks.isEmpty()) { // this file is the last file to be downloaded
viewModel.updateMapDownloadingStatus(getString(R.string.all_files_downloaded))
proceedExtractingZip(downloadedFileURI, isLastFile = true)
} else {
proceedExtractingZip(downloadedFileURI)
}
}
log("Downloaded file id: $id \nURI: $downloadedFileURI")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment