mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 07:56:19 +00:00
Converting RemoveRemoteFileOperation from java to kotlin. Final step.
This commit is contained in:
parent
f706595a9a
commit
62dbdb1021
@ -24,19 +24,18 @@
|
||||
|
||||
package com.owncloud.android.lib.resources.files;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||
import com.owncloud.android.lib.common.http.methods.nonwebdav.DeleteMethod;
|
||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import timber.log.Timber;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK;
|
||||
import android.net.Uri
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
import com.owncloud.android.lib.common.http.HttpConstants.HTTP_NO_CONTENT
|
||||
import com.owncloud.android.lib.common.http.HttpConstants.HTTP_OK
|
||||
import com.owncloud.android.lib.common.http.methods.nonwebdav.DeleteMethod
|
||||
import com.owncloud.android.lib.common.network.WebdavUtils
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode
|
||||
import com.owncloud.android.lib.common.utils.isOneOf
|
||||
import timber.log.Timber
|
||||
import java.net.URL
|
||||
|
||||
/**
|
||||
* Remote operation performing the removal of a remote file or folder in the ownCloud server.
|
||||
@ -44,53 +43,34 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R
|
||||
* @author David A. Velasco
|
||||
* @author masensio
|
||||
* @author David González Verdugo
|
||||
* @author Abel García de Prada
|
||||
*/
|
||||
public class RemoveRemoteFileOperation extends RemoteOperation {
|
||||
private String mRemotePath;
|
||||
|
||||
protected boolean removeChunksFolder = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param remotePath RemotePath of the remote file or folder to remove from the server
|
||||
*/
|
||||
public RemoveRemoteFileOperation(String remotePath) {
|
||||
mRemotePath = remotePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the rename operation.
|
||||
*
|
||||
* @param client Client object to communicate with the remote ownCloud server.
|
||||
*/
|
||||
@Override
|
||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||
RemoteOperationResult result;
|
||||
open class RemoveRemoteFileOperation(
|
||||
private val mRemotePath: String
|
||||
) : RemoteOperation<Unit>() {
|
||||
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> {
|
||||
var result: RemoteOperationResult<Unit>
|
||||
try {
|
||||
Uri srcWebDavUri = removeChunksFolder ? client.getUploadsWebDavUri() : client.getUserFilesWebDavUri();
|
||||
|
||||
DeleteMethod deleteMethod = new DeleteMethod(
|
||||
new URL(srcWebDavUri + WebdavUtils.encodePath(mRemotePath)));
|
||||
|
||||
int status = client.executeHttpMethod(deleteMethod);
|
||||
|
||||
result = isSuccess(status) ?
|
||||
new RemoteOperationResult<>(OK) :
|
||||
new RemoteOperationResult<>(deleteMethod);
|
||||
|
||||
Timber.i("Remove " + mRemotePath + ": " + result.getLogMessage());
|
||||
|
||||
} catch (Exception e) {
|
||||
result = new RemoteOperationResult<>(e);
|
||||
Timber.e(e, "Remove " + mRemotePath + ": " + result.getLogMessage());
|
||||
val srcWebDavUri = getSrcWebDavUriForClient(client)
|
||||
val deleteMethod = DeleteMethod(
|
||||
URL(srcWebDavUri.toString() + WebdavUtils.encodePath(mRemotePath))
|
||||
)
|
||||
val status = client.executeHttpMethod(deleteMethod)
|
||||
result = if (isSuccess(status)) RemoteOperationResult<Unit>(ResultCode.OK) else RemoteOperationResult<Unit>(deleteMethod)
|
||||
Timber.i("Remove $mRemotePath: ${result.logMessage}")
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult<Unit>(e)
|
||||
Timber.e(e, "Remove $mRemotePath: ${result.logMessage}")
|
||||
}
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
private boolean isSuccess(int status) {
|
||||
return status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_NO_CONTENT;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* For standard removals, we will use [OwnCloudClient.getUserFilesWebDavUri].
|
||||
* In case we need a different source Uri, override this method.
|
||||
*/
|
||||
open fun getSrcWebDavUriForClient(client: OwnCloudClient): Uri = client.userFilesWebDavUri
|
||||
|
||||
private fun isSuccess(status: Int) = status.isOneOf(HTTP_OK, HTTP_NO_CONTENT)
|
||||
}
|
||||
|
@ -22,20 +22,12 @@
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package com.owncloud.android.lib.resources.files.chunks
|
||||
|
||||
package com.owncloud.android.lib.resources.files.chunks;
|
||||
import android.net.Uri
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation
|
||||
|
||||
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
|
||||
|
||||
public class RemoveRemoteChunksFolderOperation extends RemoveRemoteFileOperation {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param remotePath RemotePath of the remote file or folder to remove from the server
|
||||
*/
|
||||
public RemoveRemoteChunksFolderOperation(String remotePath) {
|
||||
super(remotePath);
|
||||
removeChunksFolder = true;
|
||||
}
|
||||
}
|
||||
class RemoveRemoteChunksFolderOperation(remotePath: String) : RemoveRemoteFileOperation(remotePath) {
|
||||
override fun getSrcWebDavUriForClient(client: OwnCloudClient): Uri = client.uploadsWebDavUri
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user