mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-23 05:35:51 +03:00
Move app and extension update notifications to new channels/group (closes #6168)
This commit is contained in:
parent
da5942b398
commit
0edc981cd2
6 changed files with 33 additions and 20 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -789,6 +789,7 @@
|
|||
<string name="channel_complete">Complete</string>
|
||||
<string name="channel_errors">Errors</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_crash_logs">Crash logs</string>
|
||||
|
||||
|
|
Loading…
Reference in a new issue