From: David A. Velasco Date: Tue, 26 Aug 2014 08:58:34 +0000 (+0200) Subject: Start MoveFileOperation when 'Choose' button is clicked [Work In X-Git-Tag: oc-android-1.7.0_signed~197^2~19 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/7d0e39f730f8adc1421d0f5720b6bd7bf637fdfa Start MoveFileOperation when 'Choose' button is clicked [Work In Progress!] --- diff --git a/src/com/owncloud/android/operations/MoveFileOperation.java b/src/com/owncloud/android/operations/MoveFileOperation.java index f1a3f9f1..620a058c 100644 --- a/src/com/owncloud/android/operations/MoveFileOperation.java +++ b/src/com/owncloud/android/operations/MoveFileOperation.java @@ -24,6 +24,7 @@ import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.lib.resources.files.MoveRemoteFileOperation; import com.owncloud.android.lib.resources.files.RenameRemoteFileOperation; import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.utils.FileStorageUtils; @@ -45,6 +46,7 @@ public class MoveFileOperation extends SyncOperation { private Account mAccount; private String mNewParentPath; private OCFile mFile; + private String mNewPath; @@ -59,7 +61,9 @@ public class MoveFileOperation extends SyncOperation { mPath = path; mNewParentPath = newParentPath; mAccount = account; + mFile = null; + mNewPath = ""; } public OCFile getFile() { @@ -75,46 +79,59 @@ public class MoveFileOperation extends SyncOperation { @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; + mFile = getStorageManager().getFileByPath(mPath); - // check if the new name is valid in the local file system try { - String parentPath = (new File(mFile.getRemotePath())).getParent(); - parentPath = (parentPath.endsWith(OCFile.PATH_SEPARATOR)) - ? parentPath - : parentPath + OCFile.PATH_SEPARATOR; + /// 1. check move validity - String mNewPath = mNewParentPath + mFile.getFileName(); - if (mFile.isFolder() && !mNewPath.endsWith(OCFile.PATH_SEPARATOR)) { - mNewPath += OCFile.PATH_SEPARATOR; - } - - // check local overwrite - if (getStorageManager().getFileByPath(mPath) != null) { - return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); - } + /// 2. remove move MoveRemoteFileOperation operation = new MoveRemoteFileOperation( mFile.getRemotePath(), mNewPath, - mFile.isFolder() + false ); result = operation.execute(client); + + /// 3. local move if (result.isSuccess()) { + //moveLocaly(); + /* if (mFile.isFolder()) { saveLocalDirectory(); } else { saveLocalFile(); } + */ + } + + + String parentPath = (new File(mFile.getRemotePath())).getParent(); + parentPath = (parentPath.endsWith(OCFile.PATH_SEPARATOR)) + ? parentPath + : parentPath + OCFile.PATH_SEPARATOR; + + mNewPath = mNewParentPath + mFile.getFileName(); + if (mFile.isFolder() && !mNewPath.endsWith(OCFile.PATH_SEPARATOR)) { + mNewPath += OCFile.PATH_SEPARATOR; + } + + // check local overwrite + if (getStorageManager().getFileByPath(mPath) != null) { + return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); } + /* } catch (IOException e) { Log_OC.e(TAG, "Move " + mFile.getRemotePath() + " to " + (mNewParentPath==null) + ": " + - ((result!= null) ? result.getLogMessage() : ""), e); + ((result!= null) ? result.getLogMessage() : ""), e);*/ + } finally { + } return result; @@ -122,25 +139,26 @@ public class MoveFileOperation extends SyncOperation { private void saveLocalDirectory() { - getStorageManager().moveFolder(mFile, mNewParentPath); + getStorageManager().moveFolder(mFile, mNewPath); String localPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile); File localDir = new File(localPath); if (localDir.exists()) { - localDir.renameTo(new File(FileStorageUtils.getSavePath(mAccount.name) + mNewParentPath)); + localDir.renameTo(new File(FileStorageUtils.getSavePath(mAccount.name) + mNewPath)); // TODO - if renameTo fails, children files that are already down will result unlinked } } private void saveLocalFile() { - mFile.setFileName(mNewName); + /* + mFile.setRFileName(mNewName); <<< NO > - // try to rename the local copy of the file + // try to move the local copy of the file if (mFile.isDown()) { File f = new File(mFile.getStoragePath()); String parentStoragePath = f.getParent(); if (!parentStoragePath.endsWith(File.separator)) parentStoragePath += File.separator; - if (f.renameTo(new File(parentStoragePath + mNewName))) { + if (f.renameTo(new File())) { mFile.setStoragePath(parentStoragePath + mNewName); } // else - NOTHING: the link to the local file is kept although the local name can't be updated @@ -148,6 +166,7 @@ public class MoveFileOperation extends SyncOperation { } getStorageManager().saveFile(mFile); + */ } /** @@ -166,6 +185,9 @@ public class MoveFileOperation extends SyncOperation { * @throws IOException When the temporal folder can not be created. */ private boolean isValidNewName() throws IOException { + + return true; + /* // check tricky names if (mNewName == null || mNewName.length() <= 0 || mNewName.contains(File.separator) || mNewName.contains("%")) { return false; @@ -190,6 +212,7 @@ public class MoveFileOperation extends SyncOperation { testFile.delete(); return result; + */ } } diff --git a/src/com/owncloud/android/ui/activity/MoveActivity.java b/src/com/owncloud/android/ui/activity/MoveActivity.java index 69d4d28a..a4686f06 100644 --- a/src/com/owncloud/android/ui/activity/MoveActivity.java +++ b/src/com/owncloud/android/ui/activity/MoveActivity.java @@ -44,6 +44,7 @@ import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.Window; import com.owncloud.android.R; +import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.OwnCloudClient; @@ -364,12 +365,12 @@ public class MoveActivity extends HookActivity implements FileFragment.Container if (v == mCancelBtn) { finish(); } else if (v == mChooseBtn) { - // TODO request to move, OR save selected folder as a result and let request for caller - Toast.makeText( MoveActivity.this, - "TODO: MOVE IMPLEMENTATION", - Toast.LENGTH_LONG) - .show(); - finish(); + ComponentsGetter cg = (ComponentsGetter)getSherlockActivity(); + FileDataStorageManager storageManager = cg.getStorageManager(); + if (storageManager.getFileById(mTargetFile.getFileId()) != null) { + cg.getFileOperationsHelper().removeFile(mTargetFile, false); + } + cg.getFileOperationsHelper.moveFile(m) } }