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