Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.nextcloud.client.jobs.utils

import android.app.Notification
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
Expand All @@ -32,6 +33,11 @@ import kotlinx.coroutines.withContext
object UploadErrorNotificationManager {
private const val TAG = "UploadErrorNotificationManager"

fun dismissConflictResolveNotification(context: Context, id: Long) {
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
manager.cancel(id.toInt())
}

/**
* Processes the result of an upload operation and manages error notifications.
* * It filters out successful or silent results and handles [ResultCode.SYNC_CONFLICT], [ResultCode.CONFLICT]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,12 @@ public void keepOfflineOperationAndServerFile(OfflineOperationEntity entity, OCF
offlineOperationsRepository.updateNextOperations(entity);
}

private @Nullable
OCFile getFileByPath(String type, String path) {
@Nullable
private OCFile getFileByPath(String type, String path) {
if (path == null) {
return null;
}

final boolean shouldUseEncryptedPath = ProviderTableMeta.FILE_PATH.equals(type);
FileEntity fileEntity = shouldUseEncryptedPath ?
fileDao.getFileByEncryptedRemotePath(path, user.getAccountName()) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package com.owncloud.android.ui.activity

import android.annotation.SuppressLint
import android.app.NotificationManager
import android.content.Context
import android.content.Intent
import android.os.Bundle
Expand All @@ -24,6 +23,7 @@ import com.nextcloud.client.jobs.operation.FileOperationHelper
import com.nextcloud.client.jobs.upload.FileUploadHelper
import com.nextcloud.client.jobs.upload.FileUploadWorker
import com.nextcloud.client.jobs.upload.UploadNotificationManager
import com.nextcloud.client.jobs.utils.UploadErrorNotificationManager
import com.nextcloud.model.HTTPStatusCodes
import com.nextcloud.utils.extensions.getDecryptedPath
import com.nextcloud.utils.extensions.getParcelableArgument
Expand Down Expand Up @@ -141,7 +141,10 @@ class ConflictsResolveActivity :
}

withContext(Dispatchers.Main) {
dismissConflictResolveNotification()
UploadErrorNotificationManager.dismissConflictResolveNotification(
this@ConflictsResolveActivity,
conflictUploadId
)
finish()
}
}
Expand Down Expand Up @@ -332,10 +335,6 @@ class ConflictsResolveActivity :
fileDataStorageManager.saveFile(file)
}

private fun dismissConflictResolveNotification() {
(getSystemService(NOTIFICATION_SERVICE) as NotificationManager).cancel(conflictUploadId.toInt())
}

private fun showErrorAndFinish(code: Int? = null) {
val message = if (code == HTTPStatusCodes.NOT_FOUND.code) {
getString(R.string.uploader_file_not_found_on_server_message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.nextcloud.client.core.Clock
import com.nextcloud.client.device.PowerManagementService
import com.nextcloud.client.jobs.upload.FileUploadEventBroadcaster
import com.nextcloud.client.jobs.upload.FileUploadHelper
import com.nextcloud.client.jobs.utils.UploadErrorNotificationManager
import com.nextcloud.client.utils.Throttler
import com.nextcloud.utils.extensions.webDavParentPath
import com.owncloud.android.R
Expand Down Expand Up @@ -320,21 +321,21 @@ class UploadListActivity :
val client = clientRepository.getOwncloudClient()

// Check parent folder exists
val parentPath = storageManager
.getFileByPath(upload.remotePath)
.parentRemotePath
?: upload.remotePath.webDavParentPath()

val checkOp = ExistenceCheckRemoteOperation(parentPath, false)
val checkResult = checkOp.execute(client)

if (!checkResult.isSuccess &&
checkResult.code == RemoteOperationResult.ResultCode.FILE_NOT_FOUND
) {
withContext(Dispatchers.Main) {
showConflictSnackbar(R.string.uploader_file_not_found_message)
val file = storageManager.getFileByPath(upload.remotePath)
val parentPath = (file?.parentRemotePath ?: upload.remotePath?.webDavParentPath())

parentPath?.let {
val checkOp = ExistenceCheckRemoteOperation(it, false)
val checkResult = checkOp.execute(client)

if (!checkResult.isSuccess &&
checkResult.code == RemoteOperationResult.ResultCode.FILE_NOT_FOUND
) {
withContext(Dispatchers.Main) {
showConflictSnackbar(R.string.uploader_file_not_found_message)
}
return@launch
}
return@launch
}

val result = uploadFileOperationFactory
Expand All @@ -343,6 +344,10 @@ class UploadListActivity :

if (result.isSuccess) {
withContext(Dispatchers.Main) {
UploadErrorNotificationManager.dismissConflictResolveNotification(
this@UploadListActivity,
upload.uploadId
)
uploadListAdapter.loadUploadItemsFromDb()
}
}
Expand Down
Loading