feat(notification): Add separate channel for sync notifications (#928)
* Add separate channel for sync notifications (cherry picked from commit 2ef674cf5481272a80719b57d19e95b0bd0395f9) * fix `showSyncError` notification channel * Remove duplicate notification cancellation --------- Co-authored-by: Jery <jery99961@gmail.com>
This commit is contained in:
parent
303a266720
commit
46c3f1ef2f
3 changed files with 18 additions and 12 deletions
|
|
@ -51,7 +51,7 @@ object Notifications {
|
|||
const val GROUP_NEW_CHAPTERS = "eu.kanade.tachiyomi.NEW_CHAPTERS"
|
||||
|
||||
/**
|
||||
* Notification channel and ids used by the backup/restore system.
|
||||
* Notification channel and ids used by the backup/restore/sync system.
|
||||
*/
|
||||
private const val GROUP_BACKUP_RESTORE = "group_backup_restore"
|
||||
const val CHANNEL_BACKUP_RESTORE_PROGRESS = "backup_restore_progress_channel"
|
||||
|
|
@ -60,6 +60,9 @@ object Notifications {
|
|||
const val CHANNEL_BACKUP_RESTORE_COMPLETE = "backup_restore_complete_channel_v2"
|
||||
const val ID_BACKUP_COMPLETE = -502
|
||||
const val ID_RESTORE_COMPLETE = -504
|
||||
const val CHANNEL_SYNC_LIBRARY = "syncing_library_channel"
|
||||
const val ID_SYNC_PROGRESS = -505
|
||||
const val ID_SYNC_COMPLETE = -506
|
||||
|
||||
/**
|
||||
* Notification channel used for Incognito Mode
|
||||
|
|
@ -165,6 +168,11 @@ object Notifications {
|
|||
setShowBadge(false)
|
||||
setSound(null, null)
|
||||
},
|
||||
buildNotificationChannel(CHANNEL_SYNC_LIBRARY, IMPORTANCE_LOW) {
|
||||
setName(context.stringResource(MR.strings.syncing_library))
|
||||
setGroup(GROUP_BACKUP_RESTORE)
|
||||
setShowBadge(false)
|
||||
},
|
||||
buildNotificationChannel(CHANNEL_INCOGNITO_MODE, IMPORTANCE_LOW) {
|
||||
setName(context.stringResource(MR.strings.pref_incognito_mode))
|
||||
},
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import androidx.work.WorkerParameters
|
|||
import eu.kanade.domain.sync.SyncPreferences
|
||||
import eu.kanade.tachiyomi.data.SyncStatus
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.util.system.cancelNotification
|
||||
import eu.kanade.tachiyomi.util.system.isOnline
|
||||
import eu.kanade.tachiyomi.util.system.isRunning
|
||||
import eu.kanade.tachiyomi.util.system.setForegroundSafely
|
||||
|
|
@ -61,7 +60,6 @@ class SyncDataJob(private val context: Context, workerParams: WorkerParameters)
|
|||
notifier.showSyncError(e.message)
|
||||
Result.success() // try again next time
|
||||
} finally {
|
||||
context.cancelNotification(Notifications.ID_RESTORE_PROGRESS)
|
||||
// KMK -->
|
||||
syncStatus.stop()
|
||||
// KMK <--
|
||||
|
|
@ -70,7 +68,7 @@ class SyncDataJob(private val context: Context, workerParams: WorkerParameters)
|
|||
|
||||
override suspend fun getForegroundInfo(): ForegroundInfo {
|
||||
return ForegroundInfo(
|
||||
Notifications.ID_RESTORE_PROGRESS,
|
||||
Notifications.ID_SYNC_PROGRESS,
|
||||
notifier.showSyncProgress().build(),
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class SyncNotifier(private val context: Context) {
|
|||
// KMK <--
|
||||
|
||||
private val progressNotificationBuilder = context.notificationBuilder(
|
||||
Notifications.CHANNEL_BACKUP_RESTORE_PROGRESS,
|
||||
Notifications.CHANNEL_SYNC_LIBRARY,
|
||||
) {
|
||||
setSmallIcon(R.drawable.ic_komikku)
|
||||
setColor(ContextCompat.getColor(context, R.color.ic_launcher))
|
||||
|
|
@ -36,7 +36,7 @@ class SyncNotifier(private val context: Context) {
|
|||
}
|
||||
|
||||
private val completeNotificationBuilder = context.notificationBuilder(
|
||||
Notifications.CHANNEL_BACKUP_RESTORE_COMPLETE,
|
||||
Notifications.CHANNEL_SYNC_LIBRARY,
|
||||
) {
|
||||
setSmallIcon(R.drawable.ic_komikku)
|
||||
setColor(ContextCompat.getColor(context, R.color.ic_launcher))
|
||||
|
|
@ -70,34 +70,34 @@ class SyncNotifier(private val context: Context) {
|
|||
addAction(
|
||||
R.drawable.ic_close_24dp,
|
||||
context.getString(R.string.action_cancel),
|
||||
NotificationReceiver.cancelSyncPendingBroadcast(context, Notifications.ID_RESTORE_PROGRESS),
|
||||
NotificationReceiver.cancelSyncPendingBroadcast(context, Notifications.ID_SYNC_PROGRESS),
|
||||
)
|
||||
}
|
||||
|
||||
builder.show(Notifications.ID_RESTORE_PROGRESS)
|
||||
builder.show(Notifications.ID_SYNC_PROGRESS)
|
||||
|
||||
return builder
|
||||
}
|
||||
|
||||
fun showSyncError(error: String?) {
|
||||
context.cancelNotification(Notifications.ID_RESTORE_PROGRESS)
|
||||
context.cancelNotification(Notifications.ID_SYNC_PROGRESS)
|
||||
|
||||
with(completeNotificationBuilder) {
|
||||
setContentTitle(context.getString(R.string.sync_error))
|
||||
setContentText(error)
|
||||
|
||||
show(Notifications.ID_RESTORE_COMPLETE)
|
||||
show(Notifications.ID_SYNC_COMPLETE)
|
||||
}
|
||||
}
|
||||
|
||||
fun showSyncSuccess(message: String?) {
|
||||
context.cancelNotification(Notifications.ID_RESTORE_PROGRESS)
|
||||
context.cancelNotification(Notifications.ID_SYNC_PROGRESS)
|
||||
|
||||
with(completeNotificationBuilder) {
|
||||
setContentTitle(context.getString(R.string.sync_complete))
|
||||
setContentText(message)
|
||||
|
||||
show(Notifications.ID_RESTORE_COMPLETE)
|
||||
show(Notifications.ID_SYNC_COMPLETE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue