mirror of
https://github.com/nextcloud/android.git
synced 2024-11-24 06:05:42 +03:00
Change content intent
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
64e73c77ad
commit
39ce4c4c1c
2 changed files with 34 additions and 40 deletions
|
@ -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)
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue