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.
This commit is contained in:
arkon 2021-10-09 14:55:21 -04:00
parent 9106fc5b94
commit 082eef708f
7 changed files with 33 additions and 6 deletions

View file

@ -186,9 +186,9 @@ internal class DownloadNotifier(private val context: Context) {
*/ */
fun onWarning(reason: String) { fun onWarning(reason: String) {
with(errorNotificationBuilder) { with(errorNotificationBuilder) {
setContentTitle(context.getString(R.string.download_notifier_downloader_title)) setContentTitle(context.getString(R.string.label_warning))
setContentText(reason) setStyle(NotificationCompat.BigTextStyle().bigText(reason))
setSmallIcon(android.R.drawable.stat_sys_warning) setSmallIcon(R.drawable.ic_warning_white_24dp)
setAutoCancel(true) setAutoCancel(true)
clearActions() clearActions()
setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context)) setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context))
@ -216,7 +216,7 @@ internal class DownloadNotifier(private val context: Context) {
?: context.getString(R.string.download_notifier_downloader_title) ?: context.getString(R.string.download_notifier_downloader_title)
) )
setContentText(error ?: context.getString(R.string.download_notifier_unknown_error)) 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() clearActions()
setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context)) setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context))
setProgress(0, 0, false) setProgress(0, 0, false)

View file

@ -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.database.models.Manga
import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.data.download.model.DownloadQueue 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.SourceManager
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
@ -263,7 +264,10 @@ class Downloader(
// Start downloader if needed // Start downloader if needed
if (autoStart && wasEmpty) { 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)
} }
} }
} }

View file

@ -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. * Shows notification containing update entries that failed with action to open full log.
* *

View file

@ -264,6 +264,10 @@ class LibraryUpdateService(
mangaToUpdate = listToUpdate mangaToUpdate = listToUpdate
.distinctBy { it.id } .distinctBy { it.id }
.sortedWith(rankingScheme[selectedScheme]) .sortedWith(rankingScheme[selectedScheme])
if (mangaToUpdate.size > QUEUE_SIZE_WARNING_THRESHOLD) {
notifier.showQueueSizeWarningNotification()
}
} }
/** /**
@ -567,3 +571,5 @@ class LibraryUpdateService(
return File("") return File("")
} }
} }
const val QUEUE_SIZE_WARNING_THRESHOLD = 100

View file

@ -27,6 +27,7 @@ object Notifications {
private const val GROUP_LIBRARY = "group_library" private const val GROUP_LIBRARY = "group_library"
const val CHANNEL_LIBRARY_PROGRESS = "library_progress_channel" const val CHANNEL_LIBRARY_PROGRESS = "library_progress_channel"
const val ID_LIBRARY_PROGRESS = -101 const val ID_LIBRARY_PROGRESS = -101
const val ID_LIBRARY_SIZE_WARNING = -103
const val CHANNEL_LIBRARY_ERROR = "library_errors_channel" const val CHANNEL_LIBRARY_ERROR = "library_errors_channel"
const val ID_LIBRARY_ERROR = -102 const val ID_LIBRARY_ERROR = -102

View file

@ -117,7 +117,7 @@ internal class UpdaterNotifier(private val context: Context) {
fun onDownloadError(url: String) { fun onDownloadError(url: String) {
with(notificationBuilder) { with(notificationBuilder) {
setContentText(context.getString(R.string.update_check_notification_download_error)) 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) setOnlyAlertOnce(false)
setProgress(0, 0, false) setProgress(0, 0, false)

View file

@ -24,6 +24,7 @@
<string name="label_extension_info">Extension info</string> <string name="label_extension_info">Extension info</string>
<string name="label_help">Help</string> <string name="label_help">Help</string>
<string name="label_default">Default</string> <string name="label_default">Default</string>
<string name="label_warning">Warning</string>
<string name="unlock_app">Unlock Tachiyomi</string> <string name="unlock_app">Unlock Tachiyomi</string>
<string name="confirm_lock_change">Authenticate to confirm change</string> <string name="confirm_lock_change">Authenticate to confirm change</string>
@ -706,6 +707,7 @@
<!-- Library update service notifications --> <!-- Library update service notifications -->
<string name="notification_check_updates">Checking for new chapters</string> <string name="notification_check_updates">Checking for new chapters</string>
<string name="notification_updating">Updating library… (%1$d/%2$d)</string> <string name="notification_updating">Updating library… (%1$d/%2$d)</string>
<string name="notification_size_warning">Large updates may lead to increased battery usage and sources becoming slower</string>
<string name="notification_new_chapters">New chapters found</string> <string name="notification_new_chapters">New chapters found</string>
<plurals name="notification_new_chapters_summary"> <plurals name="notification_new_chapters_summary">
<item quantity="one">For 1 title</item> <item quantity="one">For 1 title</item>