Skip to content

Commit

Permalink
use localID everywhere, it is now long instead of String
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed Jul 7, 2021
1 parent 44d25ee commit bcce961
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ public class GetActivitiesRemoteOperation extends RemoteOperation {

private int lastGiven = -1;

private String fileId = "";
private long fileId = -1;

public GetActivitiesRemoteOperation() {
}

public GetActivitiesRemoteOperation(String fileId) {
public GetActivitiesRemoteOperation(long fileId) {
this.fileId = fileId;
}
public GetActivitiesRemoteOperation(String fileId, int lastGiven) {

public GetActivitiesRemoteOperation(long fileId, int lastGiven) {
this.fileId = fileId;
this.lastGiven = lastGiven;
}
Expand All @@ -102,7 +102,7 @@ public RemoteOperationResult run(NextcloudClient client) {
String url = client.getBaseUri() + OCS_ROUTE_V12_AND_UP;

// add filter for fileId, if available
if (!fileId.isEmpty()) {
if (fileId > 0) {
url = url + "/filter";
}

Expand All @@ -119,10 +119,10 @@ public RemoteOperationResult run(NextcloudClient client) {
parameters.put("since", String.valueOf(lastGiven));
}

if (!fileId.isEmpty()) {
if (fileId > 0) {
parameters.put("sort", "desc");
parameters.put("object_type", "files");
parameters.put("object_id", fileId);
parameters.put("object_id", String.valueOf(fileId));
}

get.setQueryString(parameters);
Expand Down Expand Up @@ -172,7 +172,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
String url = client.getBaseUri() + OCS_ROUTE_V12_AND_UP;

// add filter for fileId, if available
if (!fileId.isEmpty()) {
if (fileId > 0) {
url = url + "/filter";
}

Expand All @@ -190,10 +190,10 @@ protected RemoteOperationResult run(OwnCloudClient client) {
parameters.add(new NameValuePair("since", String.valueOf(lastGiven)));
}

if (!fileId.isEmpty()) {
if (fileId > 0) {
parameters.add(new NameValuePair("sort", "desc"));
parameters.add(new NameValuePair("object_type", "files"));
parameters.add(new NameValuePair("object_id", fileId));
parameters.add(new NameValuePair("object_id", String.valueOf(fileId)));
}

get.setQueryString(parameters.toArray(new NameValuePair[]{}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ public class CommentFileRemoteOperation extends RemoteOperation {
private static final String VERB_VALUE = "comment";
private static final String MESSAGE = "message";

private String message;
private String fileId;
private final String message;
private final long fileId;

/**
* Constructor
*
* @param message Comment to store
*/
public CommentFileRemoteOperation(String message, String fileId) {
public CommentFileRemoteOperation(String message, long fileId) {
this.message = message;
this.fileId = fileId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
public class MarkCommentsAsReadRemoteOperation extends RemoteOperation {
private static final String COMMENTS_URL = "/comments/files/";

private String fileId;
private final long fileId;

public MarkCommentsAsReadRemoteOperation(String fileId) {
public MarkCommentsAsReadRemoteOperation(long fileId) {
this.fileId = fileId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@

import java.util.ArrayList;

import androidx.annotation.NonNull;

/**
* Remote operation performing the read of remote trashbin folder on Nextcloud server.
*/
Expand All @@ -53,16 +51,16 @@ public class ReadFileVersionsRemoteOperation extends RemoteOperation {

private static final String TAG = ReadFileVersionsRemoteOperation.class.getSimpleName();

private String fileId;
private final long localId;
private ArrayList<Object> versions;

/**
* Constructor
*
* @param fileId FileId of the file.
*/
public ReadFileVersionsRemoteOperation(@NonNull String fileId) {
this.fileId = fileId;
public ReadFileVersionsRemoteOperation(long fileId) {
this.localId = fileId;
}

/**
Expand All @@ -76,7 +74,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
PropFindMethod query = null;

try {
String uri = client.getNewWebdavUri() + "/versions/" + client.getUserId() + "/versions/" + fileId;
String uri = client.getNewWebdavUri() + "/versions/" + client.getUserId() + "/versions/" + localId;
DavPropertyNameSet propSet = WebdavUtils.getFileVersionPropSet();

query = new PropFindMethod(uri, propSet, DavConstants.DEPTH_1);
Expand Down Expand Up @@ -109,16 +107,16 @@ protected RemoteOperationResult run(OwnCloudClient client) {

if (result == null) {
result = new RemoteOperationResult(new Exception("unknown error"));
Log_OC.e(TAG, "Synchronized file with id " + fileId + ": failed");
Log_OC.e(TAG, "Synchronized file with id " + localId + ": failed");
} else {
if (result.isSuccess()) {
Log_OC.i(TAG, "Synchronized file with id " + fileId + ": " + result.getLogMessage());
Log_OC.i(TAG, "Synchronized file with id " + localId + ": " + result.getLogMessage());
} else {
if (result.isException()) {
Log_OC.e(TAG, "Synchronized with id " + fileId + ": " + result.getLogMessage(),
result.getException());
Log_OC.e(TAG, "Synchronized with id " + localId + ": " + result.getLogMessage(),
result.getException());
} else {
Log_OC.w(TAG, "Synchronized with id " + fileId + ": " + result.getLogMessage());
Log_OC.w(TAG, "Synchronized with id " + localId + ": " + result.getLogMessage());
}
}
}
Expand All @@ -141,7 +139,7 @@ private void readData(MultiStatus remoteData, OwnCloudClient client) {

// loop to update every child
for (int i = 1; i < remoteData.getResponses().length; ++i) {
versions.add(new FileVersion(fileId, new WebdavEntry(remoteData.getResponses()[i], splitElement)));
versions.add(new FileVersion(localId, new WebdavEntry(remoteData.getResponses()[i], splitElement)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ public class RestoreFileVersionRemoteOperation extends RemoteOperation {
private static final int RESTORE_READ_TIMEOUT = 30000;
private static final int RESTORE_CONNECTION_TIMEOUT = 5000;

private String fileId;
private String fileName;
private final long fileId;
private final String fileName;

/**
* Constructor
*
* @param fileId fileId
* @param fileName version date in unixtime
*/
public RestoreFileVersionRemoteOperation(String fileId, String fileName) {
public RestoreFileVersionRemoteOperation(long fileId, String fileName) {
this.fileId = fileId;
this.fileName = fileName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class FileVersion implements Parcelable, ServerFileInterface {
@Getter @Setter private String mimeType;
@Getter @Setter private long fileLength;
@Getter @Setter private long modifiedTimestamp;
@Getter private String remoteId;
@Getter private long localId;

@Override
public boolean isFavorite() {
Expand All @@ -68,12 +68,9 @@ public String getRemotePath() {
return "";
}

/**
* For file version this is the same as remoteId
*/
@Override
public String getLocalId() {
return getRemoteId();
public String getImageKey() {
return String.valueOf(localId);
}

public boolean isFolder() {
Expand All @@ -84,8 +81,8 @@ public boolean isHidden() {
return getFileName().startsWith(".");
}

public FileVersion(String fileId, WebdavEntry we) {
remoteId = fileId;
public FileVersion(long fileId, WebdavEntry we) {
localId = fileId;
setMimeType(we.getContentType());

if (isFolder()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ public interface ServerFileInterface {

String getRemotePath();

String getLocalId();

String getRemoteId();
String getImageKey();

boolean isFavorite();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ public class TrashbinFile implements Parcelable, Serializable, ServerFileInterfa
private String originalLocation;
private long deletionTimestamp;

/**
* For trashbin this is the same as remoteId
*/
@Override
public String getLocalId() {
return getRemoteId();
}

@Override
public boolean isFolder() {
return DIRECTORY.equals(mimeType);
Expand All @@ -78,14 +70,19 @@ public boolean isHidden() {
return getFileName().startsWith(".");
}

@Override
public String getImageKey() {
return remoteId;
}

@Override
public boolean isFavorite() {
return false;
}

public TrashbinFile(WebdavEntry we, String userId) {
String path = we.decodedPath();

if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) {
throw new IllegalArgumentException("Trying to create a TrashbinFile with a non valid remote path: " + path);
}
Expand Down

0 comments on commit bcce961

Please sign in to comment.