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 b18e162761..8b645a4389 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 @@ -17,6 +17,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.download.Downloader +import eu.kanade.tachiyomi.data.notification.NotificationHandler import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.preference.PreferencesHelper @@ -92,19 +93,18 @@ class LibraryUpdateNotifier(private val context: Context) { /** * Shows notification containing update entries that failed with action to open full log. * - * @param skipped Number of entries that were skipped during the update. * @param failed Number of entries that failed to update. * @param uri Uri for error log file containing all titles that failed. */ - fun showUpdateErrorNotification(skipped: Int, failed: Int, uri: Uri) { - if (skipped == 0 && failed == 0) { + fun showUpdateErrorNotification(failed: Int, uri: Uri) { + if (failed == 0) { return } context.notificationManager.notify( Notifications.ID_LIBRARY_ERROR, context.notificationBuilder(Notifications.CHANNEL_LIBRARY_ERROR) { - setContentTitle(context.resources.getString(R.string.notification_update_skipped_error, skipped, failed)) + setContentTitle(context.resources.getString(R.string.notification_update_error, failed)) setContentText(context.getString(R.string.action_show_errors)) setSmallIcon(R.drawable.ic_tachi) @@ -114,6 +114,27 @@ class LibraryUpdateNotifier(private val context: Context) { ) } + /** + * Shows notification containing update entries that were skipped. + * + * @param skipped Number of entries that were skipped during the update. + */ + fun showUpdateSkippedNotification(skipped: Int) { + if (skipped == 0) { + return + } + + context.notificationManager.notify( + Notifications.ID_LIBRARY_SKIPPED, + context.notificationBuilder(Notifications.CHANNEL_LIBRARY_SKIPPED) { + setContentTitle(context.resources.getString(R.string.notification_update_skipped, skipped)) + setSmallIcon(R.drawable.ic_tachi) + addAction(R.drawable.ic_help_24dp, context.getString(R.string.learn_more), NotificationHandler.openUrl(context, HELP_SKIPPED_URL)) + } + .build() + ) + } + /** * Shows the notification containing the result of the update done by the service. * @@ -304,10 +325,9 @@ class LibraryUpdateNotifier(private val context: Context) { } return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) } - - companion object { - private const val NOTIF_MAX_CHAPTERS = 5 - private const val NOTIF_TITLE_MAX_LEN = 45 - private const val NOTIF_ICON_SIZE = 192 - } } + +private const val NOTIF_MAX_CHAPTERS = 5 +private const val NOTIF_TITLE_MAX_LEN = 45 +private const val NOTIF_ICON_SIZE = 192 +private const val HELP_SKIPPED_URL = "https://tachiyomi.org/help/faq/#why-does-global-update-skip-some-entries" 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 e556a6f124..5dc3bf0940 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 @@ -377,14 +377,16 @@ class LibraryUpdateService( } } - if (skippedUpdates.isNotEmpty() || failedUpdates.isNotEmpty()) { - val errorFile = writeErrorFile(skippedUpdates + failedUpdates) + if (failedUpdates.isNotEmpty()) { + val errorFile = writeErrorFile(failedUpdates) notifier.showUpdateErrorNotification( - skippedUpdates.size, failedUpdates.size, errorFile.getUriCompat(this), ) } + if (skippedUpdates.isNotEmpty()) { + notifier.showUpdateSkippedNotification(skippedUpdates.size) + } } private fun downloadChapters(manga: Manga, chapters: List) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationHandler.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationHandler.kt index 3aee021416..710e08fff1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationHandler.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationHandler.kt @@ -23,7 +23,7 @@ object NotificationHandler { flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP action = MainActivity.SHORTCUT_DOWNLOADS } - return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } /** @@ -38,7 +38,7 @@ object NotificationHandler { setDataAndType(uri, "image/*") flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION } - return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } /** @@ -52,6 +52,11 @@ object NotificationHandler { setDataAndType(uri, ExtensionInstaller.APK_MIME) flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION } - return PendingIntent.getActivity(context, 0, intent, 0) + return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE) + } + + fun openUrl(context: Context, url: String): PendingIntent { + val notificationIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) + return PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE) } } 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 5c9ffc36b1..e7cae48b89 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 @@ -28,6 +28,8 @@ object Notifications { const val ID_LIBRARY_PROGRESS = -101 const val CHANNEL_LIBRARY_ERROR = "library_errors_channel" const val ID_LIBRARY_ERROR = -102 + const val CHANNEL_LIBRARY_SKIPPED = "library_skipped_channel" + const val ID_LIBRARY_SKIPPED = -103 /** * Notification channel and ids used by the downloader. @@ -132,6 +134,11 @@ object Notifications { setGroup(GROUP_LIBRARY) setShowBadge(false) }, + buildNotificationChannel(CHANNEL_LIBRARY_SKIPPED, IMPORTANCE_LOW) { + setName(context.getString(R.string.channel_skipped)) + setGroup(GROUP_LIBRARY) + setShowBadge(false) + }, buildNotificationChannel(CHANNEL_NEW_CHAPTERS, IMPORTANCE_DEFAULT) { setName(context.getString(R.string.channel_new_chapters)) }, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2b9f5e13ce..608ad5cf14 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -736,7 +736,9 @@ Chapters %1$s and 1 more Chapters %1$s and %2$d more - %1$d update(s) skipped and %2$d update(s) failed + %1$d update(s) failed + %1$d update(s) skipped + Learn more Failed to update cover Please add the manga to your library before doing this For help on how to fix library update errors, see %1$s @@ -800,6 +802,7 @@ Progress Complete Errors + Skipped Chapter updates App updates Extension updates