Fix download notification on download finish

This commit is contained in:
Koitharu
2022-05-12 12:50:06 +03:00
parent d5c1d86313
commit fce31df121

View File

@@ -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)