From 918f43a36cd4af4df0c2103c33abce1727cb39d6 Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Thu, 25 Jan 2024 19:06:15 +0100 Subject: [PATCH] Give user feedback in upload list tab Signed-off-by: Jonas Mayer --- .../client/jobs/FilesUploadWorker.kt | 4 +++- .../android/ui/adapter/UploadListAdapter.java | 19 ++++++++++++++++++- .../android/utils/FilesUploadHelper.kt | 8 ++++++-- app/src/main/res/values/strings.xml | 1 + 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt index 00f96f068721..ff2215aed8c9 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt @@ -308,6 +308,7 @@ class FilesUploadWorker( /** * adapted from [com.owncloud.android.files.services.FileUploader.notifyUploadResult] */ + @Suppress("ReturnCount") private fun notifyUploadResult( uploadFileOperation: UploadFileOperation, uploadResult: RemoteOperationResult @@ -327,7 +328,8 @@ class FilesUploadWorker( // Only notify if it is not same file on remote that causes conflict if (uploadResult.code == ResultCode.SYNC_CONFLICT && FilesUploadHelper().isSameFileOnRemote( uploadFileOperation.user, File(uploadFileOperation.storagePath), uploadFileOperation.remotePath, context - )){ + ) + ) { return } diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java index 1b1763ce01e8..6e79e06422c1 100755 --- a/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java @@ -29,6 +29,7 @@ import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; +import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.net.Uri; import android.text.format.DateUtils; @@ -304,6 +305,16 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati case UPLOAD_FAILED -> itemViewHolder.binding.uploadDate.setVisibility(View.GONE); case UPLOAD_SUCCEEDED -> itemViewHolder.binding.uploadStatus.setVisibility(View.GONE); } + + // show status if same file conflict or local file deleted + if (item.getUploadStatus().equals(UploadStatus.UPLOAD_SUCCEEDED) && + item.getLastResult() != UploadResult.UPLOADED){ + itemViewHolder.binding.uploadStatus.setVisibility(View.VISIBLE); + itemViewHolder.binding.uploadStatus.setTypeface(null, Typeface.BOLD); + itemViewHolder.binding.uploadDate.setVisibility(View.GONE); + itemViewHolder.binding.uploadFileSize.setVisibility(View.GONE); + } + itemViewHolder.binding.uploadStatus.setText(status); // bind listeners to perform actions @@ -622,7 +633,13 @@ private String getStatusText(OCUpload upload) { break; case UPLOAD_SUCCEEDED: - status = parentActivity.getString(R.string.uploads_view_upload_status_succeeded); + if (upload.getLastResult() == UploadResult.SAME_FILE_CONFLICT){ + status = parentActivity.getString(R.string.uploads_view_upload_status_succeeded_same_file); + }else if (upload.getLastResult() == UploadResult.FILE_NOT_FOUND) { + status = getUploadFailedStatusText(upload.getLastResult()); + } else { + status = parentActivity.getString(R.string.uploads_view_upload_status_succeeded); + } break; case UPLOAD_FAILED: diff --git a/app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt b/app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt index 42b82c1c3b9c..c538f4388bc9 100644 --- a/app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt +++ b/app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt @@ -138,9 +138,10 @@ class FilesUploadHelper { } } + @Suppress("MagicNumber") fun isSameFileOnRemote(user: User, localFile: File, remotePath: String, context: Context): Boolean { // Compare remote file to local file - val localLastModifiedTimestamp = localFile.lastModified() / 1000 + val localLastModifiedTimestamp = localFile.lastModified() / 1000 // remote file timestamp in milli not micro sec val localCreationTimestamp = FileUtil.getCreationTimestamp(localFile) val localSize: Long = localFile.length() @@ -148,7 +149,10 @@ class FilesUploadHelper { val result: RemoteOperationResult<*> = operation.execute(user, context) if (result.isSuccess) { val remoteFile = result.data[0] as RemoteFile - return remoteFile.size == localSize && localCreationTimestamp != null && localCreationTimestamp == remoteFile.creationTimestamp && remoteFile.modifiedTimestamp == localLastModifiedTimestamp * 1000 + return remoteFile.size == localSize && + localCreationTimestamp != null && + localCreationTimestamp == remoteFile.creationTimestamp && + remoteFile.modifiedTimestamp == localLastModifiedTimestamp * 1000 } return false } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3aaa421c185f..3bdd3b58b937 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -152,6 +152,7 @@ Failed/pending restart Uploaded Completed + Same file found on remote, skipping upload Cancelled Connection error Credentials error