Separating Backup/Restore Progress/Complete

This commit is contained in:
Jays2Kings 2021-03-26 16:42:07 -04:00
parent 4af4b9fb9d
commit 110807bd49
3 changed files with 25 additions and 6 deletions

View File

@ -19,14 +19,14 @@ class BackupNotifier(private val context: Context) {
private val preferences: PreferencesHelper by injectLazy()
private val progressNotificationBuilder = context.notificationBuilder(Notifications.CHANNEL_BACKUP_RESTORE) {
private val progressNotificationBuilder = context.notificationBuilder(Notifications.CHANNEL_BACKUP_RESTORE_PROGRESS) {
setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher))
setSmallIcon(R.drawable.ic_tachi)
setAutoCancel(false)
setOngoing(true)
}
private val completeNotificationBuilder = context.notificationBuilder(Notifications.CHANNEL_BACKUP_RESTORE) {
private val completeNotificationBuilder = context.notificationBuilder(Notifications.CHANNEL_BACKUP_RESTORE_COMPLETE) {
setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher))
setSmallIcon(R.drawable.ic_tachi)
setAutoCancel(false)

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.data.notification
import android.app.NotificationChannel
import android.app.NotificationChannelGroup
import android.app.NotificationManager
import android.content.Context
import android.os.Build
@ -46,12 +47,13 @@ object Notifications {
const val CHANNEL_UPDATES_TO_EXTS = "updates_ext_channel"
const val ID_UPDATES_TO_EXTS = -401
const val CHANNEL_BACKUP_RESTORE = "backup_restore_channel"
private const val GROUP_BACKUP_RESTORE = "group_backup_restore"
const val CHANNEL_BACKUP_RESTORE_PROGRESS = "backup_restore_progress_channel"
const val ID_RESTORE_PROGRESS = -501
const val ID_RESTORE_COMPLETE = -502
const val CHANNEL_BACKUP_RESTORE_COMPLETE = "backup_restore_complete_channel_v2"
const val ID_BACKUP_PROGRESS = -502
const val ID_BACKUP_COMPLETE = -503
const val ID_RESTORE_ERROR = -504
/**
* Creates the notification channels introduced in Android Oreo.
@ -61,6 +63,10 @@ object Notifications {
fun createChannels(context: Context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
listOf(
NotificationChannelGroup(GROUP_BACKUP_RESTORE, context.getString(R.string.backup_and_restore)),
).forEach(context.notificationManager::createNotificationChannelGroup)
val channels = listOf(
NotificationChannel(
CHANNEL_COMMON,
@ -92,11 +98,21 @@ object Notifications {
NotificationManager.IMPORTANCE_DEFAULT
),
NotificationChannel(
CHANNEL_BACKUP_RESTORE,
context.getString(R.string.restoring_backup),
CHANNEL_BACKUP_RESTORE_PROGRESS,
context.getString(R.string.progress),
NotificationManager.IMPORTANCE_LOW
).apply {
group = GROUP_BACKUP_RESTORE
setShowBadge(false)
},
NotificationChannel(
CHANNEL_BACKUP_RESTORE_COMPLETE,
context.getString(R.string.complete),
NotificationManager.IMPORTANCE_HIGH
).apply {
group = GROUP_BACKUP_RESTORE
setShowBadge(false)
setSound(null, null)
}
)
context.notificationManager.createNotificationChannels(channels)

View File

@ -547,6 +547,7 @@
<!-- Backup -->
<string name="backup">Backup</string>
<string name="backup_and_restore">Backup and restore</string>
<string name="create_backup">Create backup</string>
<string name="can_be_used_to_restore">Can be used to restore current library</string>
<string name="create_legacy_backup">Create legacy backup</string>
@ -581,6 +582,8 @@
<string name="restoring_backup">Restoring backup</string>
<string name="restoring_progress">Restoring (%1$d/%2$d)</string>
<string name="restore_duration">%02d min, %02d sec</string>
<string name="progress">Progress</string>
<string name="complete">Complete</string>
<plurals name="restore_completed_message">
<item quantity="one">Done in %1$s with %2$s error</item>
<item quantity="other">Done in %1$s with %2$s errors</item>