|
@@ -254,31 +254,47 @@ class FilesUploadWorker(
|
|
// TODO generalize for automated uploads
|
|
// 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) {
|
|
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 {
|
|
} else {
|
|
PendingIntent.getActivity(
|
|
PendingIntent.getActivity(
|
|
context,
|
|
context,
|
|
0,
|
|
0,
|
|
- mainActivityIntent,
|
|
|
|
|
|
+ intent,
|
|
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
|
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(
|
|
notificationBuilder.addAction(
|
|
R.drawable.ic_cloud_upload,
|
|
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)
|
|
.setProgress(0, 0, false)
|
|
.clearActions()
|
|
.clearActions()
|
|
|
|
|
|
- if (notificationBuilder.mActions.isEmpty()) {
|
|
|
|
- addUploadListActionToNotification()
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
val content = ErrorMessageAdapter.getErrorCauseMessage(uploadResult, uploadFileOperation, context.resources)
|
|
val content = ErrorMessageAdapter.getErrorCauseMessage(uploadResult, uploadFileOperation, context.resources)
|
|
|
|
|
|
|
|
+ addUploadListContentIntent(uploadFileOperation)
|
|
|
|
+
|
|
|
|
+ if (uploadResult.code == ResultCode.SYNC_CONFLICT) {
|
|
|
|
+ addConflictResolveActionToNotification(uploadFileOperation)
|
|
|
|
+ }
|
|
|
|
+
|
|
if (needsToUpdateCredentials) {
|
|
if (needsToUpdateCredentials) {
|
|
createUpdateCredentialsNotification(uploadFileOperation.user.toPlatformAccount())
|
|
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)
|
|
notificationBuilder.setContentText(content)
|
|
if (!uploadResult.isSuccess) {
|
|
if (!uploadResult.isSuccess) {
|
|
notificationManager.notify(SecureRandom().nextInt(), notificationBuilder.build())
|
|
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) {
|
|
private fun createUpdateCredentialsNotification(account: Account) {
|
|
// let the user update credentials with one click
|
|
// let the user update credentials with one click
|
|
val updateAccountCredentials = Intent(context, AuthenticatorActivity::class.java)
|
|
val updateAccountCredentials = Intent(context, AuthenticatorActivity::class.java)
|