X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/39c2fffbfee249150da86f541c08f99db2ad1752..185aae4bc345f453479f94e2a78da62e8c9930b0:/src/com/owncloud/android/operations/SynchronizeFileOperation.java diff --git a/src/com/owncloud/android/operations/SynchronizeFileOperation.java b/src/com/owncloud/android/operations/SynchronizeFileOperation.java index 08367c12..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,15 +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.oc_framework.network.webdav.WebdavClient; -import com.owncloud.android.oc_framework.operations.RemoteOperation; -import com.owncloud.android.oc_framework.operations.RemoteOperationResult; -import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode; -import com.owncloud.android.oc_framework.operations.remote.ReadRemoteFileOperation; +import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.resources.files.RemoteFile; +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; @@ -41,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; @@ -57,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(WebdavClient client) { + 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); @@ -89,12 +103,12 @@ public class SynchronizeFileOperation extends RemoteOperation { ReadRemoteFileOperation operation = new ReadRemoteFileOperation(remotePath); result = operation.execute(client); if (result.isSuccess()){ - mServerFile = FileStorageUtils.fillOCFile(result.getData().get(0)); + mServerFile = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0)); mServerFile.setLastSyncDateForProperties(System.currentTimeMillis()); } } - if (result == null) { // true if the server was not checked. nothing was wrong with the remote request + if (mServerFile != null) { /// check changes in server and local file boolean serverChanged = false; @@ -103,7 +117,7 @@ public class SynchronizeFileOperation extends RemoteOperation { serverChanged = (!mServerFile.getEtag().equals(mLocalFile.getEtag())); // TODO could this be dangerous when the user upgrades the server from non-tagged to tagged? } else { */ // server without etags - serverChanged = (mServerFile.getModificationTimestamp() > mLocalFile.getModificationTimestampAtLastSyncForData()); + serverChanged = (mServerFile.getModificationTimestamp() != mLocalFile.getModificationTimestampAtLastSyncForData()); //} boolean localChanged = (mLocalFile.getLocalModificationTimestamp() > mLocalFile.getLastSyncDateForData()); // TODO this will be always true after the app is upgraded to database version 2; will result in unnecessary uploads @@ -134,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);