瀏覽代碼

Merge pull request #13733 from nextcloud/copy

allow to copy a file/folder into its own folder -> makes a copy
Tobias Kaminsky 4 月之前
父節點
當前提交
63756c7a14

+ 13 - 0
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

+ 2 - 2
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<String> 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<String> fileNames,
                                boolean encrypted) {

+ 6 - 3
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"
     }