From 00cbbb1a19efa97dbbbf2bb91ee453d809499aa1 Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Tue, 28 Nov 2023 13:15:49 +0100 Subject: [PATCH 1/7] make failed notification go away when uploading makes progress Signed-off-by: Jonas Mayer --- .../client/jobs/FilesUploadWorker.kt | 25 +++++++++++++++---- .../android/files/services/FileUploader.java | 14 +++++++++++ .../ui/notifications/NotificationUtils.java | 5 ++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt index 7ef2f53955b0..ee1e9f0cfd5d 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt @@ -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 ) { 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 diff --git a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java index 59244f331158..2c3be13b7854 100644 --- a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java +++ b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java @@ -135,6 +135,7 @@ public class FileUploader extends Service public static final String ACTION_PAUSE_BROADCAST = "PAUSE"; private static final int FOREGROUND_SERVICE_ID = 411; + private static final int NOTIFICATION_ERROR_ID = 410; public static final String KEY_FILE = "FILE"; public static final String KEY_LOCAL_FILE = "LOCAL_FILE"; @@ -781,6 +782,7 @@ public void onTransferProgress( mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); } mNotificationManager.notify(FOREGROUND_SERVICE_ID, mNotificationBuilder.build()); + cancelOldErrorNotification(mCurrentUpload); } mLastPercent = percent; } @@ -799,6 +801,10 @@ private void notifyUploadResult(UploadFileOperation upload, RemoteOperationResul mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); } + if (uploadResult.isSuccess()){ + cancelOldErrorNotification(upload); + } + // Only notify if the upload fails if (!uploadResult.isCancelled() && !uploadResult.isSuccess() && @@ -1436,6 +1442,14 @@ public static String buildRemoteName(String accountName, String remotePath) { } } + private void cancelOldErrorNotification(UploadFileOperation uploadFileOperation){ + if (uploadFileOperation == null) return; + mNotificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.getOldFile()), + NOTIFICATION_ERROR_ID); + mNotificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.getFile()), + NOTIFICATION_ERROR_ID); + } + /** * Upload worker. Performs the pending uploads in the order they were requested. diff --git a/app/src/main/java/com/owncloud/android/ui/notifications/NotificationUtils.java b/app/src/main/java/com/owncloud/android/ui/notifications/NotificationUtils.java index 6c70dc45c91a..d46871ae323d 100644 --- a/app/src/main/java/com/owncloud/android/ui/notifications/NotificationUtils.java +++ b/app/src/main/java/com/owncloud/android/ui/notifications/NotificationUtils.java @@ -25,6 +25,7 @@ import android.os.HandlerThread; import android.os.Process; +import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.utils.theme.ViewThemeUtils; import java.security.SecureRandom; @@ -81,4 +82,8 @@ public static void cancelWithDelay(final NotificationManager notificationManager ((HandlerThread) Thread.currentThread()).getLooper().quit(); }, delayInMillis); } + + public static String createUploadNotificationTag(OCFile file){ + return file.getRemotePath() + file.getStoragePath(); + } } From ba51d7c930ea14fc95ef5378b9e918dd0341fb39 Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Tue, 28 Nov 2023 15:58:23 +0100 Subject: [PATCH 2/7] remove Notification when upload is removed in UploadListActivity Signed-off-by: Jonas Mayer --- .../nextcloud/client/jobs/FilesUploadWorker.kt | 2 +- .../android/files/services/FileUploader.java | 6 +++++- .../ui/activity/UploadListActivity.java | 4 ++++ .../android/ui/adapter/UploadListAdapter.java | 18 ++++++++++++++++++ .../ui/notifications/NotificationUtils.java | 5 ++++- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt index ee1e9f0cfd5d..5b909183612b 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt @@ -413,7 +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 + const val NOTIFICATION_ERROR_ID: Int = 413 private const val MAX_PROGRESS: Int = 100 const val ACCOUNT = "data_account" var currentUploadFileOperation: UploadFileOperation? = null diff --git a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java index 2c3be13b7854..b3d50ca48067 100644 --- a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java +++ b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java @@ -135,7 +135,7 @@ public class FileUploader extends Service public static final String ACTION_PAUSE_BROADCAST = "PAUSE"; private static final int FOREGROUND_SERVICE_ID = 411; - private static final int NOTIFICATION_ERROR_ID = 410; + private static final int NOTIFICATION_ERROR_ID = FilesUploadWorker.NOTIFICATION_ERROR_ID; public static final String KEY_FILE = "FILE"; public static final String KEY_LOCAL_FILE = "LOCAL_FILE"; @@ -1443,6 +1443,10 @@ public static String buildRemoteName(String accountName, String remotePath) { } private void cancelOldErrorNotification(UploadFileOperation uploadFileOperation){ + if (mNotificationManager == null) { + mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + } + if (uploadFileOperation == null) return; mNotificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.getOldFile()), NOTIFICATION_ERROR_ID); diff --git a/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java index 52b8b0fb803b..fd9e824c8cf8 100755 --- a/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java @@ -48,6 +48,7 @@ import com.owncloud.android.databinding.UploadListLayoutBinding; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.UploadsStorageManager; +import com.owncloud.android.db.OCUpload; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.lib.common.operations.RemoteOperation; @@ -263,6 +264,9 @@ public boolean onOptionsItemSelected(MenuItem item) { openDrawer(); } } else if (itemId == R.id.action_clear_failed_uploads) { + for (OCUpload upload : uploadsStorageManager.getFailedButNotDelayedUploadsForCurrentAccount()){ + uploadListAdapter.cancelOldErrorNotification(upload); + } uploadsStorageManager.clearFailedButNotDelayedUploads(); uploadListAdapter.loadUploadItemsFromDb(); } else { diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java index 9d0f1b74ce20..75b2df413821 100755 --- a/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java @@ -24,6 +24,7 @@ package com.owncloud.android.ui.adapter; +import android.app.NotificationManager; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; @@ -42,6 +43,7 @@ import com.nextcloud.client.account.UserAccountManager; import com.nextcloud.client.core.Clock; import com.nextcloud.client.device.PowerManagementService; +import com.nextcloud.client.jobs.FilesUploadWorker; import com.nextcloud.client.network.ConnectivityService; import com.nextcloud.java.util.Optional; import com.owncloud.android.MainApp; @@ -63,6 +65,7 @@ import com.owncloud.android.ui.activity.ConflictsResolveActivity; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; +import com.owncloud.android.ui.notifications.NotificationUtils; import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.MimeTypeUtil; @@ -86,6 +89,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter Date: Wed, 6 Dec 2023 16:41:02 +0100 Subject: [PATCH 3/7] rebase with new master Signed-off-by: Jonas Mayer --- .../main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt | 2 ++ .../java/com/owncloud/android/files/services/FileUploader.java | 1 + 2 files changed, 3 insertions(+) diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt index 5b909183612b..2a50c79cf2c1 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt @@ -59,6 +59,7 @@ 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( @@ -398,6 +399,7 @@ class FilesUploadWorker( } private fun cancelOldErrorNotification(uploadFileOperation: UploadFileOperation){ + //cancel for old file because of file conflicts notificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.oldFile), NOTIFICATION_ERROR_ID) notificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.file), diff --git a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java index b3d50ca48067..526a4050be6a 100644 --- a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java +++ b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java @@ -1448,6 +1448,7 @@ private void cancelOldErrorNotification(UploadFileOperation uploadFileOperation) } if (uploadFileOperation == null) return; + //cancel for old file because of file conflicts mNotificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.getOldFile()), NOTIFICATION_ERROR_ID); mNotificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.getFile()), From ba3431851c4d3c7c17f5a8fd72d5c4e459acb0bd Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Wed, 6 Dec 2023 21:28:59 +0100 Subject: [PATCH 4/7] fix spotlessCheck for Kotlin Signed-off-by: Jonas Mayer --- .../client/jobs/FilesUploadWorker.kt | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt index 2a50c79cf2c1..95354ec5fd0c 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt @@ -262,7 +262,7 @@ class FilesUploadWorker( ) { Log_OC.d(TAG, "NotifyUploadResult with resultCode: " + uploadResult.code) - if (uploadResult.isSuccess){ + if (uploadResult.isSuccess) { cancelOldErrorNotification(uploadFileOperation) return } @@ -319,9 +319,11 @@ class FilesUploadWorker( } notificationBuilder.setContentText(content) - notificationManager.notify(NotificationUtils.createUploadNotificationTag(uploadFileOperation.file), - NOTIFICATION_ERROR_ID, notificationBuilder.build()) - + notificationManager.notify( + NotificationUtils.createUploadNotificationTag(uploadFileOperation.file), + NOTIFICATION_ERROR_ID, + notificationBuilder.build() + ) } } @@ -398,12 +400,16 @@ class FilesUploadWorker( lastPercent = percent } - private fun cancelOldErrorNotification(uploadFileOperation: UploadFileOperation){ - //cancel for old file because of file conflicts - notificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.oldFile), - NOTIFICATION_ERROR_ID) - notificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.file), - NOTIFICATION_ERROR_ID) + private fun cancelOldErrorNotification(uploadFileOperation: UploadFileOperation) { + // cancel for old file because of file conflicts + notificationManager.cancel( + NotificationUtils.createUploadNotificationTag(uploadFileOperation.oldFile), + NOTIFICATION_ERROR_ID + ) + notificationManager.cancel( + NotificationUtils.createUploadNotificationTag(uploadFileOperation.file), + NOTIFICATION_ERROR_ID + ) } override fun onStopped() { From 08705947b7d6e953b6347d9fbc5b8f2df4f22667 Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Thu, 7 Dec 2023 00:01:44 +0100 Subject: [PATCH 5/7] fix dodgy code Signed-off-by: Jonas Mayer --- .../com/owncloud/android/files/services/FileUploader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java index 526a4050be6a..895a020ec5df 100644 --- a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java +++ b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java @@ -1447,10 +1447,10 @@ private void cancelOldErrorNotification(UploadFileOperation uploadFileOperation) mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); } - if (uploadFileOperation == null) return; + if (uploadFileOperation == null || uploadFileOperation.getOldFile() == null) return; //cancel for old file because of file conflicts mNotificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.getOldFile()), - NOTIFICATION_ERROR_ID); + NOTIFICATION_ERROR_ID); mNotificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.getFile()), NOTIFICATION_ERROR_ID); } From d0182ba646ff2928f6361773f65813359d865444 Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Thu, 7 Dec 2023 00:21:15 +0100 Subject: [PATCH 6/7] hopefully really fix dodgy code Signed-off-by: Jonas Mayer --- .../android/files/services/FileUploader.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java index 895a020ec5df..8b38441b85e3 100644 --- a/app/src/main/java/com/owncloud/android/files/services/FileUploader.java +++ b/app/src/main/java/com/owncloud/android/files/services/FileUploader.java @@ -1447,12 +1447,19 @@ private void cancelOldErrorNotification(UploadFileOperation uploadFileOperation) mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); } - if (uploadFileOperation == null || uploadFileOperation.getOldFile() == null) return; - //cancel for old file because of file conflicts - mNotificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.getOldFile()), - NOTIFICATION_ERROR_ID); + if (uploadFileOperation == null) return; + mNotificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.getFile()), - NOTIFICATION_ERROR_ID); + NOTIFICATION_ERROR_ID); + + //cancel for old file because of file conflicts + OCFile oldFile = uploadFileOperation.getOldFile(); + if ( oldFile != null) { + mNotificationManager.cancel(NotificationUtils.createUploadNotificationTag(oldFile), + NOTIFICATION_ERROR_ID); + } + + } From 5672234b41dc42ef74f01149b74472d24d20dd95 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 8 Dec 2023 09:39:58 +0100 Subject: [PATCH 7/7] only cancel notification if an old file exists Signed-off-by: tobiasKaminsky --- .../com/nextcloud/client/jobs/FilesUploadWorker.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt index 95354ec5fd0c..b5dc9b8b65e7 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt @@ -402,10 +402,12 @@ class FilesUploadWorker( private fun cancelOldErrorNotification(uploadFileOperation: UploadFileOperation) { // cancel for old file because of file conflicts - notificationManager.cancel( - NotificationUtils.createUploadNotificationTag(uploadFileOperation.oldFile), - NOTIFICATION_ERROR_ID - ) + if (uploadFileOperation.oldFile != null) { + notificationManager.cancel( + NotificationUtils.createUploadNotificationTag(uploadFileOperation.oldFile), + NOTIFICATION_ERROR_ID + ) + } notificationManager.cancel( NotificationUtils.createUploadNotificationTag(uploadFileOperation.file), NOTIFICATION_ERROR_ID