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 ba08f29535..b7acf13c73 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt @@ -254,31 +254,47 @@ class FilesUploadWorker( // TODO generalize for automated uploads } - private fun getUploadListIntent(context: Context): PendingIntent { - val mainActivityIntent = Intent( - context, - UploadListActivity::class.java - ).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) + private fun createConflictResolveAction(context: Context, uploadFileOperation: UploadFileOperation): PendingIntent { + val intent = ConflictsResolveActivity.createIntent( + uploadFileOperation.file, + uploadFileOperation.user, + uploadFileOperation.ocUploadId, + Intent.FLAG_ACTIVITY_CLEAR_TOP, + context + ) return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - PendingIntent.getActivity(context, 0, mainActivityIntent, PendingIntent.FLAG_MUTABLE) + PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_MUTABLE) } else { PendingIntent.getActivity( context, 0, - mainActivityIntent, + intent, PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE ) } } - private fun addUploadListActionToNotification() { - val openUploadsIntent = getUploadListIntent(context) + private fun addConflictResolveActionToNotification(uploadFileOperation: UploadFileOperation) { + val intent: PendingIntent = createConflictResolveAction(context, uploadFileOperation) notificationBuilder.addAction( R.drawable.ic_cloud_upload, - context.getString(R.string.uploader_notification_action_button), - openUploadsIntent + context.getString(R.string.upload_list_resolve_conflict), + intent + ) + } + + private fun addUploadListContentIntent(uploadFileOperation: UploadFileOperation) { + val uploadListIntent = createUploadListIntent(uploadFileOperation) + + notificationBuilder.setContentIntent( + PendingIntent.getActivity( + context, + System.currentTimeMillis().toInt(), + uploadListIntent, + PendingIntent.FLAG_IMMUTABLE + ) ) } @@ -323,29 +339,18 @@ class FilesUploadWorker( .setProgress(0, 0, false) .clearActions() - if (notificationBuilder.mActions.isEmpty()) { - addUploadListActionToNotification() - } - val content = ErrorMessageAdapter.getErrorCauseMessage(uploadResult, uploadFileOperation, context.resources) + addUploadListContentIntent(uploadFileOperation) + + if (uploadResult.code == ResultCode.SYNC_CONFLICT) { + addConflictResolveActionToNotification(uploadFileOperation) + } + if (needsToUpdateCredentials) { createUpdateCredentialsNotification(uploadFileOperation.user.toPlatformAccount()) - } else { - val intent = if (uploadResult.code == ResultCode.SYNC_CONFLICT) { - createResolveConflictIntent(uploadFileOperation) - } else { - createUploadListIntent(uploadFileOperation) - } - notificationBuilder.setContentIntent( - PendingIntent.getActivity( - context, - System.currentTimeMillis().toInt(), - intent, - PendingIntent.FLAG_IMMUTABLE - ) - ) } + notificationBuilder.setContentText(content) if (!uploadResult.isSuccess) { notificationManager.notify(SecureRandom().nextInt(), notificationBuilder.build()) @@ -362,16 +367,6 @@ class FilesUploadWorker( ) } - private fun createResolveConflictIntent(uploadFileOperation: UploadFileOperation): Intent { - return ConflictsResolveActivity.createIntent( - uploadFileOperation.file, - uploadFileOperation.user, - uploadFileOperation.ocUploadId, - Intent.FLAG_ACTIVITY_CLEAR_TOP, - context - ) - } - private fun createUpdateCredentialsNotification(account: Account) { // let the user update credentials with one click val updateAccountCredentials = Intent(context, AuthenticatorActivity::class.java) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 99654c786d..3a5bf57199 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -914,7 +914,6 @@ creates folder info File not found. Are you sure this file exist or conflict not solved before? File upload conflict - Open Uploads Pick which version to keep of %1$s Resolve conflict Delete