From f0dd05ddc41ff85b3beda0aba31dddab71324662 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Fri, 29 Nov 2013 10:30:53 +0100 Subject: [PATCH] Merge getFile and getData methods of RemoteOperationResult in a single one --- .../test/ReadFolderTest.java | 5 ++--- .../oc_framework/operations/RemoteFile.java | 2 +- .../operations/RemoteOperationResult.java | 8 -------- .../remote/ReadRemoteFolderOperation.java | 15 ++++++--------- .../operations/SynchronizeFolderOperation.java | 18 +++++++----------- 5 files changed, 16 insertions(+), 32 deletions(-) diff --git a/oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/ReadFolderTest.java b/oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/ReadFolderTest.java index 5bb4c35b43..c339915800 100644 --- a/oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/ReadFolderTest.java +++ b/oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/ReadFolderTest.java @@ -38,9 +38,8 @@ public class ReadFolderTest extends ActivityInstrumentationTestCase2 0); - assertTrue(result.getData().size() == 3); + assertTrue(result.getData().size() > 1); + assertTrue(result.getData().size() == 4); assertTrue(result.isSuccess()); } diff --git a/oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteFile.java b/oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteFile.java index 226f1f43ac..2c1920f000 100644 --- a/oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteFile.java +++ b/oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteFile.java @@ -13,7 +13,7 @@ import com.owncloud.android.oc_framework.utils.FileUtils; * @author masensio */ -public class RemoteFile implements Parcelable, Serializable{ +public class RemoteFile implements Parcelable, Serializable { /** Generated - should be refreshed every time the class changes!! */ private static final long serialVersionUID = 7256606476031992757L; diff --git a/oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteOperationResult.java b/oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteOperationResult.java index 3c650010ce..666e31293e 100644 --- a/oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteOperationResult.java +++ b/oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteOperationResult.java @@ -98,13 +98,11 @@ public class RemoteOperationResult implements Serializable { private ResultCode mCode = ResultCode.UNKNOWN_ERROR; private String mRedirectedLocation; - private RemoteFile mFile; private ArrayList mFiles; public RemoteOperationResult(ResultCode code) { mCode = code; mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL || code == ResultCode.OK_NO_SSL); - mFile= null; mFiles = null; } @@ -201,12 +199,6 @@ public class RemoteOperationResult implements Serializable { } - public void setFile(RemoteFile file){ - mFile = file; - } - public RemoteFile getFile(){ - return mFile; - } public void setData(ArrayList files){ mFiles = files; } diff --git a/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/ReadRemoteFolderOperation.java b/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/ReadRemoteFolderOperation.java index 3a9eb1935e..7bbf7b7f91 100644 --- a/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/ReadRemoteFolderOperation.java +++ b/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/ReadRemoteFolderOperation.java @@ -28,8 +28,7 @@ public class ReadRemoteFolderOperation extends RemoteOperation { private static final String TAG = ReadRemoteFolderOperation.class.getSimpleName(); private String mRemotePath; - private RemoteFile mFolder; - private ArrayList mFiles; + private ArrayList mFolderAndFiles; /** * Constructor @@ -67,8 +66,7 @@ public class ReadRemoteFolderOperation extends RemoteOperation { result = new RemoteOperationResult(true, status, query.getResponseHeaders()); // Add data to the result if (result.isSuccess()) { - result.setFile(mFolder); - result.setData(mFiles); + result.setData(mFolderAndFiles); } } else { // synchronization failed @@ -112,20 +110,19 @@ public class ReadRemoteFolderOperation extends RemoteOperation { * @return */ private void readData(MultiStatus dataInServer, WebdavClient client) { + mFolderAndFiles = new ArrayList(); + // parse data from remote folder WebdavEntry we = new WebdavEntry(dataInServer.getResponses()[0], client.getBaseUri().getPath()); - mFolder = fillOCFile(we); - + mFolderAndFiles.add(fillOCFile(we)); // loop to update every child RemoteFile remoteFile = null; - mFiles = new ArrayList(); for (int i = 1; i < dataInServer.getResponses().length; ++i) { /// new OCFile instance with the data from the server we = new WebdavEntry(dataInServer.getResponses()[i], client.getBaseUri().getPath()); remoteFile = fillOCFile(we); - - mFiles.add(remoteFile); + mFolderAndFiles.add(remoteFile); } } diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index 2fc9d28b84..e93736c424 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -249,9 +249,7 @@ public class SynchronizeFolderOperation extends RemoteOperation { Log_OC.d(TAG, "Synchronizing " + mAccount.name + remotePath); if (result.isSuccess()) { - RemoteFile folder = result.getFile(); - ArrayList files = result.getData(); - synchronizeData(folder, files, client); + synchronizeData(result.getData(), client); if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) { result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); // should be different result, but will do the job } @@ -278,26 +276,24 @@ public class SynchronizeFolderOperation extends RemoteOperation { * * Grants that mChildren is updated with fresh data after execution. * - * @param folder Remote Folder to synchronize - * - * @param files Remote Files in Folder + * @param folderAndFiles Remote folder and children files in Folder * * @param client Client instance to the remote server where the data were * retrieved. * @return 'True' when any change was made in the local data, 'false' otherwise. */ - private void synchronizeData(RemoteFile folder, ArrayList files, WebdavClient client) { + private void synchronizeData(ArrayList folderAndFiles, WebdavClient client) { // get 'fresh data' from the database mLocalFolder = mStorageManager.getFileByPath(mLocalFolder.getRemotePath()); // parse data from remote folder - OCFile remoteFolder = fillOCFile(folder); + OCFile remoteFolder = fillOCFile(folderAndFiles.get(0)); remoteFolder.setParentId(mLocalFolder.getParentId()); remoteFolder.setFileId(mLocalFolder.getFileId()); Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath() + " changed - starting update of local data "); - List updatedFiles = new Vector(files.size()); + List updatedFiles = new Vector(folderAndFiles.size() - 1); List filesToSyncContents = new Vector(); // get current data about local contents of the folder to synchronize @@ -309,9 +305,9 @@ public class SynchronizeFolderOperation extends RemoteOperation { // loop to update every child OCFile remoteFile = null, localFile = null; - for (RemoteFile file: files) { + for (int i=1; i