|
@@ -68,7 +68,13 @@ class DownloadManager(
|
|
|
* Tells the downloader to begin downloads.
|
|
|
*/
|
|
|
fun startDownloads() {
|
|
|
- DownloadJob.start(context)
|
|
|
+ if (downloader.isRunning) return
|
|
|
+
|
|
|
+ if (DownloadJob.isRunning(context)) {
|
|
|
+ downloader.start()
|
|
|
+ } else {
|
|
|
+ DownloadJob.start(context)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -97,22 +103,16 @@ class DownloadManager(
|
|
|
return queueState.value.find { it.chapter.id == chapterId }
|
|
|
}
|
|
|
|
|
|
- fun startDownloadNow(chapterId: Long?) {
|
|
|
- if (chapterId == null) return
|
|
|
- val download = getQueuedDownloadOrNull(chapterId)
|
|
|
+ fun startDownloadNow(chapterId: Long) {
|
|
|
+ val existingDownload = getQueuedDownloadOrNull(chapterId)
|
|
|
// If not in queue try to start a new download
|
|
|
- val toAdd = download ?: runBlocking { Download.fromChapterId(chapterId) } ?: return
|
|
|
- val queue = queueState.value.toMutableList()
|
|
|
- download?.let { queue.remove(it) }
|
|
|
- queue.add(0, toAdd)
|
|
|
- reorderQueue(queue)
|
|
|
- if (!downloader.isRunning) {
|
|
|
- if (DownloadJob.isRunning(context)) {
|
|
|
- downloader.start()
|
|
|
- } else {
|
|
|
- DownloadJob.start(context)
|
|
|
- }
|
|
|
+ val toAdd = existingDownload ?: runBlocking { Download.fromChapterId(chapterId) } ?: return
|
|
|
+ queueState.value.toMutableList().apply {
|
|
|
+ existingDownload?.let { remove(it) }
|
|
|
+ add(0, toAdd)
|
|
|
+ reorderQueue(this)
|
|
|
}
|
|
|
+ startDownloads()
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -146,7 +146,7 @@ class DownloadManager(
|
|
|
addAll(0, downloads)
|
|
|
reorderQueue(this)
|
|
|
}
|
|
|
- if (!DownloadJob.isRunning(context)) DownloadJob.start(context)
|
|
|
+ if (!DownloadJob.isRunning(context)) startDownloads()
|
|
|
}
|
|
|
|
|
|
/**
|