mirror of
https://github.com/nextcloud/android.git
synced 2024-12-18 23:11:58 +03:00
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:
parent
8fdba73b92
commit
a7af4fae42
3 changed files with 21 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue