Browse Source

Add action to go upload list for file conflict notification

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 year ago
parent
commit
98136b9281

+ 30 - 0
app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt

@@ -23,6 +23,7 @@
 package com.nextcloud.client.jobs
 
 import android.accounts.Account
+import android.annotation.SuppressLint
 import android.app.NotificationManager
 import android.app.PendingIntent
 import android.content.Context
@@ -238,9 +239,33 @@ 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)
+
+        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+            PendingIntent.getActivity(context, 0, mainActivityIntent, PendingIntent.FLAG_MUTABLE)
+        } else {
+            PendingIntent.getActivity(
+                context, 0, mainActivityIntent,
+                PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
+            )
+        }
+    }
+
+    private fun addUploadListActionToNotification() {
+        val openUploadsIntent = getUploadListIntent(context)
+
+        notificationBuilder.addAction(
+            R.drawable.ic_cloud_upload,
+            context.getString(R.string.uploader_notification_action_button),
+            openUploadsIntent
+        )
+    }
+
     /**
      * adapted from [com.owncloud.android.files.services.FileUploader.notifyUploadResult]
      */
+    @SuppressLint("RestrictedApi")
     private fun notifyUploadResult(
         uploadFileOperation: UploadFileOperation,
         uploadResult: RemoteOperationResult<Any?>
@@ -269,6 +294,7 @@ class FilesUploadWorker(
                 // check file conflict
                 tickerId = R.string.uploader_upload_failed_sync_conflict_error
             }
+
             notificationBuilder
                 .setTicker(context.getString(tickerId))
                 .setContentTitle(context.getString(tickerId))
@@ -276,6 +302,10 @@ class FilesUploadWorker(
                 .setOngoing(false)
                 .setProgress(0, 0, false)
 
+            if (notificationBuilder.mActions.isEmpty()) {
+                addUploadListActionToNotification()
+            }
+
             val content = ErrorMessageAdapter.getErrorCauseMessage(uploadResult, uploadFileOperation, context.resources)
 
             if (needsToUpdateCredentials) {

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -914,6 +914,7 @@
     <string name="creates_rich_workspace">creates folder info</string>
     <string name="uploader_file_not_found_message">File not found. Are you sure this file exist or conflict not solved before?</string>
     <string name="uploader_upload_failed_sync_conflict_error">File upload conflict</string>
+    <string name="uploader_notification_action_button">Open Uploads</string>
     <string name="uploader_upload_failed_sync_conflict_error_content">Pick which version to keep of %1$s</string>
     <string name="upload_list_resolve_conflict">Resolve conflict</string>
     <string name="upload_list_delete">Delete</string>