From a7af4fae429532c8a9cd30ad406e509c1882b071 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Tue, 8 Oct 2024 09:10:57 +0200 Subject: [PATCH] allow to copy a file/folder into its own folder -> makes a copy Signed-off-by: tobiasKaminsky --- .../android/operations/CopyFileOperation.java | 13 +++++++++++++ .../android/operations/UploadFileOperation.java | 4 ++-- .../android/ui/activity/FolderPickerActivity.kt | 9 ++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/operations/CopyFileOperation.java b/app/src/main/java/com/owncloud/android/operations/CopyFileOperation.java index b052b03465..bd7d21a6db 100644 --- a/app/src/main/java/com/owncloud/android/operations/CopyFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/CopyFileOperation.java @@ -64,6 +64,19 @@ public class CopyFileOperation extends SyncOperation { if (file.isFolder()) { targetPath += OCFile.PATH_SEPARATOR; } + + // auto rename, to allow copy + if (targetPath.equals(srcPath)) { + if (file.isFolder()) { + targetPath = targetParentPath + file.getFileName(); + } + targetPath = UploadFileOperation.getNewAvailableRemotePath(client, targetPath, null, false); + + if (file.isFolder()) { + targetPath += OCFile.PATH_SEPARATOR; + } + } + RemoteOperationResult result = new CopyFileRemoteOperation(srcPath, targetPath, false).execute(client); /// 3. local copy diff --git a/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index 0771bae6b7..2ff9e9e1a3 100644 --- a/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -1342,7 +1342,7 @@ public class UploadFileOperation extends SyncOperation { * @param fileNames list of decrypted file names * @return new remote path */ - private String getNewAvailableRemotePath(OwnCloudClient client, + public static String getNewAvailableRemotePath(OwnCloudClient client, String remotePath, List fileNames, boolean encrypted) { @@ -1368,7 +1368,7 @@ public class UploadFileOperation extends SyncOperation { return newPath; } - private boolean existsFile(OwnCloudClient client, + private static boolean existsFile(OwnCloudClient client, String remotePath, List fileNames, boolean encrypted) { diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.kt b/app/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.kt index e3cab8ab92..30dc48141c 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.kt +++ b/app/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.kt @@ -403,15 +403,16 @@ open class FolderPickerActivity : private fun checkButtonStates(isConditionMet: Boolean) { folderPickerBinding.run { folderPickerBtnChoose.isEnabled = isConditionMet - folderPickerBtnCopy.isEnabled = isFolderSelectable() && isConditionMet - folderPickerBtnMove.isEnabled = isFolderSelectable() && isConditionMet + folderPickerBtnCopy.isEnabled = isFolderSelectable(COPY) && isConditionMet + folderPickerBtnMove.isEnabled = isFolderSelectable(MOVE) && isConditionMet } } // for copy and move, disable selecting parent folder of target files - private fun isFolderSelectable(): Boolean { + private fun isFolderSelectable(type: String): Boolean { return when { action != MOVE_OR_COPY -> true + action == MOVE_OR_COPY && type == COPY -> true targetFilePaths.isNullOrEmpty() -> true file?.isFolder != true -> true @@ -688,6 +689,8 @@ open class FolderPickerActivity : const val MOVE_OR_COPY = "MOVE_OR_COPY" const val CHOOSE_LOCATION = "CHOOSE_LOCATION" private val TAG = FolderPickerActivity::class.java.simpleName + private const val MOVE = "MOVE" + private const val COPY = "COPY" const val TAG_LIST_OF_FOLDERS = "LIST_OF_FOLDERS" }