Skip to content

Commit 3f72ddf

Browse files
alperozturk96backportbot[bot]
authored andcommitted
wip
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 340a6f9 commit 3f72ddf

4 files changed

Lines changed: 49 additions & 29 deletions

File tree

app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.kt

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import com.owncloud.android.db.OCUpload
3636
import com.owncloud.android.lib.common.operations.RemoteOperation
3737
import com.owncloud.android.lib.common.operations.RemoteOperationResult
3838
import com.owncloud.android.lib.common.utils.Log_OC
39+
import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation
3940
import com.owncloud.android.operations.CheckCurrentCredentialsOperation
4041
import com.owncloud.android.operations.factory.UploadFileOperationFactory
4142
import com.owncloud.android.ui.adapter.uploadList.UploadListAdapter
@@ -291,47 +292,65 @@ class UploadListActivity :
291292

292293
withContext(Dispatchers.Main) {
293294
when (result) {
294-
is ConflictHandlingResult.ConflictNotExists -> {
295-
showConflictNotExists(upload)
295+
is ConflictHandlingResult.ConflictNotExistsRemoteFileNotFound -> {
296+
showConflictSnackbar(R.string.upload_sync_conflict_not_exists)
297+
retryUpload(upload)
296298
}
297299

298300
is ConflictHandlingResult.CannotCheckConflict -> {
299-
showConflictError()
301+
showConflictSnackbar(R.string.upload_sync_conflict_check_error)
300302
}
301303

302304
is ConflictHandlingResult.ShowConflictResolveDialog -> {
303305
conflictSnackbar?.dismiss()
304306
adapterHelper.openConflictActivity(result.file, result.upload)
305307
}
308+
309+
is ConflictHandlingResult.ConflictNotExistsSameFile -> {
310+
showConflictSnackbar(R.string.upload_sync_conflict_same_file)
311+
}
306312
}
307313
}
308314
}
309315
}
310316

311-
private fun showConflictNotExists(upload: OCUpload) {
312-
conflictSnackbar?.apply {
313-
setText(R.string.upload_sync_conflict_not_exists)
314-
setDuration(Snackbar.LENGTH_LONG)
315-
setAction(R.string.retry) {
316-
lifecycleScope.launch(Dispatchers.IO) {
317-
val client = clientRepository.getOwncloudClient()
318-
val operation = uploadFileOperationFactory.create(upload).execute(client)
319-
if (operation.isSuccess) {
320-
withContext(Dispatchers.Main) {
321-
uploadListAdapter.loadUploadItemsFromDb()
322-
}
323-
}
317+
private fun retryUpload(upload: OCUpload) {
318+
lifecycleScope.launch(Dispatchers.IO) {
319+
val client = clientRepository.getOwncloudClient()
320+
321+
// Check parent folder exists
322+
val parentPath = storageManager
323+
.getFileByPath(upload.remotePath)
324+
.parentRemotePath
325+
326+
val checkOp = ExistenceCheckRemoteOperation(parentPath, false)
327+
val checkResult = checkOp.execute(client)
328+
329+
if (!checkResult.isSuccess &&
330+
checkResult.code == RemoteOperationResult.ResultCode.FILE_NOT_FOUND
331+
) {
332+
withContext(Dispatchers.Main) {
333+
showConflictSnackbar(R.string.uploader_file_not_found_message)
334+
}
335+
return@launch
336+
}
337+
338+
val result = uploadFileOperationFactory
339+
.create(upload)
340+
.execute(client)
341+
342+
if (result.isSuccess) {
343+
withContext(Dispatchers.Main) {
344+
uploadListAdapter.loadUploadItemsFromDb()
324345
}
325346
}
326-
show()
327347
}
328348
}
329349

330-
private fun showConflictError() {
350+
private fun showConflictSnackbar(messageId: Int) {
331351
conflictSnackbar?.apply {
332-
setText(R.string.upload_sync_conflict_check_error)
352+
setText(messageId)
333353
setDuration(Snackbar.LENGTH_LONG)
334-
setAction(null, null)
335354
show()
336355
}
337356
}

app/src/main/java/com/owncloud/android/ui/adapter/uploadList/helper/ConflictHandlingResult.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.owncloud.android.db.OCUpload
1212

1313
sealed class ConflictHandlingResult {
1414
data object CannotCheckConflict : ConflictHandlingResult()
15-
data object ConflictNotExists : ConflictHandlingResult()
15+
data object ConflictNotExistsSameFile : ConflictHandlingResult()
16+
data object ConflictNotExistsRemoteFileNotFound : ConflictHandlingResult()
1617
data class ShowConflictResolveDialog(val file: OCFile, val upload: OCUpload) : ConflictHandlingResult()
1718
}

app/src/main/java/com/owncloud/android/ui/adapter/uploadList/helper/UploadListAdapterActionHandler.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class UploadListAdapterActionHandler : UploadListAdapterAction {
3535
if (!operationResult.isSuccess) {
3636
return@withContext when (operationResult.code) {
3737
RemoteOperationResult.ResultCode.FILE_NOT_FOUND -> {
38-
onConflictNotExists(upload, storageManager)
38+
updateStatus(upload, storageManager, success = false)
39+
ConflictHandlingResult.ConflictNotExistsRemoteFileNotFound
3940
}
4041

4142
else -> {
@@ -54,18 +55,15 @@ class UploadListAdapterActionHandler : UploadListAdapterAction {
5455
val ocFile = FileStorageUtils.fillOCFile(remoteFile)
5556

5657
if (remoteFile.isSame(ocFile.storagePath)) {
57-
onConflictNotExists(upload, storageManager)
58+
updateStatus(upload, storageManager, success = true)
59+
ConflictHandlingResult.ConflictNotExistsSameFile
5860
} else {
5961
ConflictHandlingResult.ShowConflictResolveDialog(ocFile, upload)
6062
}
6163
}
6264

63-
private fun onConflictNotExists(
64-
upload: OCUpload,
65-
storageManager: UploadsStorageManager
66-
): ConflictHandlingResult.ConflictNotExists {
65+
private fun updateStatus(upload: OCUpload, storageManager: UploadsStorageManager, success: Boolean) {
6766
val entity = storageManager.uploadDao.getUploadById(upload.uploadId, upload.accountName)
68-
storageManager.updateStatus(entity, UploadsStorageManager.UploadStatus.UPLOAD_FAILED)
69-
return ConflictHandlingResult.ConflictNotExists
67+
storageManager.updateStatus(entity, success)
7068
}
7169
}

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,7 @@
10961096
<string name="upload_old_android">Encryption is only possible with &gt;= Android 5.0</string>
10971097
<string name="upload_sync_conflict_checking">Checking for upload conflicts…</string>
10981098
<string name="upload_sync_conflict_not_exists">Conflict resolved.</string>
1099+
<string name="upload_sync_conflict_same_file">No conflict detected. Same file.</string>
10991100
<string name="upload_sync_conflict_check_error">Could not check for upload conflicts. Please try again.</string>
11001101
<string name="upload_sync_conflict_check">There might be a conflict from your last upload. Tap to check.</string>
11011102
<string name="upload_cannot_create_file">Cannot create local file</string>
@@ -1190,6 +1191,7 @@
11901191
<string name="failed_to_start_editor">Failed to start editor</string>
11911192
<string name="create_rich_workspace">Add folder description</string>
11921193
<string name="uploader_file_not_found_on_server_message">We couldnt locate the file on server. Another user may have deleted the file</string>
1194+
<string name="uploader_file_not_found_message">File not found. Are you sure that this file exists or has a previous conflict not been resolved?</string>
11931195
<string name="uploader_upload_failed_sync_conflict_error">File upload conflict</string>
11941196
<string name="uploader_upload_failed_sync_conflict_error_content">Pick which version to keep of %1$s</string>
11951197
<string name="upload_list_resolve_conflict">Resolve conflict</string>

0 commit comments

Comments
 (0)