Keep the paused download notification after the worker stops
The paused notification reused the download worker's foreground notification id, so it was removed together with the foreground service when the worker finished. Closes #2791
This commit is contained in:
@@ -58,6 +58,7 @@ class DownloadNotifier(
|
|||||||
*/
|
*/
|
||||||
fun dismissProgress() {
|
fun dismissProgress() {
|
||||||
context.cancelNotification(Notifications.ID_DOWNLOAD_CHAPTER_PROGRESS)
|
context.cancelNotification(Notifications.ID_DOWNLOAD_CHAPTER_PROGRESS)
|
||||||
|
context.cancelNotification(Notifications.ID_DOWNLOAD_CHAPTER_PAUSED)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,6 +69,7 @@ class DownloadNotifier(
|
|||||||
fun onProgressChange(download: Download) {
|
fun onProgressChange(download: Download) {
|
||||||
with(progressNotificationBuilder) {
|
with(progressNotificationBuilder) {
|
||||||
if (!isDownloading) {
|
if (!isDownloading) {
|
||||||
|
context.cancelNotification(Notifications.ID_DOWNLOAD_CHAPTER_PAUSED)
|
||||||
setSmallIcon(android.R.drawable.stat_sys_download)
|
setSmallIcon(android.R.drawable.stat_sys_download)
|
||||||
clearActions()
|
clearActions()
|
||||||
// Open download manager when clicked
|
// Open download manager when clicked
|
||||||
@@ -117,13 +119,17 @@ class DownloadNotifier(
|
|||||||
* Show notification when download is paused.
|
* Show notification when download is paused.
|
||||||
*/
|
*/
|
||||||
fun onPaused() {
|
fun onPaused() {
|
||||||
with(progressNotificationBuilder) {
|
// The progress id belongs to the download worker's foreground service, which takes the
|
||||||
|
// notification with it when the worker stops
|
||||||
|
context.notify(
|
||||||
|
Notifications.ID_DOWNLOAD_CHAPTER_PAUSED,
|
||||||
|
Notifications.CHANNEL_DOWNLOADER_PROGRESS,
|
||||||
|
) {
|
||||||
setContentTitle(context.stringResource(MR.strings.chapter_paused))
|
setContentTitle(context.stringResource(MR.strings.chapter_paused))
|
||||||
setContentText(context.stringResource(MR.strings.download_notifier_download_paused))
|
setContentText(context.stringResource(MR.strings.download_notifier_download_paused))
|
||||||
setSmallIcon(R.drawable.ic_pause_24dp)
|
setSmallIcon(R.drawable.ic_pause_24dp)
|
||||||
setProgress(0, 0, false)
|
setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher))
|
||||||
setOngoing(false)
|
setOnlyAlertOnce(true)
|
||||||
clearActions()
|
|
||||||
// Open download manager when clicked
|
// Open download manager when clicked
|
||||||
setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context))
|
setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context))
|
||||||
// Resume action
|
// Resume action
|
||||||
@@ -138,8 +144,6 @@ class DownloadNotifier(
|
|||||||
context.stringResource(MR.strings.action_cancel_all),
|
context.stringResource(MR.strings.action_cancel_all),
|
||||||
NotificationReceiver.clearDownloadsPendingBroadcast(context),
|
NotificationReceiver.clearDownloadsPendingBroadcast(context),
|
||||||
)
|
)
|
||||||
|
|
||||||
show(Notifications.ID_DOWNLOAD_CHAPTER_PROGRESS)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset initial values
|
// Reset initial values
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ object Notifications {
|
|||||||
private const val GROUP_DOWNLOADER = "group_downloader"
|
private const val GROUP_DOWNLOADER = "group_downloader"
|
||||||
const val CHANNEL_DOWNLOADER_PROGRESS = "downloader_progress_channel"
|
const val CHANNEL_DOWNLOADER_PROGRESS = "downloader_progress_channel"
|
||||||
const val ID_DOWNLOAD_CHAPTER_PROGRESS = -201
|
const val ID_DOWNLOAD_CHAPTER_PROGRESS = -201
|
||||||
|
const val ID_DOWNLOAD_CHAPTER_PAUSED = -203
|
||||||
const val CHANNEL_DOWNLOADER_ERROR = "downloader_error_channel"
|
const val CHANNEL_DOWNLOADER_ERROR = "downloader_error_channel"
|
||||||
const val ID_DOWNLOAD_CHAPTER_ERROR = -202
|
const val ID_DOWNLOAD_CHAPTER_ERROR = -202
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user