mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 19:27:25 +01:00
Split out backup/restore notifications into separate channels for progress/completion
This commit is contained in:
parent
02502c4ea5
commit
2661700d9a
@ -19,7 +19,14 @@ internal class BackupNotifier(private val context: Context) {
|
|||||||
|
|
||||||
private val preferences: PreferencesHelper by injectLazy()
|
private val preferences: PreferencesHelper by injectLazy()
|
||||||
|
|
||||||
private val notificationBuilder = 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_COMPLETE) {
|
||||||
setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher))
|
setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher))
|
||||||
setSmallIcon(R.drawable.ic_tachi)
|
setSmallIcon(R.drawable.ic_tachi)
|
||||||
setAutoCancel(false)
|
setAutoCancel(false)
|
||||||
@ -30,11 +37,10 @@ internal class BackupNotifier(private val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun showBackupProgress(): NotificationCompat.Builder {
|
fun showBackupProgress(): NotificationCompat.Builder {
|
||||||
val builder = with(notificationBuilder) {
|
val builder = with(progressNotificationBuilder) {
|
||||||
setContentTitle(context.getString(R.string.creating_backup))
|
setContentTitle(context.getString(R.string.creating_backup))
|
||||||
|
|
||||||
setProgress(0, 0, true)
|
setProgress(0, 0, true)
|
||||||
setOngoing(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.show(Notifications.ID_BACKUP_PROGRESS)
|
builder.show(Notifications.ID_BACKUP_PROGRESS)
|
||||||
@ -45,32 +51,24 @@ internal class BackupNotifier(private val context: Context) {
|
|||||||
fun showBackupError(error: String?) {
|
fun showBackupError(error: String?) {
|
||||||
context.notificationManager.cancel(Notifications.ID_BACKUP_PROGRESS)
|
context.notificationManager.cancel(Notifications.ID_BACKUP_PROGRESS)
|
||||||
|
|
||||||
with(notificationBuilder) {
|
with(completeNotificationBuilder) {
|
||||||
setContentTitle(context.getString(R.string.creating_backup_error))
|
setContentTitle(context.getString(R.string.creating_backup_error))
|
||||||
setContentText(error)
|
setContentText(error)
|
||||||
|
|
||||||
// Remove progress bar
|
show(Notifications.ID_BACKUP_COMPLETE)
|
||||||
setProgress(0, 0, false)
|
|
||||||
setOngoing(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationBuilder.show(Notifications.ID_BACKUP_COMPLETE)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showBackupComplete(unifile: UniFile) {
|
fun showBackupComplete(unifile: UniFile) {
|
||||||
context.notificationManager.cancel(Notifications.ID_BACKUP_PROGRESS)
|
context.notificationManager.cancel(Notifications.ID_BACKUP_PROGRESS)
|
||||||
|
|
||||||
with(notificationBuilder) {
|
with(completeNotificationBuilder) {
|
||||||
setContentTitle(context.getString(R.string.backup_created))
|
setContentTitle(context.getString(R.string.backup_created))
|
||||||
|
|
||||||
if (unifile.filePath != null) {
|
if (unifile.filePath != null) {
|
||||||
setContentText(unifile.filePath)
|
setContentText(unifile.filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove progress bar
|
|
||||||
setProgress(0, 0, false)
|
|
||||||
setOngoing(false)
|
|
||||||
|
|
||||||
// Clear old actions if they exist
|
// Clear old actions if they exist
|
||||||
if (mActions.isNotEmpty()) {
|
if (mActions.isNotEmpty()) {
|
||||||
mActions.clear()
|
mActions.clear()
|
||||||
@ -81,13 +79,13 @@ internal class BackupNotifier(private val context: Context) {
|
|||||||
context.getString(R.string.action_share),
|
context.getString(R.string.action_share),
|
||||||
NotificationReceiver.shareBackupPendingBroadcast(context, unifile.uri, Notifications.ID_BACKUP_COMPLETE)
|
NotificationReceiver.shareBackupPendingBroadcast(context, unifile.uri, Notifications.ID_BACKUP_COMPLETE)
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
notificationBuilder.show(Notifications.ID_BACKUP_COMPLETE)
|
show(Notifications.ID_BACKUP_COMPLETE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showRestoreProgress(content: String = "", progress: Int = 0, maxAmount: Int = 100): NotificationCompat.Builder {
|
fun showRestoreProgress(content: String = "", progress: Int = 0, maxAmount: Int = 100): NotificationCompat.Builder {
|
||||||
val builder = with(notificationBuilder) {
|
val builder = with(progressNotificationBuilder) {
|
||||||
setContentTitle(context.getString(R.string.restoring_backup))
|
setContentTitle(context.getString(R.string.restoring_backup))
|
||||||
|
|
||||||
if (!preferences.hideNotificationContent()) {
|
if (!preferences.hideNotificationContent()) {
|
||||||
@ -95,7 +93,6 @@ internal class BackupNotifier(private val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setProgress(maxAmount, progress, false)
|
setProgress(maxAmount, progress, false)
|
||||||
setOngoing(true)
|
|
||||||
|
|
||||||
// Clear old actions if they exist
|
// Clear old actions if they exist
|
||||||
if (mActions.isNotEmpty()) {
|
if (mActions.isNotEmpty()) {
|
||||||
@ -117,16 +114,12 @@ internal class BackupNotifier(private val context: Context) {
|
|||||||
fun showRestoreError(error: String?) {
|
fun showRestoreError(error: String?) {
|
||||||
context.notificationManager.cancel(Notifications.ID_RESTORE_PROGRESS)
|
context.notificationManager.cancel(Notifications.ID_RESTORE_PROGRESS)
|
||||||
|
|
||||||
with(notificationBuilder) {
|
with(completeNotificationBuilder) {
|
||||||
setContentTitle(context.getString(R.string.restoring_backup_error))
|
setContentTitle(context.getString(R.string.restoring_backup_error))
|
||||||
setContentText(error)
|
setContentText(error)
|
||||||
|
|
||||||
// Remove progress bar
|
show(Notifications.ID_RESTORE_COMPLETE)
|
||||||
setProgress(0, 0, false)
|
|
||||||
setOngoing(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationBuilder.show(Notifications.ID_RESTORE_COMPLETE)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showRestoreComplete(time: Long, errorCount: Int, path: String?, file: String?) {
|
fun showRestoreComplete(time: Long, errorCount: Int, path: String?, file: String?) {
|
||||||
@ -140,17 +133,10 @@ internal class BackupNotifier(private val context: Context) {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
with(notificationBuilder) {
|
with(completeNotificationBuilder) {
|
||||||
setSmallIcon(R.drawable.ic_tachi)
|
|
||||||
setAutoCancel(false)
|
|
||||||
|
|
||||||
setContentTitle(context.getString(R.string.restore_completed))
|
setContentTitle(context.getString(R.string.restore_completed))
|
||||||
setContentText(context.getString(R.string.restore_completed_content, timeString, errorCount))
|
setContentText(context.getString(R.string.restore_completed_content, timeString, errorCount))
|
||||||
|
|
||||||
// Remove progress bar
|
|
||||||
setProgress(0, 0, false)
|
|
||||||
setOngoing(false)
|
|
||||||
|
|
||||||
// Clear old actions if they exist
|
// Clear old actions if they exist
|
||||||
if (mActions.isNotEmpty()) {
|
if (mActions.isNotEmpty()) {
|
||||||
mActions.clear()
|
mActions.clear()
|
||||||
@ -166,8 +152,8 @@ internal class BackupNotifier(private val context: Context) {
|
|||||||
NotificationReceiver.openErrorLogPendingActivity(context, uri)
|
NotificationReceiver.openErrorLogPendingActivity(context, uri)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
notificationBuilder.show(Notifications.ID_RESTORE_COMPLETE)
|
show(Notifications.ID_RESTORE_COMPLETE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package eu.kanade.tachiyomi.data.notification
|
package eu.kanade.tachiyomi.data.notification
|
||||||
|
|
||||||
import android.app.NotificationChannel
|
import android.app.NotificationChannel
|
||||||
|
import android.app.NotificationChannelGroup
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
@ -48,10 +49,12 @@ object Notifications {
|
|||||||
/**
|
/**
|
||||||
* Notification channel and ids used by the backup/restore system.
|
* Notification channel and ids used by the backup/restore system.
|
||||||
*/
|
*/
|
||||||
const val CHANNEL_BACKUP_RESTORE = "backup_restore_channel"
|
private const val GROUP_BACK_RESTORE = "group_backup_restore"
|
||||||
|
const val CHANNEL_BACKUP_RESTORE_PROGRESS = "backup_restore_progress_channel"
|
||||||
const val ID_BACKUP_PROGRESS = -501
|
const val ID_BACKUP_PROGRESS = -501
|
||||||
const val ID_BACKUP_COMPLETE = -502
|
|
||||||
const val ID_RESTORE_PROGRESS = -503
|
const val ID_RESTORE_PROGRESS = -503
|
||||||
|
const val CHANNEL_BACKUP_RESTORE_COMPLETE = "backup_restore_complete_channel"
|
||||||
|
const val ID_BACKUP_COMPLETE = -502
|
||||||
const val ID_RESTORE_COMPLETE = -504
|
const val ID_RESTORE_COMPLETE = -504
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,6 +65,9 @@ object Notifications {
|
|||||||
fun createChannels(context: Context) {
|
fun createChannels(context: Context) {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
|
||||||
|
|
||||||
|
val backupRestoreGroup = NotificationChannelGroup(GROUP_BACK_RESTORE, context.getString(R.string.channel_backup_restore))
|
||||||
|
context.notificationManager.createNotificationChannelGroup(backupRestoreGroup)
|
||||||
|
|
||||||
val channels = listOf(
|
val channels = listOf(
|
||||||
NotificationChannel(
|
NotificationChannel(
|
||||||
CHANNEL_COMMON, context.getString(R.string.channel_common),
|
CHANNEL_COMMON, context.getString(R.string.channel_common),
|
||||||
@ -88,9 +94,17 @@ object Notifications {
|
|||||||
NotificationManager.IMPORTANCE_DEFAULT
|
NotificationManager.IMPORTANCE_DEFAULT
|
||||||
),
|
),
|
||||||
NotificationChannel(
|
NotificationChannel(
|
||||||
CHANNEL_BACKUP_RESTORE, context.getString(R.string.channel_backup_restore),
|
CHANNEL_BACKUP_RESTORE_PROGRESS, context.getString(R.string.channel_backup_restore_progress),
|
||||||
|
NotificationManager.IMPORTANCE_DEFAULT
|
||||||
|
).apply {
|
||||||
|
group = GROUP_BACK_RESTORE
|
||||||
|
setShowBadge(false)
|
||||||
|
},
|
||||||
|
NotificationChannel(
|
||||||
|
CHANNEL_BACKUP_RESTORE_COMPLETE, context.getString(R.string.channel_backup_restore_complete),
|
||||||
NotificationManager.IMPORTANCE_HIGH
|
NotificationManager.IMPORTANCE_HIGH
|
||||||
).apply {
|
).apply {
|
||||||
|
group = GROUP_BACK_RESTORE
|
||||||
setShowBadge(false)
|
setShowBadge(false)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -630,5 +630,7 @@
|
|||||||
<string name="channel_new_chapters">Chapter updates</string>
|
<string name="channel_new_chapters">Chapter updates</string>
|
||||||
<string name="channel_ext_updates">Extension updates</string>
|
<string name="channel_ext_updates">Extension updates</string>
|
||||||
<string name="channel_backup_restore">Backup and restore</string>
|
<string name="channel_backup_restore">Backup and restore</string>
|
||||||
|
<string name="channel_backup_restore_progress">Progress</string>
|
||||||
|
<string name="channel_backup_restore_complete">Complete</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user