Skip to content

Commit

Permalink
Change content intent
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Dec 5, 2023
1 parent 64e73c7 commit 39ce4c4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 40 deletions.
73 changes: 34 additions & 39 deletions app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
}

Expand Down Expand Up @@ -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())
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,6 @@
<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>
Expand Down

0 comments on commit 39ce4c4

Please sign in to comment.