From: masensio Date: Thu, 8 May 2014 15:13:45 +0000 (+0200) Subject: Add CreateFolderOperation to OperationsService X-Git-Tag: oc-android-1.7.0_signed~309^2~39 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/7295820d57a7de182b565f8f0cb6f6faffa52ce8?ds=inline;hp=--cc Add CreateFolderOperation to OperationsService --- 7295820d57a7de182b565f8f0cb6f6faffa52ce8 diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index 406635a2..d037e832 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -232,4 +232,16 @@ public class FileOperationsHelper { mFileActivity.showLoadingDialog(); } + + public void createFolder(String remotePath, boolean createFullPath) { + // Create Folder + Intent service = new Intent(mFileActivity, OperationsService.class); + service.setAction(OperationsService.ACTION_CREATE_FOLDER); + service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); + service.putExtra(OperationsService.EXTRA_REMOTE_PATH, remotePath); + service.putExtra(OperationsService.EXTRA_CREATE_FULL_PATH, createFullPath); + mFileActivity.getOperationsServiceBinder().newOperation(service); + + mFileActivity.showLoadingDialog(); + } } diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index d302e267..08f9d3d4 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -38,6 +38,7 @@ import com.owncloud.android.lib.resources.files.RemoteFile; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.operations.UploadFileOperation; +import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation; import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation; @@ -549,10 +550,8 @@ public class FileUploader extends Service implements OnDatatransferProgressListe RemoteOperation operation = new ExistenceCheckRemoteOperation(pathToGrant, this, false); RemoteOperationResult result = operation.execute(mUploadClient); if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND && mCurrentUpload.isRemoteFolderToBeCreated()) { - operation = new CreateFolderOperation( pathToGrant, - true, - mStorageManager ); - result = operation.execute(mUploadClient); + SyncOperation syncOp = new CreateFolderOperation( pathToGrant, true); + result = syncOp.execute(mUploadClient, mStorageManager); } if (result.isSuccess()) { OCFile parentDir = mStorageManager.getFileByPath(pathToGrant); diff --git a/src/com/owncloud/android/operations/CreateFolderOperation.java b/src/com/owncloud/android/operations/CreateFolderOperation.java index 19e9ddc4..1058a235 100644 --- a/src/com/owncloud/android/operations/CreateFolderOperation.java +++ b/src/com/owncloud/android/operations/CreateFolderOperation.java @@ -1,5 +1,5 @@ /* ownCloud Android client application - * Copyright (C) 2012 ownCloud Inc. + * Copyright (C) 2014 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -17,13 +17,13 @@ package com.owncloud.android.operations; -import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation; import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.utils.FileStorageUtils; import com.owncloud.android.utils.Log_OC; @@ -35,24 +35,21 @@ import com.owncloud.android.utils.Log_OC; * @author David A. Velasco * @author masensio */ -public class CreateFolderOperation extends RemoteOperation implements OnRemoteOperationListener{ +public class CreateFolderOperation extends SyncOperation implements OnRemoteOperationListener{ private static final String TAG = CreateFolderOperation.class.getSimpleName(); protected String mRemotePath; protected boolean mCreateFullPath; - protected FileDataStorageManager mStorageManager; /** * Constructor * * @param createFullPath 'True' means that all the ancestor folders should be created if don't exist yet. - * @param storageManager Reference to the local database corresponding to the account where the file is contained. */ - public CreateFolderOperation(String remotePath, boolean createFullPath, FileDataStorageManager storageManager) { + public CreateFolderOperation(String remotePath, boolean createFullPath) { mRemotePath = remotePath; mCreateFullPath = createFullPath; - mStorageManager = storageManager; } @@ -94,10 +91,10 @@ public class CreateFolderOperation extends RemoteOperation implements OnRemoteOp public void saveFolderInDB() { OCFile newDir = new OCFile(mRemotePath); newDir.setMimetype("DIR"); - long parentId = mStorageManager.getFileByPath(FileStorageUtils.getParentPath(mRemotePath)).getFileId(); + long parentId = getStorageManager().getFileByPath(FileStorageUtils.getParentPath(mRemotePath)).getFileId(); newDir.setParentId(parentId); newDir.setModificationTimestamp(System.currentTimeMillis()); - mStorageManager.saveFile(newDir); + getStorageManager().saveFile(newDir); Log_OC.d(TAG, "Create directory " + mRemotePath + " in Database"); diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index 3a9b3484..c3082d42 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -34,6 +34,7 @@ import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation; import com.owncloud.android.lib.resources.shares.ShareType; import com.owncloud.android.lib.resources.users.GetRemoteUserNameOperation; import com.owncloud.android.operations.common.SyncOperation; +import com.owncloud.android.operations.CreateFolderOperation; import com.owncloud.android.operations.CreateShareOperation; import com.owncloud.android.operations.GetServerInfoOperation; import com.owncloud.android.operations.OAuth2GetAccessToken; @@ -68,6 +69,7 @@ public class OperationsService extends Service { public static final String EXTRA_SEND_INTENT = "SEND_INTENT"; public static final String EXTRA_NEWNAME = "NEWNAME"; public static final String EXTRA_REMOVE_LOCAL_COPY = "REMOVE_LOCAL_COPY"; + public static final String EXTRA_CREATE_FULL_PATH = "CREATE_FULL_PATH"; public static final String EXTRA_RESULT = "RESULT"; // TODO review if ALL OF THEM are necessary @@ -87,17 +89,13 @@ public class OperationsService extends Service { public static final String ACTION_GET_USER_NAME = "GET_USER_NAME"; public static final String ACTION_RENAME = "RENAME"; public static final String ACTION_REMOVE = "REMOVE"; + public static final String ACTION_CREATE_FOLDER = "CREATE_FOLDER"; public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED"; public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED"; private ConcurrentLinkedQueue> mPendingOperations = new ConcurrentLinkedQueue>(); - - /* - private ConcurrentMap mOperationResults = - new ConcurrentHashMap(); - */ private ConcurrentMap> mUndispatchedFinishedOperations = @@ -353,7 +351,14 @@ public class OperationsService extends Service { String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); boolean removeLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_LOCAL_COPY, true); operation = new RemoveFileOperation(remotePath, removeLocalCopy); + + } else if (action.equals(ACTION_CREATE_FOLDER)) { + // Create Folder + String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); + boolean createFullPath = operationIntent.getBooleanExtra(EXTRA_CREATE_FULL_PATH, true); + operation = new CreateFolderOperation(remotePath, createFullPath); } + } } catch (IllegalArgumentException e) { diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 6df94a70..f65a05be 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1424,14 +1424,7 @@ OnSslUntrustedCertListener, EditNameDialogListener { // Create directory path += newDirectoryName + OCFile.PATH_SEPARATOR; - RemoteOperation operation = new CreateFolderOperation(path, false, getStorageManager()); - operation.execute( getAccount(), - FileDisplayActivity.this, - FileDisplayActivity.this, - getHandler(), - FileDisplayActivity.this); - - showLoadingDialog(); + getFileOperationsHelper().createFolder(path, false); } } }