From 7e73ede47abcd1f65ab2e0eb9506409d0357643b Mon Sep 17 00:00:00 2001
From: Jimmy Low <52811724+moe-attack@users.noreply.github.com>
Date: Thu, 30 Jul 2020 05:31:45 +0800
Subject: [PATCH] [Feature Request] - Download Complete Remidner #3475 (#3527)
* [Feat] Show a download complete notification channel when all downloads are completed. Auto cancels when onclick and navigate to download screen.
* [Feat] Update the download message string to shorten the length.
---
.../data/download/DownloadNotifier.kt | 21 +++++++++++++++++++
.../tachiyomi/data/download/Downloader.kt | 2 +-
.../data/notification/Notifications.kt | 1 +
app/src/main/res/values/strings.xml | 1 +
4 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt
index 2dde19e79..f93b343b1 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt
@@ -71,6 +71,27 @@ internal class DownloadNotifier(private val context: Context) {
context.notificationManager.cancel(Notifications.ID_DOWNLOAD_CHAPTER)
}
+ /**
+ * This function shows a notification to inform download tasks are done.
+ */
+ fun downloadFinished() {
+ // Create notification
+ with(notificationBuilder) {
+ setContentTitle(context.getString(R.string.download_notifier_downloader_title))
+ setContentText(context.getString(R.string.download_notifier_download_finish))
+ setSmallIcon(android.R.drawable.stat_sys_download_done)
+ clearActions()
+ setAutoCancel(true)
+ setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context))
+ setProgress(0, 0, false)
+ }
+ notificationBuilder.show(Notifications.ID_DOWNLOAD_CHAPTER_COMPLETE)
+
+ // Reset states to default
+ errorThrown = false
+ isDownloading = false
+ }
+
/**
* Called when download progress changes.
*
diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt
index cd5f82653..d87459a61 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt
@@ -139,7 +139,7 @@ class Downloader(
notifier.paused = false
notifier.onDownloadPaused()
} else {
- notifier.dismiss()
+ notifier.downloadFinished()
}
}
}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt
index cd8132fac..81165edfd 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt
@@ -33,6 +33,7 @@ object Notifications {
const val CHANNEL_DOWNLOADER = "downloader_channel"
const val ID_DOWNLOAD_CHAPTER = -201
const val ID_DOWNLOAD_CHAPTER_ERROR = -202
+ const val ID_DOWNLOAD_CHAPTER_COMPLETE = -203
/**
* Notification channel and ids used by the library updater.
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 14db14d9a..ef36c29a1 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -672,6 +672,7 @@
No Wi-Fi connection available
No network connection available
Download paused
+ Download completed
Common