mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
Merge remote-tracking branch 'origin/refactor_remote_operation_to_read_file' into refactor_remote_operation_to_read_file
This commit is contained in:
commit
e6e86b60c5
3 changed files with 19 additions and 30 deletions
|
@ -22,6 +22,7 @@ import java.io.Serializable;
|
|||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.owncloud.android.oc_framework.network.webdav.WebdavEntry;
|
||||
import com.owncloud.android.oc_framework.utils.FileUtils;
|
||||
|
||||
/**
|
||||
|
@ -33,7 +34,7 @@ import com.owncloud.android.oc_framework.utils.FileUtils;
|
|||
public class RemoteFile implements Parcelable, Serializable {
|
||||
|
||||
/** Generated - should be refreshed every time the class changes!! */
|
||||
private static final long serialVersionUID = 7256606476031992757L;
|
||||
private static final long serialVersionUID = 532139091191390616L;
|
||||
|
||||
private String mRemotePath;
|
||||
private String mMimeType;
|
||||
|
@ -108,6 +109,15 @@ public class RemoteFile implements Parcelable, Serializable {
|
|||
}
|
||||
mRemotePath = path;
|
||||
}
|
||||
|
||||
public RemoteFile(WebdavEntry we) {
|
||||
this(we.decodedPath());
|
||||
this.setCreationTimestamp(we.createTimestamp());
|
||||
this.setLength(we.contentLength());
|
||||
this.setMimeType(we.contentType());
|
||||
this.setModifiedTimestamp(we.modifiedTimestamp());
|
||||
this.setEtag(we.etag());
|
||||
}
|
||||
|
||||
/**
|
||||
* Used internally. Reset all file properties
|
||||
|
|
|
@ -31,7 +31,6 @@ import com.owncloud.android.oc_framework.network.webdav.WebdavUtils;
|
|||
import com.owncloud.android.oc_framework.operations.RemoteFile;
|
||||
import com.owncloud.android.oc_framework.operations.RemoteOperation;
|
||||
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.oc_framework.utils.FileUtils;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -79,19 +78,17 @@ public class ReadRemoteFileOperation extends RemoteOperation {
|
|||
|
||||
boolean isMultiStatus = status == HttpStatus.SC_MULTI_STATUS;
|
||||
if (isMultiStatus) {
|
||||
// Parse response
|
||||
MultiStatus resp = propfind.getResponseBodyAsMultiStatus();
|
||||
WebdavEntry we = new WebdavEntry(resp.getResponses()[0], client.getBaseUri().getPath());
|
||||
RemoteFile remoteFile = new RemoteFile(we);
|
||||
ArrayList<RemoteFile> files = new ArrayList<RemoteFile>();
|
||||
files.add(remoteFile);
|
||||
|
||||
// Result of the operation
|
||||
result = new RemoteOperationResult(true, status, propfind.getResponseHeaders());
|
||||
result.setData(files);
|
||||
|
||||
// Add data to the result
|
||||
if (result.isSuccess()) {
|
||||
WebdavEntry we = new WebdavEntry(resp.getResponses()[0], client.getBaseUri().getPath());
|
||||
RemoteFile remoteFile = FileUtils.fillOCFile(we);
|
||||
ArrayList<RemoteFile> files = new ArrayList<RemoteFile>();
|
||||
files.add(remoteFile);
|
||||
result.setData(files);
|
||||
}
|
||||
|
||||
} else {
|
||||
client.exhaustResponse(propfind.getResponseBodyAsStream());
|
||||
result = new RemoteOperationResult(false, status, propfind.getResponseHeaders());
|
||||
|
|
|
@ -19,9 +19,6 @@ package com.owncloud.android.oc_framework.utils;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import com.owncloud.android.oc_framework.network.webdav.WebdavEntry;
|
||||
import com.owncloud.android.oc_framework.operations.RemoteFile;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class FileUtils {
|
||||
|
@ -69,21 +66,6 @@ public class FileUtils {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates and populates a new {@link RemoteFile} object with the data read from the server.
|
||||
*
|
||||
* @param we WebDAV entry read from the server for a WebDAV resource (remote file or folder).
|
||||
* @return New OCFile instance representing the remote resource described by we.
|
||||
*/
|
||||
public static RemoteFile fillOCFile(WebdavEntry we) {
|
||||
RemoteFile file = new RemoteFile(we.decodedPath());
|
||||
file.setCreationTimestamp(we.createTimestamp());
|
||||
file.setLength(we.contentLength());
|
||||
file.setMimeType(we.contentType());
|
||||
file.setModifiedTimestamp(we.modifiedTimestamp());
|
||||
file.setEtag(we.etag());
|
||||
return file;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue