Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/downloader manager persisting queue #639

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Extract reorder logic into function
  • Loading branch information
schroda committed Aug 6, 2023
commit a7ce7b8e2866dc4153360c70fe6a483db1f6a3f3
Original file line number Diff line number Diff line change
Expand Up @@ -314,21 +314,24 @@ object DownloadManager {
}

fun reorder(chapterIndex: Int, mangaId: Int, to: Int) {
require(to >= 0) { "'to' must be over or equal to 0" }
val download = downloadQueue.find { it.mangaId == mangaId && it.chapterIndex == chapterIndex }
?: return

logger.debug { "reorder download $download from ${downloadQueue.indexOf(download)} to $to" }

downloadQueue -= download
downloadQueue.add(to, download)
saveDownloadQueue()
reorder(download, to)
}

fun reorder(chapterId: Int, to: Int) {
require(to >= 0) { "'to' must be over or equal to 0" }
val download = downloadQueue.find { it.chapter.id == chapterId }
?: return

reorder(download, to)
}

private fun reorder(download: DownloadChapter, to: Int) {
require(to >= 0) { "'to' must be over or equal to 0" }

logger.debug { "reorder download $download from ${downloadQueue.indexOf(download)} to $to" }

downloadQueue -= download
downloadQueue.add(to, download)
saveDownloadQueue()
Expand Down