Search in sources :

Example 1 with MoveRemoteFileOperation

use of com.owncloud.android.lib.resources.files.MoveRemoteFileOperation in project android by owncloud.

the class MoveFileOperation method run.

/**
     * Performs the operation.
     * 
     * @param   client      Client object to communicate with the remote ownCloud server.
     */
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result = null;
    /// 1. check move validity
    if (mTargetParentPath.startsWith(mSrcPath)) {
        return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT);
    }
    mFile = getStorageManager().getFileByPath(mSrcPath);
    if (mFile == null) {
        return new RemoteOperationResult(ResultCode.FILE_NOT_FOUND);
    }
    /// 2. remote move
    String targetPath = mTargetParentPath + mFile.getFileName();
    if (mFile.isFolder()) {
        targetPath += OCFile.PATH_SEPARATOR;
    }
    MoveRemoteFileOperation operation = new MoveRemoteFileOperation(mSrcPath, targetPath, false);
    result = operation.execute(client);
    /// 3. local move
    if (result.isSuccess()) {
        // stop observing changes if available offline
        boolean isAvailableOffline = mFile.getAvailableOfflineStatus().equals(OCFile.AvailableOfflineStatus.AVAILABLE_OFFLINE);
        // OCFile.AvailableOfflineStatus.AVAILABLE_OFFLINE_PARENT requires no action
        if (isAvailableOffline) {
            stopObservation();
        }
        getStorageManager().moveLocalFile(mFile, targetPath, mTargetParentPath);
        // adjust available offline status after move resume observation of file after rename
        OCFile updatedFile = getStorageManager().getFileById(mFile.getFileId());
        OCFile.AvailableOfflineStatus updatedAvOffStatus = updatedFile.getAvailableOfflineStatus();
        if (updatedAvOffStatus == OCFile.AvailableOfflineStatus.AVAILABLE_OFFLINE) {
            resumeObservation(targetPath);
        } else if (updatedAvOffStatus == OCFile.AvailableOfflineStatus.AVAILABLE_OFFLINE_PARENT) {
            // enforce ancestor to rescan subfolders for immediate observation
            OCFile ancestor = getStorageManager().getAvailableOfflineAncestorOf(updatedFile);
            FileObserverService.observeFile(MainApp.getAppContext(), ancestor, getStorageManager().getAccount(), true);
        }
    }
    return result;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) MoveRemoteFileOperation(com.owncloud.android.lib.resources.files.MoveRemoteFileOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult)

Aggregations

OCFile (com.owncloud.android.datamodel.OCFile)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 MoveRemoteFileOperation (com.owncloud.android.lib.resources.files.MoveRemoteFileOperation)1