[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.
This commit is contained in:
Jimmy Low 2020-07-30 05:31:45 +08:00 committed by GitHub
parent b0106aa420
commit 7e73ede47a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 1 deletions

View File

@ -71,6 +71,27 @@ internal class DownloadNotifier(private val context: Context) {
context.notificationManager.cancel(Notifications.ID_DOWNLOAD_CHAPTER) 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. * Called when download progress changes.
* *

View File

@ -139,7 +139,7 @@ class Downloader(
notifier.paused = false notifier.paused = false
notifier.onDownloadPaused() notifier.onDownloadPaused()
} else { } else {
notifier.dismiss() notifier.downloadFinished()
} }
} }
} }

View File

@ -33,6 +33,7 @@ object Notifications {
const val CHANNEL_DOWNLOADER = "downloader_channel" const val CHANNEL_DOWNLOADER = "downloader_channel"
const val ID_DOWNLOAD_CHAPTER = -201 const val ID_DOWNLOAD_CHAPTER = -201
const val ID_DOWNLOAD_CHAPTER_ERROR = -202 const val ID_DOWNLOAD_CHAPTER_ERROR = -202
const val ID_DOWNLOAD_CHAPTER_COMPLETE = -203
/** /**
* Notification channel and ids used by the library updater. * Notification channel and ids used by the library updater.

View File

@ -672,6 +672,7 @@
<string name="download_notifier_text_only_wifi">No Wi-Fi connection available</string> <string name="download_notifier_text_only_wifi">No Wi-Fi connection available</string>
<string name="download_notifier_no_network">No network connection available</string> <string name="download_notifier_no_network">No network connection available</string>
<string name="download_notifier_download_paused">Download paused</string> <string name="download_notifier_download_paused">Download paused</string>
<string name="download_notifier_download_finish">Download completed</string>
<!-- Notification channels --> <!-- Notification channels -->
<string name="channel_common">Common</string> <string name="channel_common">Common</string>