mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-14 13:08:56 +01:00
Handle download cancelation from icon properly (fixes #4241)
This commit is contained in:
@@ -212,8 +212,19 @@ class DownloadManager(private val context: Context) {
|
||||
fun deleteChapters(chapters: List<Chapter>, manga: Manga, source: Source): List<Chapter> {
|
||||
val filteredChapters = getChaptersToDelete(chapters)
|
||||
|
||||
val wasRunning = downloader.isRunning
|
||||
downloader.pause()
|
||||
|
||||
downloader.queue.remove(filteredChapters)
|
||||
queue.remove(filteredChapters)
|
||||
|
||||
if (downloader.queue.isEmpty()) {
|
||||
DownloadService.stop(context)
|
||||
downloader.stop()
|
||||
} else if (wasRunning && downloader.queue.isNotEmpty()) {
|
||||
downloader.start()
|
||||
}
|
||||
|
||||
val chapterDirs = provider.findChapterDirs(filteredChapters, manga, source)
|
||||
chapterDirs.forEach { it.delete() }
|
||||
cache.removeChapters(filteredChapters, manga)
|
||||
|
||||
@@ -165,6 +165,8 @@ internal class DownloadNotifier(private val context: Context) {
|
||||
* This function shows a notification to inform download tasks are done.
|
||||
*/
|
||||
fun onComplete() {
|
||||
dismissProgress()
|
||||
|
||||
if (!errorThrown) {
|
||||
// Create notification
|
||||
with(completeNotificationBuilder) {
|
||||
|
||||
@@ -134,15 +134,16 @@ class Downloader(
|
||||
|
||||
if (reason != null) {
|
||||
notifier.onWarning(reason)
|
||||
} else {
|
||||
if (notifier.paused) {
|
||||
notifier.paused = false
|
||||
notifier.onPaused()
|
||||
} else {
|
||||
notifier.dismissProgress()
|
||||
notifier.onComplete()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (notifier.paused && !queue.isEmpty()) {
|
||||
notifier.onPaused()
|
||||
} else {
|
||||
notifier.onComplete()
|
||||
}
|
||||
|
||||
notifier.paused = false
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user