Build download error notifications fresh each time

The warning and error notifications shared one builder for the life of
the app, so an error kept the first notification's timestamp and the
previous warning's expanded text, auto cancel and timeout.

Closes #3341
This commit is contained in:
AntsyLich
2026-10-04 13:11:06 +06:00
parent d1c5c12bdd
commit f82a7a68f4
@@ -38,12 +38,6 @@ class DownloadNotifier(
}
}
private val errorNotificationBuilder by lazy {
context.notificationBuilder(Notifications.CHANNEL_DOWNLOADER_ERROR) {
setAutoCancel(false)
}
}
/**
* Status of download. Used for correct notification icon.
*/
@@ -171,12 +165,14 @@ class DownloadNotifier(
* Only works on Android 8+.
*/
fun onWarning(reason: String, timeout: Long? = null, contentIntent: PendingIntent? = null, mangaId: Long? = null) {
with(errorNotificationBuilder) {
context.notify(
Notifications.ID_DOWNLOAD_CHAPTER_ERROR,
Notifications.CHANNEL_DOWNLOADER_ERROR,
) {
setContentTitle(context.stringResource(MR.strings.download_notifier_downloader_title))
setStyle(NotificationCompat.BigTextStyle().bigText(reason))
setSmallIcon(R.drawable.ic_warning_white_24dp)
setAutoCancel(true)
clearActions()
setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context))
if (mangaId != null) {
addAction(
@@ -185,11 +181,8 @@ class DownloadNotifier(
NotificationReceiver.openEntryPendingActivity(context, mangaId),
)
}
setProgress(0, 0, false)
timeout?.let { setTimeoutAfter(it) }
contentIntent?.let { setContentIntent(it) }
show(Notifications.ID_DOWNLOAD_CHAPTER_ERROR)
}
// Reset download information
@@ -206,13 +199,15 @@ class DownloadNotifier(
*/
fun onError(error: String? = null, chapter: String? = null, mangaTitle: String? = null, mangaId: Long? = null) {
// Create notification
with(errorNotificationBuilder) {
context.notify(
Notifications.ID_DOWNLOAD_CHAPTER_ERROR,
Notifications.CHANNEL_DOWNLOADER_ERROR,
) {
setContentTitle(
mangaTitle?.plus(": $chapter") ?: context.stringResource(MR.strings.download_notifier_downloader_title),
)
setContentText(error ?: context.stringResource(MR.strings.download_notifier_unknown_error))
setSmallIcon(R.drawable.ic_warning_white_24dp)
clearActions()
setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context))
if (mangaId != null) {
addAction(
@@ -221,9 +216,6 @@ class DownloadNotifier(
NotificationReceiver.openEntryPendingActivity(context, mangaId),
)
}
setProgress(0, 0, false)
show(Notifications.ID_DOWNLOAD_CHAPTER_ERROR)
}
// Reset download information