Skip to content

Commit a6ccb5b

Browse files
authored
Merge pull request #7259 from Bnyro/master
fix: automatically resume next paused download item after finishing previous one
2 parents 53a76d2 + ad2539c commit a6ccb5b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

app/src/main/java/com/github/libretube/services/DownloadService.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,17 @@ class DownloadService : LifecycleService() {
227227

228228
downloadQueue[item.id] = false
229229

230-
if (_downloadFlow.firstOrNull { it.first == item.id }?.second == DownloadStatus.Stopped) {
230+
if (downloadFlow.firstOrNull { it.first == item.id }?.second == DownloadStatus.Stopped) {
231231
downloadQueue.remove(item.id, false)
232232
}
233233

234-
stopServiceIfDone()
234+
// start the next download if there are any remaining ones enqueued
235+
val nextDownload = downloadFlow.firstOrNull { (_, status) -> status == DownloadStatus.Paused }
236+
if (nextDownload != null) {
237+
resume(nextDownload.first)
238+
} else {
239+
stopServiceIfDone()
240+
}
235241
}
236242

237243
private suspend fun progressDownload(

0 commit comments

Comments
 (0)