From: masensio Date: Mon, 12 May 2014 10:54:28 +0000 (+0200) Subject: Move execution of 'refresh file' operation to OperationsService X-Git-Tag: oc-android-1.7.0_signed~309^2~32 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/df4ae2eb352abf968a03ff3e4646a641db33ed8f?hp=-c Move execution of 'refresh file' operation to OperationsService --- df4ae2eb352abf968a03ff3e4646a641db33ed8f diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index c596ed93..022cbec1 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -19,7 +19,6 @@ package com.owncloud.android.files; import org.apache.http.protocol.HTTP; -import android.accounts.Account; import android.accounts.AccountManager; import android.content.Intent; import android.net.Uri; @@ -32,9 +31,7 @@ import com.owncloud.android.datamodel.OCFile; 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.resources.status.OwnCloudVersion; -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; @@ -194,15 +191,14 @@ 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); + mFileActivity.getOperationsServiceBinder().newOperation(service); + mFileActivity.showLoadingDialog(); } diff --git a/src/com/owncloud/android/files/OwnCloudFileObserver.java b/src/com/owncloud/android/files/OwnCloudFileObserver.java index d5a42b5e..551bc25f 100644 --- a/src/com/owncloud/android/files/OwnCloudFileObserver.java +++ b/src/com/owncloud/android/files/OwnCloudFileObserver.java @@ -1,6 +1,6 @@ /* ownCloud Android client application * Copyright (C) 2012 Bartek Przybylski - * Copyright (C) 2012-2013 ownCloud Inc. + * Copyright (C) 2012-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, @@ -91,11 +91,10 @@ public class OwnCloudFileObserver extends FileObserver { // again, assuming that local files are linked to a remote file AT MOST, SOMETHING TO BE DONE; SynchronizeFileOperation sfo = new SynchronizeFileOperation(file, null, - storageManager, mOCAccount, true, mContext); - RemoteOperationResult result = sfo.execute(mOCAccount, mContext); + RemoteOperationResult result = sfo.execute(storageManager, mContext); if (result.getCode() == ResultCode.SYNC_CONFLICT) { // ISSUE 5: if the user is not running the app (this is a service!), this can be very intrusive; a notification should be preferred Intent i = new Intent(mContext, ConflictsResolveActivity.class); diff --git a/src/com/owncloud/android/operations/SynchronizeFileOperation.java b/src/com/owncloud/android/operations/SynchronizeFileOperation.java index 7189167d..1614ba1c 100644 --- a/src/com/owncloud/android/operations/SynchronizeFileOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFileOperation.java @@ -1,6 +1,6 @@ /* ownCloud Android client application * Copyright (C) 2012 Bartek Przybylski - * Copyright (C) 2012-2013 ownCloud Inc. + * Copyright (C) 2012-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, @@ -18,16 +18,15 @@ package com.owncloud.android.operations; -import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.lib.common.OwnCloudClient; 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.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation; +import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.utils.FileStorageUtils; import com.owncloud.android.utils.Log_OC; @@ -42,13 +41,13 @@ import android.content.Intent; * @author masensio */ -public class SynchronizeFileOperation extends RemoteOperation { +public class SynchronizeFileOperation extends SyncOperation { private String TAG = SynchronizeFileOperation.class.getSimpleName(); private OCFile mLocalFile; + private String mRemotePath; private OCFile mServerFile; - private FileDataStorageManager mStorageManager; private Account mAccount; private boolean mSyncFileContents; private Context mContext; @@ -58,25 +57,39 @@ public class SynchronizeFileOperation extends RemoteOperation { public SynchronizeFileOperation( OCFile localFile, OCFile serverFile, // make this null to let the operation checks the server; added to reuse info from SynchronizeFolderOperation - FileDataStorageManager storageManager, Account account, boolean syncFileContents, Context context) { mLocalFile = localFile; mServerFile = serverFile; - mStorageManager = storageManager; mAccount = account; mSyncFileContents = syncFileContents; mContext = context; } + public SynchronizeFileOperation( + String remotePath, + Account account, + boolean syncFileContents, + Context context) { + + mRemotePath = remotePath; + mServerFile = null; + mAccount = account; + mSyncFileContents = syncFileContents; + mContext = context; + } @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; mTransferWasRequested = false; + + // Get local file from the DB + mLocalFile = getStorageManager().getFileByPath(mRemotePath); + if (!mLocalFile.isDown()) { /// easy decision requestForDownload(mLocalFile); @@ -135,7 +148,7 @@ public class SynchronizeFileOperation extends RemoteOperation { mServerFile.setLastSyncDateForData(mLocalFile.getLastSyncDateForData()); mServerFile.setStoragePath(mLocalFile.getStoragePath()); mServerFile.setParentId(mLocalFile.getParentId()); - mStorageManager.saveFile(mServerFile); + getStorageManager().saveFile(mServerFile); } result = new RemoteOperationResult(ResultCode.OK); diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index 68e78578..a8e230d5 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -1,5 +1,5 @@ /* ownCloud Android client application - * Copyright (C) 2012-2013 ownCloud Inc. + * Copyright (C) 2012-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, @@ -350,11 +350,11 @@ public class SynchronizeFolderOperation extends RemoteOperation { if (remoteFile.keepInSync()) { SynchronizeFileOperation operation = new SynchronizeFileOperation( localFile, remoteFile, - mStorageManager, - mAccount, + mAccount, true, mContext ); + filesToSyncContents.add(operation); } @@ -382,7 +382,7 @@ public class SynchronizeFolderOperation extends RemoteOperation { private void startContentSynchronizations(List filesToSyncContents, OwnCloudClient client) { RemoteOperationResult contentsResult = null; for (SynchronizeFileOperation op: filesToSyncContents) { - contentsResult = op.execute(client); // returns without waiting for upload or download finishes + contentsResult = op.execute(mStorageManager, mContext); // returns without waiting for upload or download finishes if (!contentsResult.isSuccess()) { if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) { mConflictsFound++; diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index 0bed2399..eeda5e9d 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -40,6 +40,7 @@ import com.owncloud.android.operations.GetServerInfoOperation; import com.owncloud.android.operations.OAuth2GetAccessToken; import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.RenameFileOperation; +import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.UnshareLinkOperation; import com.owncloud.android.utils.Log_OC; @@ -70,6 +71,7 @@ public class OperationsService extends Service { public static final String EXTRA_NEWNAME = "NEWNAME"; public static final String EXTRA_REMOVE_ONLY_LOCAL = "REMOVE_LOCAL_COPY"; public static final String EXTRA_CREATE_FULL_PATH = "CREATE_FULL_PATH"; + public static final String EXTRA_SYNC_FILE_CONTENTS = "SYNC_FILE_CONTENTS"; public static final String EXTRA_RESULT = "RESULT"; // TODO review if ALL OF THEM are necessary @@ -90,6 +92,7 @@ public class OperationsService extends Service { 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_SYNC_FILE = "SYNC_FILE"; public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED"; public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED"; @@ -357,6 +360,12 @@ public class OperationsService extends Service { String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); boolean createFullPath = operationIntent.getBooleanExtra(EXTRA_CREATE_FULL_PATH, true); operation = new CreateFolderOperation(remotePath, createFullPath); + + } else if (action.equals(ACTION_SYNC_FILE)) { + // Sync file + String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); + boolean syncFileContents = operationIntent.getBooleanExtra(EXTRA_SYNC_FILE_CONTENTS, true); + operation = new SynchronizeFileOperation(remotePath, account, syncFileContents, getApplicationContext()); } }