mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-16 19:09:17 +01:00
Fix related to cancelling queued chapters (#8528)
Tachi removes the downloaded chapter (if it exists) when you just cancelled a download from queue. PR fixes that Also removes redundant return
This commit is contained in:
parent
d60367768b
commit
ba2a528886
@ -214,22 +214,9 @@ class DownloadManager(
|
|||||||
return cache.getDownloadCount(manga)
|
return cache.getDownloadCount(manga)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
fun deletePendingDownloads(downloads: List<Download>) {
|
||||||
* Calls delete chapter, which deletes a temp download.
|
val domainChapters = downloads.map { it.chapter.toDomainChapter()!! }
|
||||||
*
|
removeFromDownloadQueue(domainChapters)
|
||||||
* @param download the download to cancel.
|
|
||||||
*/
|
|
||||||
fun deletePendingDownload(download: Download) {
|
|
||||||
deleteChapters(listOf(download.chapter.toDomainChapter()!!), download.manga, download.source, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun deletePendingDownloads(vararg downloads: Download) {
|
|
||||||
val downloadsByManga = downloads.groupBy { it.manga.id }
|
|
||||||
downloadsByManga.map { entry ->
|
|
||||||
val manga = entry.value.first().manga
|
|
||||||
val source = entry.value.first().source
|
|
||||||
deleteChapters(entry.value.map { it.chapter.toDomainChapter()!! }, manga, source, true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -238,14 +225,9 @@ class DownloadManager(
|
|||||||
* @param chapters the list of chapters to delete.
|
* @param chapters the list of chapters to delete.
|
||||||
* @param manga the manga of the chapters.
|
* @param manga the manga of the chapters.
|
||||||
* @param source the source of the chapters.
|
* @param source the source of the chapters.
|
||||||
* @param isCancelling true if it's simply cancelling a download
|
|
||||||
*/
|
*/
|
||||||
fun deleteChapters(chapters: List<Chapter>, manga: Manga, source: Source, isCancelling: Boolean = false): List<Chapter> {
|
fun deleteChapters(chapters: List<Chapter>, manga: Manga, source: Source) {
|
||||||
val filteredChapters = if (isCancelling) {
|
val filteredChapters = getChaptersToDelete(chapters, manga)
|
||||||
chapters
|
|
||||||
} else {
|
|
||||||
getChaptersToDelete(chapters, manga)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filteredChapters.isNotEmpty()) {
|
if (filteredChapters.isNotEmpty()) {
|
||||||
launchIO {
|
launchIO {
|
||||||
@ -269,8 +251,6 @@ class DownloadManager(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return filteredChapters
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeFromDownloadQueue(chapters: List<Chapter>) {
|
private fun removeFromDownloadQueue(chapters: List<Chapter>) {
|
||||||
|
@ -479,7 +479,7 @@ class DownloadController :
|
|||||||
presenter.reorder(selectedSeries + otherSeries)
|
presenter.reorder(selectedSeries + otherSeries)
|
||||||
}
|
}
|
||||||
R.id.cancel_download -> {
|
R.id.cancel_download -> {
|
||||||
presenter.cancelDownload(item.download)
|
presenter.cancelDownloads(listOf(item.download))
|
||||||
}
|
}
|
||||||
R.id.cancel_series -> {
|
R.id.cancel_series -> {
|
||||||
val allDownloadsForSeries = adapter?.currentItems
|
val allDownloadsForSeries = adapter?.currentItems
|
||||||
|
@ -72,11 +72,7 @@ class DownloadPresenter : BasePresenter<DownloadController>() {
|
|||||||
downloadManager.reorderQueue(downloads)
|
downloadManager.reorderQueue(downloads)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cancelDownload(download: Download) {
|
|
||||||
downloadManager.deletePendingDownload(download)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun cancelDownloads(downloads: List<Download>) {
|
fun cancelDownloads(downloads: List<Download>) {
|
||||||
downloadManager.deletePendingDownloads(*downloads.toTypedArray())
|
downloadManager.deletePendingDownloads(downloads)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -658,7 +658,7 @@ class MangaInfoScreenModel(
|
|||||||
|
|
||||||
fun cancelDownload(chapterId: Long) {
|
fun cancelDownload(chapterId: Long) {
|
||||||
val activeDownload = downloadManager.queue.find { chapterId == it.chapter.id } ?: return
|
val activeDownload = downloadManager.queue.find { chapterId == it.chapter.id } ?: return
|
||||||
downloadManager.deletePendingDownload(activeDownload)
|
downloadManager.deletePendingDownloads(listOf(activeDownload))
|
||||||
updateDownloadState(activeDownload.apply { status = Download.State.NOT_DOWNLOADED })
|
updateDownloadState(activeDownload.apply { status = Download.State.NOT_DOWNLOADED })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,8 +490,8 @@ class ReaderPresenter(
|
|||||||
* if setting is enabled and [currentChapter] is queued for download
|
* if setting is enabled and [currentChapter] is queued for download
|
||||||
*/
|
*/
|
||||||
private fun deleteChapterFromDownloadQueue(currentChapter: ReaderChapter): Download? {
|
private fun deleteChapterFromDownloadQueue(currentChapter: ReaderChapter): Download? {
|
||||||
return downloadManager.getChapterDownloadOrNull(currentChapter.chapter.toDomainChapter()!!)?.apply {
|
return downloadManager.getChapterDownloadOrNull(currentChapter.chapter.toDomainChapter()!!)?.also {
|
||||||
downloadManager.deletePendingDownload(this)
|
downloadManager.deletePendingDownloads(listOf(it))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ class UpdatesPresenter(
|
|||||||
|
|
||||||
private fun cancelDownload(chapterId: Long) {
|
private fun cancelDownload(chapterId: Long) {
|
||||||
val activeDownload = downloadManager.queue.find { chapterId == it.chapter.id } ?: return
|
val activeDownload = downloadManager.queue.find { chapterId == it.chapter.id } ?: return
|
||||||
downloadManager.deletePendingDownload(activeDownload)
|
downloadManager.deletePendingDownloads(listOf(activeDownload))
|
||||||
updateDownloadState(activeDownload.apply { status = Download.State.NOT_DOWNLOADED })
|
updateDownloadState(activeDownload.apply { status = Download.State.NOT_DOWNLOADED })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user