From 082eef708fc50f4b26b499bfd50e9046ec26637a Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 9 Oct 2021 14:55:21 -0400 Subject: [PATCH] Add warnings when library and download queues are considered large (closes #5950) Arbitrarily set at a size of 100 for now. We could adjust this in the future as appropriate if needed. --- .../tachiyomi/data/download/DownloadNotifier.kt | 8 ++++---- .../kanade/tachiyomi/data/download/Downloader.kt | 6 +++++- .../data/library/LibraryUpdateNotifier.kt | 14 ++++++++++++++ .../tachiyomi/data/library/LibraryUpdateService.kt | 6 ++++++ .../tachiyomi/data/notification/Notifications.kt | 1 + .../tachiyomi/data/updater/UpdaterNotifier.kt | 2 +- app/src/main/res/values/strings.xml | 2 ++ 7 files changed, 33 insertions(+), 6 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 ae9d1be7d5..c5af10a41a 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 @@ -186,9 +186,9 @@ internal class DownloadNotifier(private val context: Context) { */ fun onWarning(reason: String) { with(errorNotificationBuilder) { - setContentTitle(context.getString(R.string.download_notifier_downloader_title)) - setContentText(reason) - setSmallIcon(android.R.drawable.stat_sys_warning) + setContentTitle(context.getString(R.string.label_warning)) + setStyle(NotificationCompat.BigTextStyle().bigText(reason)) + setSmallIcon(R.drawable.ic_warning_white_24dp) setAutoCancel(true) clearActions() setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context)) @@ -216,7 +216,7 @@ internal class DownloadNotifier(private val context: Context) { ?: context.getString(R.string.download_notifier_downloader_title) ) setContentText(error ?: context.getString(R.string.download_notifier_unknown_error)) - setSmallIcon(android.R.drawable.stat_sys_warning) + setSmallIcon(R.drawable.ic_warning_white_24dp) clearActions() setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context)) setProgress(0, 0, 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 99e777a4b6..e1bf847722 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 @@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.download.model.DownloadQueue +import eu.kanade.tachiyomi.data.library.QUEUE_SIZE_WARNING_THRESHOLD import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.online.HttpSource @@ -263,7 +264,10 @@ class Downloader( // Start downloader if needed if (autoStart && wasEmpty) { - DownloadService.start(this@Downloader.context) + if (queue.size > QUEUE_SIZE_WARNING_THRESHOLD) { + notifier.onWarning(context.getString(R.string.notification_size_warning)) + } + DownloadService.start(context) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt index 5caf8ba773..ac9a7618ed 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt @@ -88,6 +88,20 @@ class LibraryUpdateNotifier(private val context: Context) { ) } + fun showQueueSizeWarningNotification() { + val notification = context.notificationBuilder(Notifications.CHANNEL_LIBRARY_PROGRESS) { + setContentTitle(context.getString(R.string.label_warning)) + setSmallIcon(R.drawable.ic_warning_white_24dp) + setStyle(NotificationCompat.BigTextStyle().bigText(context.getString(R.string.notification_size_warning))) + } + .build() + + context.notificationManager.notify( + Notifications.ID_LIBRARY_SIZE_WARNING, + notification, + ) + } + /** * Shows notification containing update entries that failed with action to open full log. * diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 00faa04788..ebdef98e52 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -264,6 +264,10 @@ class LibraryUpdateService( mangaToUpdate = listToUpdate .distinctBy { it.id } .sortedWith(rankingScheme[selectedScheme]) + + if (mangaToUpdate.size > QUEUE_SIZE_WARNING_THRESHOLD) { + notifier.showQueueSizeWarningNotification() + } } /** @@ -567,3 +571,5 @@ class LibraryUpdateService( return File("") } } + +const val QUEUE_SIZE_WARNING_THRESHOLD = 100 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 c6403a25ca..753701a7b9 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 @@ -27,6 +27,7 @@ object Notifications { private const val GROUP_LIBRARY = "group_library" const val CHANNEL_LIBRARY_PROGRESS = "library_progress_channel" const val ID_LIBRARY_PROGRESS = -101 + const val ID_LIBRARY_SIZE_WARNING = -103 const val CHANNEL_LIBRARY_ERROR = "library_errors_channel" const val ID_LIBRARY_ERROR = -102 diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterNotifier.kt index 6dc4bec8c5..cf8735b7b1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterNotifier.kt @@ -117,7 +117,7 @@ internal class UpdaterNotifier(private val context: Context) { fun onDownloadError(url: String) { with(notificationBuilder) { setContentText(context.getString(R.string.update_check_notification_download_error)) - setSmallIcon(android.R.drawable.stat_sys_warning) + setSmallIcon(R.drawable.ic_warning_white_24dp) setOnlyAlertOnce(false) setProgress(0, 0, false) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f7a8ba2f91..e260ecbf81 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -24,6 +24,7 @@ Extension info Help Default + Warning Unlock Tachiyomi Authenticate to confirm change @@ -706,6 +707,7 @@ Checking for new chapters Updating library… (%1$d/%2$d) + Large updates may lead to increased battery usage and sources becoming slower New chapters found For 1 title