|
@@ -59,7 +59,6 @@ import com.owncloud.android.utils.ErrorMessageAdapter
|
|
|
import com.owncloud.android.utils.FilesUploadHelper
|
|
|
import com.owncloud.android.utils.theme.ViewThemeUtils
|
|
|
import java.io.File
|
|
|
-import java.security.SecureRandom
|
|
|
|
|
|
@Suppress("LongParameterList")
|
|
|
class FilesUploadWorker(
|
|
@@ -261,8 +260,14 @@ class FilesUploadWorker(
|
|
|
uploadResult: RemoteOperationResult<Any?>
|
|
|
) {
|
|
|
Log_OC.d(TAG, "NotifyUploadResult with resultCode: " + uploadResult.code)
|
|
|
+
|
|
|
+ if (uploadResult.isSuccess){
|
|
|
+ cancelOldErrorNotification(uploadFileOperation)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
// Only notify if the upload fails
|
|
|
- if (uploadResult.isSuccess || uploadResult.isCancelled) {
|
|
|
+ if (uploadResult.isCancelled) {
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -312,9 +317,10 @@ class FilesUploadWorker(
|
|
|
)
|
|
|
}
|
|
|
notificationBuilder.setContentText(content)
|
|
|
- if (!uploadResult.isSuccess) {
|
|
|
- notificationManager.notify(SecureRandom().nextInt(), notificationBuilder.build())
|
|
|
- }
|
|
|
+
|
|
|
+ notificationManager.notify(NotificationUtils.createUploadNotificationTag(uploadFileOperation.file),
|
|
|
+ NOTIFICATION_ERROR_ID, notificationBuilder.build())
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -386,10 +392,18 @@ class FilesUploadWorker(
|
|
|
totalToTransfer,
|
|
|
fileAbsoluteName
|
|
|
)
|
|
|
+ currentUploadFileOperation?.let { cancelOldErrorNotification(it) }
|
|
|
}
|
|
|
lastPercent = percent
|
|
|
}
|
|
|
|
|
|
+ private fun cancelOldErrorNotification(uploadFileOperation: UploadFileOperation){
|
|
|
+ notificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.oldFile),
|
|
|
+ NOTIFICATION_ERROR_ID)
|
|
|
+ notificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.file),
|
|
|
+ NOTIFICATION_ERROR_ID)
|
|
|
+ }
|
|
|
+
|
|
|
override fun onStopped() {
|
|
|
super.onStopped()
|
|
|
currentUploadFileOperation?.cancel(null)
|
|
@@ -399,6 +413,7 @@ class FilesUploadWorker(
|
|
|
companion object {
|
|
|
val TAG: String = FilesUploadWorker::class.java.simpleName
|
|
|
private const val FOREGROUND_SERVICE_ID: Int = 412
|
|
|
+ private const val NOTIFICATION_ERROR_ID: Int = 413
|
|
|
private const val MAX_PROGRESS: Int = 100
|
|
|
const val ACCOUNT = "data_account"
|
|
|
var currentUploadFileOperation: UploadFileOperation? = null
|