diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index 34e74166112d7eca22fde53420986cd1f42474bb..0000000000000000000000000000000000000000
--- a/.gitmodules
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "nextcloud-android-lib"]
- path = nextcloud-android-lib
- url = ../nextcloud-android-lib.git
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 0bda024227adbb6b814b990cd47dad42e43e78be..35eb1ddfbbc029bcab630581847471d7f238ec53 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -2,6 +2,5 @@
-
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 6f4aaa57a77417379a15172c3dd7c7c8d8c38d32..30c8f6ee9b2b448f62aeaa32314969aee20fbd2c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -63,9 +63,9 @@ android {
}
-
dependencies {
- api project(':NextcloudLib')
+ implementation 'com.github.nextcloud:android-library:2.10.1'
+ implementation "commons-httpclient:commons-httpclient:3.1@jar"
implementation fileTree(include: ['*.jar'], dir: 'libs')
api 'androidx.annotation:annotation:1.3.0'
implementation 'androidx.core:core:1.6.0'
diff --git a/app/src/main/java/foundation/e/drive/operations/DownloadFileOperation.java b/app/src/main/java/foundation/e/drive/operations/DownloadFileOperation.java
index 4445239c721e7a0ead86a1264ed77327d9b88cde..0142dcdf869f41cfbbac424a14b85f81d8a7c3af 100644
--- a/app/src/main/java/foundation/e/drive/operations/DownloadFileOperation.java
+++ b/app/src/main/java/foundation/e/drive/operations/DownloadFileOperation.java
@@ -13,6 +13,7 @@ import android.util.Log;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import com.owncloud.android.lib.resources.files.DownloadFileRemoteOperation;
import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
import java.io.File;
@@ -28,11 +29,11 @@ public class DownloadFileOperation extends RemoteOperation {
private final static String TAG = DownloadFileOperation.class.getSimpleName();
private final RemoteFile remoteFile;
- private Context context;
- private String targetPath;
+ private final Context context;
+ private final String targetPath;
private int restartCounter =0;
- private SyncedFileState syncedFileState;
- private String previousEtag;
+ private final SyncedFileState syncedFileState;
+ private final String previousEtag;
/**
* COnstructor of download operation where syncedFileState is already known
@@ -50,26 +51,22 @@ public class DownloadFileOperation extends RemoteOperation {
@Override
protected RemoteOperationResult run(OwnCloudClient ownCloudClient) {
Log.i(TAG, "run(ownCloudClient)");
-
- //get or build synced file equivalent of this.mFile
- if (syncedFileState == null || targetPath == null || targetPath.isEmpty()) {
- Log.e(TAG, "syncedFileState or targetPath is empty or null. Can't Download in those conditions");
- return new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN);
- } else if (syncedFileState.getId() == -1) {
+ if (syncedFileState.getId() == -1) {
this.syncedFileState.setId(DbHelper.manageSyncedFileStateDB(this.syncedFileState, "INSERT", context));
}
- if (syncedFileState.getLastETAG().equals(remoteFile.getEtag()) && syncedFileState.getLocalLastModified() > 0L) {
- //Same etag and localLastModified not null mean the file is up to date
+ if (syncedFileState.getLastETAG().equals(remoteFile.getEtag())
+ && syncedFileState.getLocalLastModified() > 0L) { //file is up to date
Log.w(TAG, "File already up-to-date");
return new RemoteOperationResult(RemoteOperationResult.ResultCode.ETAG_UNCHANGED);
}
final String tmpTargetPath = context.getExternalCacheDir()+ FileUtils.PATH_SEPARATOR+ syncedFileState.getName();
+
final DownloadFileRemoteOperation downloadOperation = new DownloadFileRemoteOperation(remoteFile.getRemotePath(),
tmpTargetPath);
-
final RemoteOperationResult downloadResult = downloadOperation.execute(ownCloudClient);
+
RemoteOperationResult.ResultCode resultCode;
boolean mustRestart = true;
@@ -78,32 +75,20 @@ public class DownloadFileOperation extends RemoteOperation {
if (!tmpLocalFile.exists()) {
Log.e(TAG, "Downloaded file doesn't exist or is null");
resultCode = RemoteOperationResult.ResultCode.FILE_NOT_FOUND;
-
} else if (tmpLocalFile.length() != remoteFile.getLength()) {
-
Log.e(TAG, "Local and remote file doesn't have the same size.");
resultCode = RemoteOperationResult.ResultCode.INVALID_OVERWRITE;
tmpLocalFile.delete();
+ } else { //file has been correctly download
- } else {
- //file has been correctly download.
final File localFile = new File(targetPath);
- if (localFile.exists()) {
- localFile.delete();
- }
- //Check parentFolder existence and create if needed
- final String parentFoldersPath = localFile.getParent();
- final File localParentFile = new File(parentFoldersPath);
- if (!localParentFile.exists()) {
- if (localParentFile.mkdirs())
- Log.d(TAG, "Created folders: "+parentFoldersPath);
- else
- Log.d(TAG, "Can't create folders: "+parentFoldersPath);
+ if (localFile.exists()) { localFile.delete(); }
+
+ if (!tmpLocalFile.renameTo(localFile)) {
+ Log.d(TAG, "Can't move " + tmpTargetPath + " to " + targetPath);
+ return new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN);
}
- boolean renameResult = tmpLocalFile.renameTo(localFile);
- if (!renameResult)
- Log.d(TAG, "File hasn't been successfully moved at its place");
syncedFileState.setLocalLastModified(localFile.lastModified())
.setLastETAG(remoteFile.getEtag());
mustRestart = false;
@@ -118,7 +103,7 @@ public class DownloadFileOperation extends RemoteOperation {
}
if (mustRestart) {
- Log.w(TAG, restartCounter+" unsuccessfull trial.s of downloading file "
+ Log.w(TAG, restartCounter+" unsuccessfull trial.s of downloading "
+ remoteFile.getRemotePath());
syncedFileState.setLastETAG(this.previousEtag);
if (this.restartCounter < 3) {
diff --git a/app/src/main/java/foundation/e/drive/operations/DownloadFileRemoteOperation.java b/app/src/main/java/foundation/e/drive/operations/DownloadFileRemoteOperation.java
deleted file mode 100644
index dce9dff620ad4ab620450b046dcd50eb94fb49e5..0000000000000000000000000000000000000000
--- a/app/src/main/java/foundation/e/drive/operations/DownloadFileRemoteOperation.java
+++ /dev/null
@@ -1,180 +0,0 @@
-
-/* ownCloud Android Library is available under MIT license
- * Copyright (C) 2015 ownCloud Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-package foundation.e.drive.operations;
-
-import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.common.network.WebdavUtils;
-import com.owncloud.android.lib.common.operations.OperationCancelledException;
-import com.owncloud.android.lib.common.operations.RemoteOperation;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.lib.common.utils.Log_OC;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.methods.GetMethod;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Date;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * Remote operation performing the download of a remote file in the ownCloud server.
- *
- * @author David A. Velasco
- * @author masensio
- * @author Vincent Bourgmayer
- */
-class DownloadFileRemoteOperation extends RemoteOperation {
- private static final String TAG = DownloadFileRemoteOperation.class.getSimpleName();
-
- private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
- private long mModificationTimestamp = 0;
- private String mEtag = "";
- private GetMethod mGet;
- private final String mRemotePath;
- private final String mLocalFolderPath;
-
- /**
- * Constructor
- * @param remotePath Path of file on the server
- * @param localFolderPath Path of file on the device
- */
- public DownloadFileRemoteOperation(String remotePath, String localFolderPath) {
- mRemotePath = remotePath;
- mLocalFolderPath = localFolderPath;
- }
-
- @Override
- protected RemoteOperationResult run(OwnCloudClient client) {
- RemoteOperationResult result = null;
- /// download will be performed to a temporal file, then moved to the final location
- File tmpFile = new File(getTmpPath());
- /// perform the download
- try {
- tmpFile.getParentFile().mkdirs();
- int status = downloadFile(client, tmpFile);
- result = new RemoteOperationResult(isSuccess(status), mGet);
- Log_OC.i(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " +
- result.getLogMessage());
-
- } catch (Exception e) {
- result = new RemoteOperationResult(e);
- Log_OC.e(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " +
- result.getLogMessage(), e);
- }
-
- return result;
- }
-
- private int downloadFile(OwnCloudClient client, File targetFile) throws IOException, OperationCancelledException {
- int status = -1;
- boolean savedFile = false;
- mGet = new GetMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
-
- FileOutputStream fos = null;
- try {
- status = client.executeMethod(mGet);
- if (isSuccess(status)) {
- targetFile.createNewFile();
- BufferedInputStream bis = new BufferedInputStream(mGet.getResponseBodyAsStream());
- fos = new FileOutputStream(targetFile);
- long transferred = 0;
-
- Header contentLength = mGet.getResponseHeader("Content-Length");
- long totalToTransfer = (contentLength != null &&
- contentLength.getValue().length() > 0) ?
- Long.parseLong(contentLength.getValue()) : 0;
-
- byte[] bytes = new byte[4096];
- int readResult = 0;
- while ((readResult = bis.read(bytes)) != -1) {
- synchronized (mCancellationRequested) {
- if (mCancellationRequested.get()) {
- mGet.abort();
- throw new OperationCancelledException();
- }
- }
- fos.write(bytes, 0, readResult);
- transferred += readResult;
- }
- // Check if the file is completed
- // if transfer-encoding: chunked we cannot check if the file is complete
- Header transferEncodingHeader = mGet.getResponseHeader("Transfer-Encoding");
- boolean transferEncoding = false;
-
- if (transferEncodingHeader != null) {
- transferEncoding = transferEncodingHeader.getValue().equals("chunked");
- }
-
- if (transferred == totalToTransfer || transferEncoding) {
- savedFile = true;
- Header modificationTime = mGet.getResponseHeader("Last-Modified");
- if (modificationTime == null) {
- modificationTime = mGet.getResponseHeader("last-modified");
- }
- if (modificationTime != null) {
- Date d = WebdavUtils.parseResponseDate(modificationTime.getValue());
- mModificationTimestamp = (d != null) ? d.getTime() : 0;
- } else {
- Log_OC.e(TAG, "Could not read modification time from response downloading " + mRemotePath);
- }
-
- mEtag = WebdavUtils.getEtagFromResponse(mGet);
- if (mEtag.length() == 0) {
- Log_OC.e(TAG, "Could not read eTag from response downloading " + mRemotePath);
- }
-
- } else {
- client.exhaustResponse(mGet.getResponseBodyAsStream());
- // TODO some kind of error control!
- }
- } else {
- client.exhaustResponse(mGet.getResponseBodyAsStream());
- }
- } catch (Exception e) {
- Log_OC.e(TAG, e.getMessage());
- } finally {
- if (fos != null) fos.close();
- if (!savedFile && targetFile.exists()) {
- targetFile.delete();
- }
- mGet.releaseConnection(); // let the connection available for other methods
- }
- return status;
- }
-
- private boolean isSuccess(int status) {
- return (status == HttpStatus.SC_OK);
- }
-
- /**
- * IMPLEMENTATION DIFFER FROM NC IMPLEMENTATION
- * @return
- */
- private String getTmpPath() {
- return mLocalFolderPath;
- }
-}
diff --git a/app/src/main/java/foundation/e/drive/operations/GetAliasOperation.java b/app/src/main/java/foundation/e/drive/operations/GetAliasOperation.java
index 4f67f76f95ff326c7810406b8ff375c97ecd5711..7df0b64fae9ab2a7da8ede86a0d9fd2fe6cceacb 100644
--- a/app/src/main/java/foundation/e/drive/operations/GetAliasOperation.java
+++ b/app/src/main/java/foundation/e/drive/operations/GetAliasOperation.java
@@ -24,7 +24,6 @@ import java.util.ArrayList;
/**
* @author TheScarastic
*/
-
public class GetAliasOperation extends RemoteOperation {
private static final String TAG = GetAliasOperation.class.getSimpleName();
@@ -35,14 +34,13 @@ public class GetAliasOperation extends RemoteOperation {
private static final String NODE_DATA = "data";
private static final String NODE_ALIASES = "aliases";
-
private boolean isSuccess(int status) {
return (status == HttpStatus.SC_OK);
}
@Override
- protected RemoteOperationResult run(OwnCloudClient client) {
- RemoteOperationResult result;
+ protected RemoteOperationResult> run(OwnCloudClient client) {
+ RemoteOperationResult> result;
GetMethod get = null;
final String uri = client.getBaseUri() + ALIAS_PATH + client.getCredentials().getUsername();
@@ -52,25 +50,25 @@ public class GetAliasOperation extends RemoteOperation {
get.setQueryString(new NameValuePair[]{new NameValuePair("format", "json")});
if (isSuccess(client.executeMethod(get))) {
- String response = get.getResponseBodyAsString();
+ final String response = get.getResponseBodyAsString();
// parse
final JSONArray aliases = new JSONObject(response).getJSONObject(NODE_OCS)
.getJSONObject(NODE_DATA).getJSONArray(NODE_ALIASES);
- final ArrayList