mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 16:36:13 +00:00
Create RemoveRemoteFileOperation and use it
This commit is contained in:
parent
81120ac7ad
commit
74c9430382
@ -1,5 +1,5 @@
|
||||
/* ownCloud Android Library is available under MIT license
|
||||
* Copyright (C) 2016 ownCloud GmbH.
|
||||
* 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
|
||||
@ -47,11 +47,11 @@ import com.owncloud.android.lib.refactor.account.OCAccount;
|
||||
import com.owncloud.android.lib.refactor.authentication.credentials.OwnCloudCredentialsFactory;
|
||||
import com.owncloud.android.lib.refactor.resources.files.DownloadRemoteFileOperation;
|
||||
import com.owncloud.android.lib.refactor.resources.files.PropfindOperation;
|
||||
import com.owncloud.android.lib.refactor.resources.files.RemoveRemoteFileOperation;
|
||||
import com.owncloud.android.lib.refactor.resources.files.UploadRemoteFileOperation;
|
||||
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;
|
||||
@ -167,7 +167,10 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
|
||||
for(DavResource el : result.getData().getMembers()) {
|
||||
remoteFiles.add(new RemoteFile(el));
|
||||
}
|
||||
handler.post(() -> mFilesAdapter.addAll(remoteFiles));
|
||||
handler.post(() -> {
|
||||
mFilesAdapter.clear();
|
||||
mFilesAdapter.addAll(remoteFiles);
|
||||
});
|
||||
}).start();
|
||||
// ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR);
|
||||
// refreshOperation.execute(mClient, this, mHandler);
|
||||
@ -210,11 +213,30 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
|
||||
}
|
||||
|
||||
private void startRemoteDeletion() {
|
||||
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||
File fileToUpload = upFolder.listFiles()[0];
|
||||
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
|
||||
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
|
||||
removeOperation.execute(mClient, this, mHandler);
|
||||
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
|
||||
File fileToUpload = upFolder.listFiles()[0];
|
||||
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
|
||||
|
||||
final RemoveRemoteFileOperation removeRemoteFileOperation = new RemoveRemoteFileOperation(
|
||||
mOCContext,
|
||||
remotePath
|
||||
);
|
||||
final Handler handler = new Handler();
|
||||
|
||||
new Thread(() -> {
|
||||
final RemoveRemoteFileOperation.Result result = removeRemoteFileOperation.exec();
|
||||
if (!result.isSuccess()) {
|
||||
handler.post(() ->
|
||||
Toast.makeText(this, result.getLogMessage(), Toast.LENGTH_LONG).show());
|
||||
return;
|
||||
}
|
||||
handler.post(() ->
|
||||
Toast.makeText(this, "Delete successful", Toast.LENGTH_LONG).show());
|
||||
}).start();
|
||||
|
||||
|
||||
// RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
|
||||
// removeOperation.execute(mClient, this, mHandler);
|
||||
}
|
||||
|
||||
private void startDownload() {
|
||||
@ -272,9 +294,9 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
|
||||
} 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);
|
||||
|
||||
// } else if (operation instanceof RemoveRemoteFileOperation ) {
|
||||
// onSuccessfulRemoteDeletion((RemoveRemoteFileOperation)operation, result);
|
||||
//
|
||||
// } else if (operation instanceof DownloadRemoteFileOperation ) {
|
||||
// onSuccessfulDownload((DownloadRemoteFileOperation)operation, result);
|
||||
|
||||
|
@ -52,8 +52,8 @@ public abstract class RemoteOperation<I extends Object> {
|
||||
}
|
||||
|
||||
|
||||
protected RemoteOperation(OCContext context) {
|
||||
mContext = context;
|
||||
protected RemoteOperation(OCContext ocContext) {
|
||||
mContext = ocContext;
|
||||
if(mClient == null) {
|
||||
mClient = new OkHttpClient.Builder()
|
||||
.followRedirects(false)
|
||||
|
@ -29,6 +29,10 @@ import at.bitfire.dav4android.DavOCResource;
|
||||
import static com.owncloud.android.lib.refactor.operations.RemoteOperationResult.ResultCode.OK;
|
||||
|
||||
/**
|
||||
* Remote operation performing the download of a remote file in the ownCloud server.
|
||||
*
|
||||
* @author David A. Velasco
|
||||
* @author masensio
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
public class DownloadRemoteFileOperation extends RemoteOperation<Void> {
|
||||
@ -52,7 +56,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation<Void> {
|
||||
);
|
||||
davOCResource.get("*/*");
|
||||
|
||||
//TODO Create local file from the downloaded one
|
||||
//TODO Create local file from the downloaded one and implement progress listener
|
||||
|
||||
return new Result(OK);
|
||||
|
||||
|
@ -0,0 +1,65 @@
|
||||
/* 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.resources.files;
|
||||
|
||||
import com.owncloud.android.lib.refactor.OCContext;
|
||||
import com.owncloud.android.lib.refactor.operations.RemoteOperation;
|
||||
import at.bitfire.dav4android.DavOCResource;
|
||||
|
||||
import static com.owncloud.android.lib.refactor.operations.RemoteOperationResult.ResultCode.OK;
|
||||
|
||||
/**
|
||||
* Remote operation performing the removal of a remote file or folder in the ownCloud server.
|
||||
*
|
||||
* @author David A. Velasco
|
||||
* @author masensio
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
public class RemoveRemoteFileOperation extends RemoteOperation<Void> {
|
||||
|
||||
private String mRemotePath;
|
||||
|
||||
public RemoveRemoteFileOperation(OCContext ocContext, String remotePath) {
|
||||
super(ocContext);
|
||||
|
||||
mRemotePath = remotePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result exec() {
|
||||
try {
|
||||
DavOCResource davOCResource = new DavOCResource(
|
||||
getClient(),
|
||||
getWebDavHttpUrl(mRemotePath)
|
||||
);
|
||||
davOCResource.delete(null);
|
||||
|
||||
return new Result(OK);
|
||||
|
||||
} catch (Exception e) {
|
||||
return new Result(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -38,6 +38,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
*
|
||||
* @author David A. Velasco
|
||||
* @author masensio
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
public class RemoveRemoteFileOperation extends RemoteOperation {
|
||||
private static final String TAG = RemoveRemoteFileOperation.class.getSimpleName();
|
||||
@ -88,5 +89,4 @@ public class RemoveRemoteFileOperation extends RemoteOperation {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user