X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/c6edcab5a2f81773f05b8f796f2c356c2c2aeb4d..60d26d53f6dee0fa3724f583bf799ea046bb1ab7:/src/com/owncloud/android/files/FileOperationsHelper.java diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index b7dc67f0..e1ab1953 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -29,18 +29,16 @@ import android.widget.Toast; import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; +import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.lib.common.accounts.AccountUtils.Constants; import com.owncloud.android.lib.common.network.WebdavUtils; -import com.owncloud.android.lib.common.operations.RemoteOperation; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.OwnCloudVersion; -import com.owncloud.android.operations.RemoveFileOperation; -import com.owncloud.android.operations.RenameFileOperation; -import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.services.OperationsService; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.dialog.ShareLinkToDialog; -import com.owncloud.android.utils.Log_OC; /** * @@ -54,6 +52,9 @@ public class FileOperationsHelper { private static final String FTAG_CHOOSER_DIALOG = "CHOOSER_DIALOG"; protected FileActivity mFileActivity = null; + + /// Identifier of operation in progress which result shouldn't be lost + private long mWaitingForOpId = Long.MAX_VALUE; public FileOperationsHelper(FileActivity fileActivity) { mFileActivity = fileActivity; @@ -126,7 +127,7 @@ public class FileOperationsHelper { service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); service.putExtra(OperationsService.EXTRA_SEND_INTENT, sendIntent); - mFileActivity.getOperationsServiceBinder().newOperation(service); + mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service); } else { Log_OC.wtf(TAG, "Trying to open a NULL OCFile"); @@ -164,7 +165,7 @@ public class FileOperationsHelper { service.setAction(OperationsService.ACTION_UNSHARE); service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); - mFileActivity.getOperationsServiceBinder().newOperation(service); + mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service); mFileActivity.showLoadingDialog(); @@ -196,53 +197,102 @@ public class FileOperationsHelper { public void syncFile(OCFile file) { - Account account = mFileActivity.getAccount(); - RemoteOperation operation = new SynchronizeFileOperation( - file, - null, - mFileActivity.getStorageManager(), - account, - true, - mFileActivity); - operation.execute(account, mFileActivity, mFileActivity, mFileActivity.getHandler(), mFileActivity); + // Sync file + Intent service = new Intent(mFileActivity, OperationsService.class); + service.setAction(OperationsService.ACTION_SYNC_FILE); + service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); + service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); + service.putExtra(OperationsService.EXTRA_SYNC_FILE_CONTENTS, true); + mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service); + mFileActivity.showLoadingDialog(); } public void renameFile(OCFile file, String newFilename) { - Account account = mFileActivity.getAccount(); - RemoteOperation operation = new RenameFileOperation( - file, - account, - newFilename, - mFileActivity.getStorageManager()); - - operation.execute( - account, - mFileActivity, - mFileActivity, - mFileActivity.getHandler(), - mFileActivity); + // RenameFile + Intent service = new Intent(mFileActivity, OperationsService.class); + service.setAction(OperationsService.ACTION_RENAME); + service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); + service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); + service.putExtra(OperationsService.EXTRA_NEWNAME, newFilename); + mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service); mFileActivity.showLoadingDialog(); } - public void removeFile(OCFile file, boolean removeLocalCopy) { - Account account = mFileActivity.getAccount(); - RemoteOperation operation = new RemoveFileOperation( - file, - removeLocalCopy, - mFileActivity.getStorageManager()); + public void removeFile(OCFile file, boolean onlyLocalCopy) { + // RemoveFile + Intent service = new Intent(mFileActivity, OperationsService.class); + service.setAction(OperationsService.ACTION_REMOVE); + service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); + service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); + service.putExtra(OperationsService.EXTRA_REMOVE_ONLY_LOCAL, onlyLocalCopy); + mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service); - operation.execute( - account, - mFileActivity, - mFileActivity, - mFileActivity.getHandler(), - mFileActivity); + 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); + mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service); mFileActivity.showLoadingDialog(); } + + + public void cancelTransference(OCFile file) { + Account account = mFileActivity.getAccount(); + FileDownloaderBinder downloaderBinder = mFileActivity.getFileDownloaderBinder(); + FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder(); + if (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) { + // Remove etag for parent, if file is a keep_in_sync + if (file.keepInSync()) { + OCFile parent = mFileActivity.getStorageManager().getFileById(file.getParentId()); + parent.setEtag(""); + mFileActivity.getStorageManager().saveFile(parent); + } + + downloaderBinder.cancel(account, file); + + } else if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) { + uploaderBinder.cancel(account, file); + } + } + + /** + * Start move file operation + * @param newfile File where it is going to be moved + * @param currentFile File with the previous info + */ + public void moveFile(OCFile newfile, OCFile currentFile) { + // Move files + Intent service = new Intent(mFileActivity, OperationsService.class); + service.setAction(OperationsService.ACTION_MOVE_FILE); + service.putExtra(OperationsService.EXTRA_NEW_PARENT_PATH, newfile.getRemotePath()); + service.putExtra(OperationsService.EXTRA_REMOTE_PATH, currentFile.getRemotePath()); + service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); + mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service); + + mFileActivity.showLoadingDialog(); + } + + + public long getOpIdWaitingFor() { + return mWaitingForOpId; + } + + + public void setOpIdWaitingFor(long waitingForOpId) { + mWaitingForOpId = waitingForOpId; + } + }