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

Loading…
Cancel
Save