allow to copy a file/folder into its own folder -> makes a copy

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2024-10-08 09:10:57 +02:00 committed by Alper Öztürk
parent 8fdba73b92
commit a7af4fae42
3 changed files with 21 additions and 5 deletions

View file

@ -64,6 +64,19 @@ public class CopyFileOperation extends SyncOperation {
if (file.isFolder()) { if (file.isFolder()) {
targetPath += OCFile.PATH_SEPARATOR; 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); RemoteOperationResult result = new CopyFileRemoteOperation(srcPath, targetPath, false).execute(client);
/// 3. local copy /// 3. local copy

View file

@ -1342,7 +1342,7 @@ public class UploadFileOperation extends SyncOperation {
* @param fileNames list of decrypted file names * @param fileNames list of decrypted file names
* @return new remote path * @return new remote path
*/ */
private String getNewAvailableRemotePath(OwnCloudClient client, public static String getNewAvailableRemotePath(OwnCloudClient client,
String remotePath, String remotePath,
List<String> fileNames, List<String> fileNames,
boolean encrypted) { boolean encrypted) {
@ -1368,7 +1368,7 @@ public class UploadFileOperation extends SyncOperation {
return newPath; return newPath;
} }
private boolean existsFile(OwnCloudClient client, private static boolean existsFile(OwnCloudClient client,
String remotePath, String remotePath,
List<String> fileNames, List<String> fileNames,
boolean encrypted) { boolean encrypted) {

View file

@ -403,15 +403,16 @@ open class FolderPickerActivity :
private fun checkButtonStates(isConditionMet: Boolean) { private fun checkButtonStates(isConditionMet: Boolean) {
folderPickerBinding.run { folderPickerBinding.run {
folderPickerBtnChoose.isEnabled = isConditionMet folderPickerBtnChoose.isEnabled = isConditionMet
folderPickerBtnCopy.isEnabled = isFolderSelectable() && isConditionMet folderPickerBtnCopy.isEnabled = isFolderSelectable(COPY) && isConditionMet
folderPickerBtnMove.isEnabled = isFolderSelectable() && isConditionMet folderPickerBtnMove.isEnabled = isFolderSelectable(MOVE) && isConditionMet
} }
} }
// for copy and move, disable selecting parent folder of target files // for copy and move, disable selecting parent folder of target files
private fun isFolderSelectable(): Boolean { private fun isFolderSelectable(type: String): Boolean {
return when { return when {
action != MOVE_OR_COPY -> true action != MOVE_OR_COPY -> true
action == MOVE_OR_COPY && type == COPY -> true
targetFilePaths.isNullOrEmpty() -> true targetFilePaths.isNullOrEmpty() -> true
file?.isFolder != true -> true file?.isFolder != true -> true
@ -688,6 +689,8 @@ open class FolderPickerActivity :
const val MOVE_OR_COPY = "MOVE_OR_COPY" const val MOVE_OR_COPY = "MOVE_OR_COPY"
const val CHOOSE_LOCATION = "CHOOSE_LOCATION" const val CHOOSE_LOCATION = "CHOOSE_LOCATION"
private val TAG = FolderPickerActivity::class.java.simpleName 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" const val TAG_LIST_OF_FOLDERS = "LIST_OF_FOLDERS"
} }