2 * ownCloud Android client application
4 * @author David A. Velasco
5 * Copyright (C) 2015 ownCloud Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2,
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 package com
.owncloud
.android
.operations
;
23 import com
.owncloud
.android
.MainApp
;
24 import com
.owncloud
.android
.datamodel
.OCFile
;
25 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
26 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
27 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
.ResultCode
;
28 import com
.owncloud
.android
.lib
.resources
.files
.MoveRemoteFileOperation
;
29 import com
.owncloud
.android
.operations
.common
.SyncOperation
;
31 import android
.accounts
.Account
;
35 * Operation mmoving an {@link OCFile} to a different folder.
37 public class MoveFileOperation
extends SyncOperation
{
39 //private static final String TAG = MoveFileOperation.class.getSimpleName();
41 private String mSrcPath
;
42 private String mTargetParentPath
;
51 * @param srcPath Remote path of the {@link OCFile} to move.
52 * @param targetParentPath Path to the folder where the file will be moved into.
53 * @param account OwnCloud account containing both the file and the target folder
55 public MoveFileOperation(String srcPath
, String targetParentPath
, Account account
) {
57 mTargetParentPath
= targetParentPath
;
58 if (!mTargetParentPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
59 mTargetParentPath
+= OCFile
.PATH_SEPARATOR
;
66 * Performs the operation.
68 * @param client Client object to communicate with the remote ownCloud server.
71 protected RemoteOperationResult
run(OwnCloudClient client
) {
72 RemoteOperationResult result
= null
;
74 /// 1. check move validity
75 if (mTargetParentPath
.startsWith(mSrcPath
)) {
76 return new RemoteOperationResult(ResultCode
.INVALID_MOVE_INTO_DESCENDANT
);
78 mFile
= getStorageManager().getFileByPath(mSrcPath
);
80 return new RemoteOperationResult(ResultCode
.FILE_NOT_FOUND
);
84 String targetPath
= mTargetParentPath
+ mFile
.getFileName();
85 if (mFile
.isFolder()) {
86 targetPath
+= OCFile
.PATH_SEPARATOR
;
88 MoveRemoteFileOperation operation
= new MoveRemoteFileOperation(
93 result
= operation
.execute(client
);
96 if (result
.isSuccess()) {
97 getStorageManager().moveLocalFile(mFile
, targetPath
, mTargetParentPath
);
99 // TODO handle ResultCode.PARTIAL_MOVE_DONE in client Activity, for the moment