Fix download notification on download finish

pull/168/head
Koitharu 4 years ago
parent d5c1d86313
commit fce31df121
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -99,8 +99,9 @@ class DownloadService : BaseService() {
private fun listenJob(job: ProgressJob<DownloadState>) {
lifecycleScope.launch {
val startId = job.progressValue.startId
val timeLeftEstimator = TimeLeftEstimator()
val notification = DownloadNotification(this@DownloadService, startId)
try {
val timeLeftEstimator = TimeLeftEstimator()
notificationSwitcher.notify(startId, notification.create(job.progressValue, -1L))
job.progressAsFlow()
.onEach { state ->
@ -117,6 +118,7 @@ class DownloadService : BaseService() {
notificationSwitcher.notify(startId, notification.create(state, timeLeft))
}
job.join()
} finally {
(job.progressValue as? DownloadState.Done)?.let {
sendBroadcast(
Intent(ACTION_DOWNLOAD_COMPLETE)
@ -134,6 +136,7 @@ class DownloadService : BaseService() {
stopSelf(startId)
}
}
}
private fun Flow<DownloadState>.whileActive(): Flow<DownloadState> = transformWhile { state ->
emit(state)

Loading…
Cancel
Save