From 2ef277bceff5326986eba4072431336aef3c5152 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 2 Aug 2020 10:33:56 -0400 Subject: [PATCH] Don't show completed notification if download error notification was shown --- .../data/download/DownloadNotifier.kt | 26 ++++++++++--------- .../tachiyomi/data/download/Downloader.kt | 4 +-- .../tachiyomi/ui/reader/ReaderActivity.kt | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) 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 c3d14c25bc..f03f08bff2 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 @@ -119,7 +119,7 @@ internal class DownloadNotifier(private val context: Context) { /** * Show notification when download is paused. */ - fun onDownloadPaused() { + fun onPaused() { with(progressNotificationBuilder) { setContentTitle(context.getString(R.string.chapter_paused)) setContentText(context.getString(R.string.download_notifier_download_paused)) @@ -151,18 +151,20 @@ internal class DownloadNotifier(private val context: Context) { /** * This function shows a notification to inform download tasks are done. */ - fun downloadFinished() { - // Create notification - with(completeNotificationBuilder) { - 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) + fun onComplete() { + if (!errorThrown) { + // Create notification + with(completeNotificationBuilder) { + 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) + } + completeNotificationBuilder.show(Notifications.ID_DOWNLOAD_CHAPTER_COMPLETE) } - completeNotificationBuilder.show(Notifications.ID_DOWNLOAD_CHAPTER_COMPLETE) // Reset states to default errorThrown = false 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 ef928fdd08..67e288f43f 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 @@ -137,9 +137,9 @@ class Downloader( } else { if (notifier.paused) { notifier.paused = false - notifier.onDownloadPaused() + notifier.onPaused() } else { - notifier.downloadFinished() + notifier.onComplete() } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index a30aebc9d3..6439071e59 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -238,7 +238,7 @@ class ReaderActivity : BaseRxActivity() R.id.action_settings -> ReaderSettingsSheet(this).show() R.id.action_custom_filter -> { val sheet = ReaderColorFilterSheet(this) - // Remove dimmed backdrop so changes can be previewd + // Remove dimmed backdrop so changes can be previewed .apply { window?.setDimAmount(0f) } // Hide toolbars while sheet is open for better preview