Created
October 10, 2021 14:48
-
-
Save rohitjakhar/d36b440b4b0d437d6ec646630ea4301e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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