Skip to content

Commit

Permalink
Fix notification conflict not resolvable also on master
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Mayer <[email protected]>
  • Loading branch information
JonasMayerDev committed Jan 27, 2024
1 parent c069cd1 commit bb27d01
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ class FileUploaderIntents(private val context: Context) {
)

return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_MUTABLE)
PendingIntent.getActivity(context, SecureRandom().nextInt(), intent, PendingIntent.FLAG_MUTABLE)
} else {
PendingIntent.getActivity(
context,
0,
SecureRandom().nextInt(),
intent,
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,20 @@ class UploadNotificationManager(private val context: Context, private val viewTh
return
}

notificationManager.cancel(
NotificationUtils.createUploadNotificationTag(operation.file),
FileUploadWorker.NOTIFICATION_ERROR_ID
)
dismissOldErrorNotification(operation.file.remotePath, operation.file.storagePath)

operation.oldFile?.let {
notificationManager.cancel(
NotificationUtils.createUploadNotificationTag(it),
FileUploadWorker.NOTIFICATION_ERROR_ID
)
dismissOldErrorNotification(it.remotePath, it.storagePath)
}
}

fun dismissOldErrorNotification(remotePath: String, localPath: String) {
notificationManager.cancel(
NotificationUtils.createUploadNotificationTag(remotePath, localPath),
FileUploadWorker.NOTIFICATION_ERROR_ID
)
}

fun dismissWorkerNotifications() {
notificationManager.cancel(ID)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.nextcloud.client.account.User
import com.nextcloud.client.jobs.download.FileDownloadHelper
import com.nextcloud.client.jobs.upload.FileUploadHelper
import com.nextcloud.client.jobs.upload.FileUploadWorker
import com.nextcloud.client.jobs.upload.UploadNotificationManager
import com.nextcloud.model.HTTPStatusCodes
import com.nextcloud.utils.extensions.getParcelableArgument
import com.owncloud.android.R
Expand Down Expand Up @@ -92,36 +93,49 @@ class ConflictsResolveActivity : FileActivity(), OnConflictDecisionMadeListener
when (decision) {
Decision.CANCEL -> {}
Decision.KEEP_LOCAL -> {
upload?.let {
FileUploadHelper.instance().cancelFileUpload(it.remotePath, it.accountName)
}
FileUploadHelper.instance().uploadUpdatedFile(
user,
arrayOf(file),
localBehaviour,
NameCollisionPolicy.OVERWRITE
)
uploadsStorageManager?.removeUpload(upload)
}

Decision.KEEP_BOTH -> {
upload?.let {
FileUploadHelper.instance().cancelFileUpload(it.remotePath, it.accountName)
}
FileUploadHelper.instance().uploadUpdatedFile(
user,
arrayOf(file),
localBehaviour,
NameCollisionPolicy.RENAME
)
uploadsStorageManager?.removeUpload(upload)
}

Decision.KEEP_SERVER -> if (!shouldDeleteLocal()) {
// Overwrite local file
file?.let {
FileDownloadHelper.instance().downloadFile(
getUser().orElseThrow { RuntimeException() },
file,
conflictUploadId = conflictUploadId
)
Decision.KEEP_SERVER -> {
if (!shouldDeleteLocal()) {
// Overwrite local file
file?.let {
FileDownloadHelper.instance().downloadFile(
getUser().orElseThrow { RuntimeException() },
file,
conflictUploadId = conflictUploadId
)
}
}

upload?.let {
FileUploadHelper.instance().cancelFileUpload(it.remotePath, it.accountName)

UploadNotificationManager(
applicationContext,
viewThemeUtils
).dismissOldErrorNotification(it.remotePath, it.localPath)
}
} else {
uploadsStorageManager?.removeUpload(upload)
}

else -> {}
Expand Down

0 comments on commit bb27d01

Please sign in to comment.