From 0edc981cd2331e70b43ff71f5c23ed74758d934e Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 30 Oct 2021 17:42:06 -0400 Subject: [PATCH] Move app and extension update notifications to new channels/group (closes #6168) --- .../data/notification/Notifications.kt | 36 ++++++++++++------- .../data/updater/AppUpdateNotifier.kt | 10 +++--- .../data/updater/AppUpdateService.kt | 2 +- .../tachiyomi/extension/ExtensionUpdateJob.kt | 2 +- .../extension/util/ExtensionInstallService.kt | 2 +- app/src/main/res/values/strings.xml | 1 + 6 files changed, 33 insertions(+), 20 deletions(-) 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..5c9ffc36b1 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 @@ -18,7 +18,6 @@ object Notifications { * Common notification channel and ids used anywhere. */ const val CHANNEL_COMMON = "common_channel" - const val ID_UPDATER = 1 const val ID_DOWNLOAD_IMAGE = 2 /** @@ -48,13 +47,6 @@ object Notifications { const val ID_NEW_CHAPTERS = -301 const val GROUP_NEW_CHAPTERS = "eu.kanade.tachiyomi.NEW_CHAPTERS" - /** - * Notification channel and ids used by the library updater. - */ - const val CHANNEL_UPDATES_TO_EXTS = "updates_ext_channel" - const val ID_UPDATES_TO_EXTS = -401 - const val ID_EXTENSION_INSTALLER = -402 - /** * Notification channel and ids used by the backup/restore system. */ @@ -78,10 +70,22 @@ object Notifications { const val CHANNEL_INCOGNITO_MODE = "incognito_mode_channel" const val ID_INCOGNITO_MODE = -701 + /** + * Notification channel and ids used for app and extension updates. + */ + private const val GROUP_APK_UPDATES = "group_apk_updates" + const val CHANNEL_APP_UPDATE = "app_apk_update_channel" + const val ID_APP_UPDATER = 1 + const val CHANNEL_EXTENSIONS_UPDATE = "ext_apk_update_channel" + const val ID_UPDATES_TO_EXTS = -401 + const val ID_EXTENSION_INSTALLER = -402 + private val deprecatedChannels = listOf( "downloader_channel", "backup_restore_complete_channel", "library_channel", + "library_progress_channel", + "updates_ext_channel", ) /** @@ -93,6 +97,9 @@ object Notifications { fun createChannels(context: Context) { val notificationService = NotificationManagerCompat.from(context) + // Delete old notification channels + deprecatedChannels.forEach(notificationService::deleteNotificationChannel) + notificationService.createNotificationChannelGroupsCompat( listOf( buildNotificationChannelGroup(GROUP_BACKUP_RESTORE) { @@ -104,6 +111,9 @@ object Notifications { buildNotificationChannelGroup(GROUP_LIBRARY) { setName(context.getString(R.string.label_library)) }, + buildNotificationChannelGroup(GROUP_APK_UPDATES) { + setName(context.getString(R.string.label_recent_updates)) + }, ) ) @@ -157,13 +167,15 @@ object Notifications { buildNotificationChannel(CHANNEL_INCOGNITO_MODE, IMPORTANCE_LOW) { setName(context.getString(R.string.pref_incognito_mode)) }, - buildNotificationChannel(CHANNEL_UPDATES_TO_EXTS, IMPORTANCE_DEFAULT) { + buildNotificationChannel(CHANNEL_APP_UPDATE, IMPORTANCE_DEFAULT) { + setGroup(GROUP_APK_UPDATES) + setName(context.getString(R.string.channel_app_updates)) + }, + buildNotificationChannel(CHANNEL_EXTENSIONS_UPDATE, IMPORTANCE_DEFAULT) { + setGroup(GROUP_APK_UPDATES) setName(context.getString(R.string.channel_ext_updates)) }, ) ) - - // Delete old notification channels - deprecatedChannels.forEach(notificationService::deleteNotificationChannel) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateNotifier.kt index 9701be1668..00eab8124e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateNotifier.kt @@ -15,14 +15,14 @@ import eu.kanade.tachiyomi.util.system.notificationManager internal class AppUpdateNotifier(private val context: Context) { - private val notificationBuilder = context.notificationBuilder(Notifications.CHANNEL_COMMON) + private val notificationBuilder = context.notificationBuilder(Notifications.CHANNEL_APP_UPDATE) /** * Call to show notification. * * @param id id of the notification channel. */ - private fun NotificationCompat.Builder.show(id: Int = Notifications.ID_UPDATER) { + private fun NotificationCompat.Builder.show(id: Int = Notifications.ID_APP_UPDATER) { context.notificationManager.notify(id, build()) } @@ -109,7 +109,7 @@ internal class AppUpdateNotifier(private val context: Context) { addAction( R.drawable.ic_close_24dp, context.getString(R.string.action_cancel), - NotificationReceiver.dismissNotificationPendingBroadcast(context, Notifications.ID_UPDATER) + NotificationReceiver.dismissNotificationPendingBroadcast(context, Notifications.ID_APP_UPDATER) ) } notificationBuilder.show() @@ -136,9 +136,9 @@ internal class AppUpdateNotifier(private val context: Context) { addAction( R.drawable.ic_close_24dp, context.getString(R.string.action_cancel), - NotificationReceiver.dismissNotificationPendingBroadcast(context, Notifications.ID_UPDATER) + NotificationReceiver.dismissNotificationPendingBroadcast(context, Notifications.ID_APP_UPDATER) ) } - notificationBuilder.show(Notifications.ID_UPDATER) + notificationBuilder.show(Notifications.ID_APP_UPDATER) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateService.kt index e899102429..470151116a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateService.kt @@ -42,7 +42,7 @@ class AppUpdateService : Service() { notifier = AppUpdateNotifier(this) wakeLock = acquireWakeLock(javaClass.name) - startForeground(Notifications.ID_UPDATER, notifier.onDownloadStarted().build()) + startForeground(Notifications.ID_APP_UPDATER, notifier.onDownloadStarted().build()) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt index fbf2b6f640..bdcd7a1d8c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt @@ -42,7 +42,7 @@ class ExtensionUpdateJob(private val context: Context, workerParams: WorkerParam NotificationManagerCompat.from(context).apply { notify( Notifications.ID_UPDATES_TO_EXTS, - context.notification(Notifications.CHANNEL_UPDATES_TO_EXTS) { + context.notification(Notifications.CHANNEL_EXTENSIONS_UPDATE) { setContentTitle( context.resources.getQuantityString( R.plurals.update_check_notification_ext_updates, diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallService.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallService.kt index c052f3ccb0..f470caa546 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallService.kt @@ -22,7 +22,7 @@ class ExtensionInstallService : Service() { override fun onCreate() { super.onCreate() - val notification = notificationBuilder(Notifications.CHANNEL_DOWNLOADER_PROGRESS) { + val notification = notificationBuilder(Notifications.CHANNEL_EXTENSIONS_UPDATE) { setSmallIcon(R.drawable.ic_tachi) setAutoCancel(false) setOngoing(true) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d18ca02f74..a273027bd5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -789,6 +789,7 @@ Complete Errors Chapter updates + App updates Extension updates Crash logs