diff --git a/dav4android b/dav4android index ffeb457c..6a5835a9 160000 --- a/dav4android +++ b/dav4android @@ -1 +1 @@ -Subproject commit ffeb457c4df4691aad75a43eaad54a6d8788ee75 +Subproject commit 6a5835a960c4a3d4361a70ef72914b9fa214363d diff --git a/sample_client/src/com/owncloud/android/lib/sampleclient/MainActivity.java b/sample_client/src/com/owncloud/android/lib/sampleclient/MainActivity.java index bf5e4d18..1cb4eb5b 100644 --- a/sample_client/src/com/owncloud/android/lib/sampleclient/MainActivity.java +++ b/sample_client/src/com/owncloud/android/lib/sampleclient/MainActivity.java @@ -24,32 +24,6 @@ package com.owncloud.android.lib.sampleclient; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; -import com.owncloud.android.lib.common.OwnCloudClientFactory; -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.refactor.OCContext; -import com.owncloud.android.lib.refactor.account.OCAccount; -import com.owncloud.android.lib.refactor.authentication.credentials.OwnCloudCredentialsFactory; -import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; -import com.owncloud.android.lib.refactor.OwnCloudContext; -import com.owncloud.android.lib.refactor.operations.PropfindOperation; -import com.owncloud.android.lib.resources.files.RemoteFile; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation; -import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation; -import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation; -import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation; -import com.owncloud.android.lib.resources.files.FileUtils; - import android.app.Activity; import android.content.res.AssetManager; import android.graphics.drawable.BitmapDrawable; @@ -62,6 +36,31 @@ import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; +import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.OwnCloudClientFactory; +import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; +import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; +import com.owncloud.android.lib.common.operations.RemoteOperation; +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.refactor.OCContext; +import com.owncloud.android.lib.refactor.account.OCAccount; +import com.owncloud.android.lib.refactor.authentication.credentials.OwnCloudCredentialsFactory; +import com.owncloud.android.lib.refactor.operations.PropfindOperation; +import com.owncloud.android.lib.refactor.operations.UploadRemoteFileOperation; +import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation; +import com.owncloud.android.lib.resources.files.FileUtils; +import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation; +import com.owncloud.android.lib.resources.files.RemoteFile; +import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + public class MainActivity extends Activity implements OnRemoteOperationListener, OnDatatransferProgressListener { private static String LOG_TAG = MainActivity.class.getCanonicalName(); @@ -165,6 +164,8 @@ public class MainActivity extends Activity implements OnRemoteOperationListener, } private void startUpload() { + + File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path)); File fileToUpload = upFolder.listFiles()[0]; String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName(); @@ -174,9 +175,19 @@ public class MainActivity extends Activity implements OnRemoteOperationListener, Long timeStampLong = fileToUpload.lastModified()/1000; String timeStamp = timeStampLong.toString(); - UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(), remotePath, mimeType, timeStamp); - uploadOperation.addDatatransferProgressListener(this); - uploadOperation.execute(mClient, this, mHandler); + final UploadRemoteFileOperation uploadRemoteFileOperation = new UploadRemoteFileOperation( + mOCContext, + fileToUpload.getAbsolutePath(), + remotePath, + mimeType, + timeStamp + ); + + new Thread(() -> uploadRemoteFileOperation.exec()).start(); + +// UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(), remotePath, mimeType, timeStamp); +// uploadOperation.addDatatransferProgressListener(this); +// uploadOperation.execute(mClient, this, mHandler); } private void startRemoteDeletion() { @@ -219,8 +230,8 @@ public class MainActivity extends Activity implements OnRemoteOperationListener, } else if (operation instanceof ReadRemoteFolderOperation) { onSuccessfulRefresh((ReadRemoteFolderOperation)operation, result); - } else if (operation instanceof UploadRemoteFileOperation ) { - onSuccessfulUpload((UploadRemoteFileOperation)operation, result); + } else if (operation instanceof com.owncloud.android.lib.resources.files.UploadRemoteFileOperation) { + onSuccessfulUpload((com.owncloud.android.lib.resources.files.UploadRemoteFileOperation)operation, result); } else if (operation instanceof RemoveRemoteFileOperation ) { onSuccessfulRemoteDeletion((RemoveRemoteFileOperation)operation, result); @@ -249,7 +260,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener, mFilesAdapter.notifyDataSetChanged(); } - private void onSuccessfulUpload(UploadRemoteFileOperation operation, RemoteOperationResult result) { + private void onSuccessfulUpload(com.owncloud.android.lib.resources.files.UploadRemoteFileOperation operation, RemoteOperationResult result) { startRefresh(); } diff --git a/src/com/owncloud/android/lib/refactor/operations/PropfindOperation.java b/src/com/owncloud/android/lib/refactor/operations/PropfindOperation.java index 07ccfc35..2b4d074b 100644 --- a/src/com/owncloud/android/lib/refactor/operations/PropfindOperation.java +++ b/src/com/owncloud/android/lib/refactor/operations/PropfindOperation.java @@ -1,3 +1,27 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2018 ownCloud GmbH. + * + * 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 com.owncloud.android.lib.refactor.operations; import com.owncloud.android.lib.refactor.OCContext; @@ -13,7 +37,6 @@ public class PropfindOperation extends RemoteOperation { public PropfindOperation(OCContext context, String remotePath) { super(context); - mRemotePath = remotePath; } diff --git a/src/com/owncloud/android/lib/refactor/operations/PutOperation.java b/src/com/owncloud/android/lib/refactor/operations/PutOperation.java deleted file mode 100644 index 76c453ff..00000000 --- a/src/com/owncloud/android/lib/refactor/operations/PutOperation.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.owncloud.android.lib.refactor.operations; - -import com.owncloud.android.lib.refactor.OCContext; -import com.owncloud.android.lib.refactor.RemoteOperation; -import com.owncloud.android.lib.refactor.RemoteOperationResult; - -import at.bitfire.dav4android.DavOCResource; -import at.bitfire.dav4android.DavResource; -import at.bitfire.dav4android.PropertyUtils; -import okhttp3.MediaType; -import okhttp3.RequestBody; - -public class PutOperation extends RemoteOperation { - - private String mRemotePath; - private String mMimeType; - private String mTimeStamp; - - public PutOperation(OCContext context, String remotePath, String mimetype, String timestamp) { - super(context); - - mRemotePath = remotePath; - mMimeType = mimetype; - mTimeStamp = timestamp; - } - - @Override - public RemoteOperationResult exec() { - - try { - - MediaType mediaType = MediaType.parse(mMimeType); - RequestBody requestBody = RequestBody.create(mediaType, mRemotePath); - - DavOCResource davOCResource = new DavOCResource(getClient(), getWebDavHttpUrl(mRemotePath), null); - - - } catch (Exception e) { - e.printStackTrace(); - } - - return null; - } -} \ No newline at end of file diff --git a/src/com/owncloud/android/lib/refactor/operations/UploadRemoteFileOperation.java b/src/com/owncloud/android/lib/refactor/operations/UploadRemoteFileOperation.java new file mode 100644 index 00000000..84bdac14 --- /dev/null +++ b/src/com/owncloud/android/lib/refactor/operations/UploadRemoteFileOperation.java @@ -0,0 +1,81 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2018 ownCloud GmbH. + * + * 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 com.owncloud.android.lib.refactor.operations; + +import com.owncloud.android.lib.refactor.OCContext; +import com.owncloud.android.lib.refactor.RemoteOperation; +import com.owncloud.android.lib.refactor.RemoteOperationResult; + +import java.io.File; + +import at.bitfire.dav4android.DavOCResource; +import okhttp3.MediaType; +import okhttp3.RequestBody; + +public class UploadRemoteFileOperation extends RemoteOperation { + + private String mLocalPath; + private String mRemotePath; + private String mMimeType; + private String mFileLastModifTimestamp; + + public UploadRemoteFileOperation(OCContext context, String localPath, String remotePath, String mimetype, + String fileLastModifTimestamp) { + super(context); + + mLocalPath = localPath; + mRemotePath = remotePath; + mMimeType = mimetype; + mFileLastModifTimestamp = fileLastModifTimestamp; + } + + @Override + public RemoteOperationResult exec() { + + try { + + File fileToUpload = new File(mLocalPath); + MediaType mediaType = MediaType.parse(mMimeType); + RequestBody requestBody = RequestBody.create(mediaType, fileToUpload); + + DavOCResource davOCResource = new DavOCResource( + getClient(), + getWebDavHttpUrl(mRemotePath), + null); + + davOCResource.put(requestBody, + null, + false, + "multipart/form-data", + String.valueOf(fileToUpload.length()), + mFileLastModifTimestamp); + + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } +} \ No newline at end of file