Move app and extension update notifications to new channels/group (closes #6168)

This commit is contained in:
arkon 2021-10-30 17:42:06 -04:00
parent da5942b398
commit 0edc981cd2
6 changed files with 33 additions and 20 deletions

View File

@ -18,7 +18,6 @@ object Notifications {
* Common notification channel and ids used anywhere. * Common notification channel and ids used anywhere.
*/ */
const val CHANNEL_COMMON = "common_channel" const val CHANNEL_COMMON = "common_channel"
const val ID_UPDATER = 1
const val ID_DOWNLOAD_IMAGE = 2 const val ID_DOWNLOAD_IMAGE = 2
/** /**
@ -48,13 +47,6 @@ object Notifications {
const val ID_NEW_CHAPTERS = -301 const val ID_NEW_CHAPTERS = -301
const val GROUP_NEW_CHAPTERS = "eu.kanade.tachiyomi.NEW_CHAPTERS" 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. * 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 CHANNEL_INCOGNITO_MODE = "incognito_mode_channel"
const val ID_INCOGNITO_MODE = -701 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( private val deprecatedChannels = listOf(
"downloader_channel", "downloader_channel",
"backup_restore_complete_channel", "backup_restore_complete_channel",
"library_channel", "library_channel",
"library_progress_channel",
"updates_ext_channel",
) )
/** /**
@ -93,6 +97,9 @@ object Notifications {
fun createChannels(context: Context) { fun createChannels(context: Context) {
val notificationService = NotificationManagerCompat.from(context) val notificationService = NotificationManagerCompat.from(context)
// Delete old notification channels
deprecatedChannels.forEach(notificationService::deleteNotificationChannel)
notificationService.createNotificationChannelGroupsCompat( notificationService.createNotificationChannelGroupsCompat(
listOf( listOf(
buildNotificationChannelGroup(GROUP_BACKUP_RESTORE) { buildNotificationChannelGroup(GROUP_BACKUP_RESTORE) {
@ -104,6 +111,9 @@ object Notifications {
buildNotificationChannelGroup(GROUP_LIBRARY) { buildNotificationChannelGroup(GROUP_LIBRARY) {
setName(context.getString(R.string.label_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) { buildNotificationChannel(CHANNEL_INCOGNITO_MODE, IMPORTANCE_LOW) {
setName(context.getString(R.string.pref_incognito_mode)) 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)) setName(context.getString(R.string.channel_ext_updates))
}, },
) )
) )
// Delete old notification channels
deprecatedChannels.forEach(notificationService::deleteNotificationChannel)
} }
} }

View File

@ -15,14 +15,14 @@ import eu.kanade.tachiyomi.util.system.notificationManager
internal class AppUpdateNotifier(private val context: Context) { 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. * Call to show notification.
* *
* @param id id of the notification channel. * @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()) context.notificationManager.notify(id, build())
} }
@ -109,7 +109,7 @@ internal class AppUpdateNotifier(private val context: Context) {
addAction( addAction(
R.drawable.ic_close_24dp, R.drawable.ic_close_24dp,
context.getString(R.string.action_cancel), context.getString(R.string.action_cancel),
NotificationReceiver.dismissNotificationPendingBroadcast(context, Notifications.ID_UPDATER) NotificationReceiver.dismissNotificationPendingBroadcast(context, Notifications.ID_APP_UPDATER)
) )
} }
notificationBuilder.show() notificationBuilder.show()
@ -136,9 +136,9 @@ internal class AppUpdateNotifier(private val context: Context) {
addAction( addAction(
R.drawable.ic_close_24dp, R.drawable.ic_close_24dp,
context.getString(R.string.action_cancel), 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)
} }
} }

View File

@ -42,7 +42,7 @@ class AppUpdateService : Service() {
notifier = AppUpdateNotifier(this) notifier = AppUpdateNotifier(this)
wakeLock = acquireWakeLock(javaClass.name) wakeLock = acquireWakeLock(javaClass.name)
startForeground(Notifications.ID_UPDATER, notifier.onDownloadStarted().build()) startForeground(Notifications.ID_APP_UPDATER, notifier.onDownloadStarted().build())
} }
/** /**

View File

@ -42,7 +42,7 @@ class ExtensionUpdateJob(private val context: Context, workerParams: WorkerParam
NotificationManagerCompat.from(context).apply { NotificationManagerCompat.from(context).apply {
notify( notify(
Notifications.ID_UPDATES_TO_EXTS, Notifications.ID_UPDATES_TO_EXTS,
context.notification(Notifications.CHANNEL_UPDATES_TO_EXTS) { context.notification(Notifications.CHANNEL_EXTENSIONS_UPDATE) {
setContentTitle( setContentTitle(
context.resources.getQuantityString( context.resources.getQuantityString(
R.plurals.update_check_notification_ext_updates, R.plurals.update_check_notification_ext_updates,

View File

@ -22,7 +22,7 @@ class ExtensionInstallService : Service() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
val notification = notificationBuilder(Notifications.CHANNEL_DOWNLOADER_PROGRESS) { val notification = notificationBuilder(Notifications.CHANNEL_EXTENSIONS_UPDATE) {
setSmallIcon(R.drawable.ic_tachi) setSmallIcon(R.drawable.ic_tachi)
setAutoCancel(false) setAutoCancel(false)
setOngoing(true) setOngoing(true)

View File

@ -789,6 +789,7 @@
<string name="channel_complete">Complete</string> <string name="channel_complete">Complete</string>
<string name="channel_errors">Errors</string> <string name="channel_errors">Errors</string>
<string name="channel_new_chapters">Chapter updates</string> <string name="channel_new_chapters">Chapter updates</string>
<string name="channel_app_updates">App updates</string>
<string name="channel_ext_updates">Extension updates</string> <string name="channel_ext_updates">Extension updates</string>
<string name="channel_crash_logs">Crash logs</string> <string name="channel_crash_logs">Crash logs</string>