From fce3cd00a1f7ed557c04a40d676c6a32a4237482 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 17 Sep 2021 18:46:51 -0400 Subject: [PATCH] Remove setting to disable update error notifications and split out notification channel Users can exclude things from updating if needed, or disable the notification channel from system settings. --- .../data/library/LibraryUpdateNotifier.kt | 4 +- .../data/library/LibraryUpdateService.kt | 2 +- .../data/notification/Notifications.kt | 128 ++++++++++-------- .../data/preference/PreferenceKeys.kt | 2 - .../data/preference/PreferencesHelper.kt | 2 - .../ui/setting/SettingsLibraryController.kt | 5 - app/src/main/res/values/strings.xml | 4 - 7 files changed, 74 insertions(+), 73 deletions(-) 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 0db4f301a2..5caf8ba773 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 @@ -51,7 +51,7 @@ class LibraryUpdateNotifier(private val context: Context) { * Cached progress notification to avoid creating a lot. */ val progressNotificationBuilder by lazy { - context.notificationBuilder(Notifications.CHANNEL_LIBRARY) { + context.notificationBuilder(Notifications.CHANNEL_LIBRARY_PROGRESS) { setContentTitle(context.getString(R.string.app_name)) setSmallIcon(R.drawable.ic_refresh_24dp) setLargeIcon(notificationBitmap) @@ -101,7 +101,7 @@ class LibraryUpdateNotifier(private val context: Context) { context.notificationManager.notify( Notifications.ID_LIBRARY_ERROR, - context.notificationBuilder(Notifications.CHANNEL_LIBRARY) { + context.notificationBuilder(Notifications.CHANNEL_LIBRARY_ERROR) { setContentTitle(context.resources.getQuantityString(R.plurals.notification_update_error, errors.size, errors.size)) setStyle( NotificationCompat.BigTextStyle().bigText( 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 d23a5b5e26..44e7c13a69 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 @@ -350,7 +350,7 @@ class LibraryUpdateService( } } - if (preferences.showLibraryUpdateErrors() && failedUpdates.isNotEmpty()) { + if (failedUpdates.isNotEmpty()) { val errorFile = writeErrorFile(failedUpdates) notifier.showUpdateErrorNotification( failedUpdates.map { it.first.title }, 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 8999a93479..11887d2839 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 @@ -24,8 +24,10 @@ object Notifications { /** * Notification channel and ids used by the library updater. */ - const val CHANNEL_LIBRARY = "library_channel" + private const val GROUP_LIBRARY = "group_library" + const val CHANNEL_LIBRARY_PROGRESS = "library_progress_channel" const val ID_LIBRARY_PROGRESS = -101 + const val CHANNEL_LIBRARY_ERROR = "library_errors_channel" const val ID_LIBRARY_ERROR = -102 /** @@ -77,7 +79,8 @@ object Notifications { private val deprecatedChannels = listOf( "downloader_channel", - "backup_restore_complete_channel" + "backup_restore_complete_channel", + "library_channel", ) /** @@ -89,64 +92,75 @@ object Notifications { fun createChannels(context: Context) { val notificationService = NotificationManagerCompat.from(context) - val channelGroupList = listOf( - buildNotificationChannelGroup(GROUP_BACKUP_RESTORE) { - setName(context.getString(R.string.group_backup_restore)) - }, - buildNotificationChannelGroup(GROUP_DOWNLOADER) { - setName(context.getString(R.string.group_downloader)) - } + notificationService.createNotificationChannelGroupsCompat( + listOf( + buildNotificationChannelGroup(GROUP_BACKUP_RESTORE) { + setName(context.getString(R.string.label_backup)) + }, + buildNotificationChannelGroup(GROUP_DOWNLOADER) { + setName(context.getString(R.string.download_notifier_downloader_title)) + }, + buildNotificationChannelGroup(GROUP_LIBRARY) { + setName(context.getString(R.string.label_library)) + }, + ) ) - notificationService.createNotificationChannelGroupsCompat(channelGroupList) - val channelList = listOf( - buildNotificationChannel(CHANNEL_COMMON, IMPORTANCE_LOW) { - setName(context.getString(R.string.channel_common)) - }, - buildNotificationChannel(CHANNEL_LIBRARY, IMPORTANCE_LOW) { - setName(context.getString(R.string.channel_library)) - setShowBadge(false) - }, - buildNotificationChannel(CHANNEL_DOWNLOADER_PROGRESS, IMPORTANCE_LOW) { - setName(context.getString(R.string.channel_progress)) - setGroup(GROUP_DOWNLOADER) - setShowBadge(false) - }, - buildNotificationChannel(CHANNEL_DOWNLOADER_COMPLETE, IMPORTANCE_LOW) { - setName(context.getString(R.string.channel_complete)) - setGroup(GROUP_DOWNLOADER) - setShowBadge(false) - }, - buildNotificationChannel(CHANNEL_DOWNLOADER_ERROR, IMPORTANCE_LOW) { - setName(context.getString(R.string.channel_errors)) - setGroup(GROUP_DOWNLOADER) - setShowBadge(false) - }, - buildNotificationChannel(CHANNEL_NEW_CHAPTERS, IMPORTANCE_DEFAULT) { - setName(context.getString(R.string.channel_new_chapters)) - }, - buildNotificationChannel(CHANNEL_UPDATES_TO_EXTS, IMPORTANCE_DEFAULT) { - setName(context.getString(R.string.channel_ext_updates)) - }, - buildNotificationChannel(CHANNEL_BACKUP_RESTORE_PROGRESS, IMPORTANCE_LOW) { - setName(context.getString(R.string.channel_progress)) - setGroup(GROUP_BACKUP_RESTORE) - setShowBadge(false) - }, - buildNotificationChannel(CHANNEL_BACKUP_RESTORE_COMPLETE, IMPORTANCE_HIGH) { - setName(context.getString(R.string.channel_complete)) - setGroup(GROUP_BACKUP_RESTORE) - setShowBadge(false) - setSound(null, null) - }, - buildNotificationChannel(CHANNEL_CRASH_LOGS, IMPORTANCE_HIGH) { - setName(context.getString(R.string.channel_crash_logs)) - }, - buildNotificationChannel(CHANNEL_INCOGNITO_MODE, IMPORTANCE_LOW) { - setName(context.getString(R.string.pref_incognito_mode)) - }, + notificationService.createNotificationChannelsCompat( + listOf( + buildNotificationChannel(CHANNEL_COMMON, IMPORTANCE_LOW) { + setName(context.getString(R.string.channel_common)) + }, + buildNotificationChannel(CHANNEL_LIBRARY_PROGRESS, IMPORTANCE_LOW) { + setName(context.getString(R.string.channel_progress)) + setGroup(GROUP_LIBRARY) + setShowBadge(false) + }, + buildNotificationChannel(CHANNEL_LIBRARY_ERROR, IMPORTANCE_LOW) { + setName(context.getString(R.string.channel_errors)) + setGroup(GROUP_LIBRARY) + setShowBadge(false) + }, + buildNotificationChannel(CHANNEL_NEW_CHAPTERS, IMPORTANCE_DEFAULT) { + setName(context.getString(R.string.channel_new_chapters)) + }, + buildNotificationChannel(CHANNEL_DOWNLOADER_PROGRESS, IMPORTANCE_LOW) { + setName(context.getString(R.string.channel_progress)) + setGroup(GROUP_DOWNLOADER) + setShowBadge(false) + }, + buildNotificationChannel(CHANNEL_DOWNLOADER_COMPLETE, IMPORTANCE_LOW) { + setName(context.getString(R.string.channel_complete)) + setGroup(GROUP_DOWNLOADER) + setShowBadge(false) + }, + buildNotificationChannel(CHANNEL_DOWNLOADER_ERROR, IMPORTANCE_LOW) { + setName(context.getString(R.string.channel_errors)) + setGroup(GROUP_DOWNLOADER) + setShowBadge(false) + }, + buildNotificationChannel(CHANNEL_BACKUP_RESTORE_PROGRESS, IMPORTANCE_LOW) { + setName(context.getString(R.string.channel_progress)) + setGroup(GROUP_BACKUP_RESTORE) + setShowBadge(false) + }, + buildNotificationChannel(CHANNEL_BACKUP_RESTORE_COMPLETE, IMPORTANCE_HIGH) { + setName(context.getString(R.string.channel_complete)) + setGroup(GROUP_BACKUP_RESTORE) + setShowBadge(false) + setSound(null, null) + }, + buildNotificationChannel(CHANNEL_CRASH_LOGS, IMPORTANCE_HIGH) { + setName(context.getString(R.string.channel_crash_logs)) + }, + buildNotificationChannel(CHANNEL_INCOGNITO_MODE, IMPORTANCE_LOW) { + setName(context.getString(R.string.pref_incognito_mode)) + }, + buildNotificationChannel(CHANNEL_UPDATES_TO_EXTS, IMPORTANCE_DEFAULT) { + setName(context.getString(R.string.channel_ext_updates)) + }, + ) ) - notificationService.createNotificationChannelsCompat(channelList) // Delete old notification channels deprecatedChannels.forEach(notificationService::deleteNotificationChannel) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 0fe8892db0..2bbbc0e0d2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -171,8 +171,6 @@ object PreferenceKeys { const val autoUpdateTrackers = "auto_update_trackers" - const val showLibraryUpdateErrors = "show_library_update_errors" - const val downloadNew = "download_new" const val downloadNewCategories = "download_new_categories" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index d5c2b2ecae..6b95f9e04d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -86,8 +86,6 @@ class PreferencesHelper(val context: Context) { fun autoUpdateTrackers() = prefs.getBoolean(Keys.autoUpdateTrackers, false) - fun showLibraryUpdateErrors() = prefs.getBoolean(Keys.showLibraryUpdateErrors, true) - fun themeMode() = flowPrefs.getEnum(Keys.themeMode, system) fun appTheme() = flowPrefs.getEnum(Keys.appTheme, Values.AppTheme.DEFAULT) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 57ecb05386..8889fb7db4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -282,11 +282,6 @@ class SettingsLibraryController : SettingsController() { defaultValue = false } } - switchPreference { - key = Keys.showLibraryUpdateErrors - titleRes = R.string.pref_library_update_error_notification - defaultValue = true - } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6569073ef3..453237af46 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -226,7 +226,6 @@ Check for new cover and details when updating library Automatically refresh trackers Update trackers when updating library - Show update errors notifications Default category Always ask @@ -775,9 +774,6 @@ Progress Complete Errors - Library - Downloads - Backup and restore Chapter updates Extension updates Crash logs