mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	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:
		| @@ -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) | ||||
|   | ||||
| @@ -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) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -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. | ||||
|      * | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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 | ||||
|  | ||||
|   | ||||
| @@ -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) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user