mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
Merge getFile and getData methods of RemoteOperationResult in a single one
This commit is contained in:
parent
d74d2c7800
commit
f0dd05ddc4
5 changed files with 16 additions and 32 deletions
|
@ -38,9 +38,8 @@ public class ReadFolderTest extends ActivityInstrumentationTestCase2<TestActivit
|
|||
public void testReadFolder() {
|
||||
|
||||
RemoteOperationResult result = mActivity.readFile(mRemoteFolderPath);
|
||||
assertTrue(result.getFile() != null);
|
||||
assertTrue(result.getData().size() > 0);
|
||||
assertTrue(result.getData().size() == 3);
|
||||
assertTrue(result.getData().size() > 1);
|
||||
assertTrue(result.getData().size() == 4);
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -98,13 +98,11 @@ public class RemoteOperationResult implements Serializable {
|
|||
private ResultCode mCode = ResultCode.UNKNOWN_ERROR;
|
||||
private String mRedirectedLocation;
|
||||
|
||||
private RemoteFile mFile;
|
||||
private ArrayList<RemoteFile> 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<RemoteFile> files){
|
||||
mFiles = files;
|
||||
}
|
||||
|
|
|
@ -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<RemoteFile> mFiles;
|
||||
private ArrayList<RemoteFile> 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<RemoteFile>();
|
||||
|
||||
// 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<RemoteFile>();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<RemoteFile> 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<RemoteFile> files, WebdavClient client) {
|
||||
private void synchronizeData(ArrayList<RemoteFile> 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<OCFile> updatedFiles = new Vector<OCFile>(files.size());
|
||||
List<OCFile> updatedFiles = new Vector<OCFile>(folderAndFiles.size() - 1);
|
||||
List<SynchronizeFileOperation> filesToSyncContents = new Vector<SynchronizeFileOperation>();
|
||||
|
||||
// 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<folderAndFiles.size(); i++) {
|
||||
/// new OCFile instance with the data from the server
|
||||
remoteFile = fillOCFile(file);
|
||||
remoteFile = fillOCFile(folderAndFiles.get(i));
|
||||
remoteFile.setParentId(mLocalFolder.getFileId());
|
||||
|
||||
/// retrieve local data for the read file
|
||||
|
|
Loading…
Reference in a new issue