Don't show rejected packages (usually 0 size) as failed

Also change notification ID to not collide with Nextcloud's ID.
This commit is contained in:
Torsten Grote 2019-08-05 11:07:55 +02:00
parent e2a3e3d2b7
commit 2685f2b48a
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
2 changed files with 8 additions and 5 deletions

View file

@ -4,6 +4,7 @@ import android.app.NotificationChannel
import android.app.NotificationManager import android.app.NotificationManager
import android.app.NotificationManager.IMPORTANCE_LOW import android.app.NotificationManager.IMPORTANCE_LOW
import android.app.backup.BackupProgress import android.app.backup.BackupProgress
import android.app.backup.BackupTransport.TRANSPORT_PACKAGE_REJECTED
import android.app.backup.IBackupObserver import android.app.backup.IBackupObserver
import android.content.Context import android.content.Context
import android.util.Log import android.util.Log
@ -14,7 +15,7 @@ import androidx.core.app.NotificationCompat.PRIORITY_DEFAULT
import androidx.core.app.NotificationCompat.PRIORITY_LOW import androidx.core.app.NotificationCompat.PRIORITY_LOW
private const val CHANNEL_ID = "NotificationBackupObserver" private const val CHANNEL_ID = "NotificationBackupObserver"
private const val NOTIFICATION_ID = 1 private const val NOTIFICATION_ID = 1042
private val TAG = NotificationBackupObserver::class.java.simpleName private val TAG = NotificationBackupObserver::class.java.simpleName
@ -70,10 +71,11 @@ class NotificationBackupObserver(
if (isLoggable(TAG, INFO)) { if (isLoggable(TAG, INFO)) {
Log.i(TAG, "Completed. Target: $target, status: $status") Log.i(TAG, "Completed. Target: $target, status: $status")
} }
val title = context.getString( val title = context.getString(when (status) {
if (status == 0) R.string.notification_backup_result_complete 0 -> R.string.notification_backup_result_complete
else R.string.notification_backup_result_error TRANSPORT_PACKAGE_REJECTED -> R.string.notification_backup_result_rejected
) else -> R.string.notification_backup_result_error
})
val notification = notificationBuilder.apply { val notification = notificationBuilder.apply {
setContentTitle(title) setContentTitle(title)
setContentText(getAppName(target)) setContentText(getAppName(target))

View file

@ -62,6 +62,7 @@
<string name="notification_channel_title">Backup Notification</string> <string name="notification_channel_title">Backup Notification</string>
<string name="notification_title">Backup running</string> <string name="notification_title">Backup running</string>
<string name="notification_backup_result_complete">Backup complete</string> <string name="notification_backup_result_complete">Backup complete</string>
<string name="notification_backup_result_rejected">Not backed up</string>
<string name="notification_backup_result_error">Backup failed</string> <string name="notification_backup_result_error">Backup failed</string>
</resources> </resources>