import org.apache.http.protocol.HTTP;
-import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Intent;
import android.net.Uri;
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;
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();
}
/* 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,
// 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);
/* 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,
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;
* @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;
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);
mServerFile.setLastSyncDateForData(mLocalFile.getLastSyncDateForData());
mServerFile.setStoragePath(mLocalFile.getStoragePath());
mServerFile.setParentId(mLocalFile.getParentId());
- mStorageManager.saveFile(mServerFile);
+ getStorageManager().saveFile(mServerFile);
}
result = new RemoteOperationResult(ResultCode.OK);
/* 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,
if (remoteFile.keepInSync()) {
SynchronizeFileOperation operation = new SynchronizeFileOperation( localFile,
remoteFile,
- mStorageManager,
- mAccount,
+ mAccount,
true,
mContext
);
+
filesToSyncContents.add(operation);
}
private void startContentSynchronizations(List<SynchronizeFileOperation> 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++;
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;
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
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";
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());
}
}