mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Converting RemoveRemoteFileOperation from java to kotlin. Final step.
This commit is contained in:
parent
02e6ddc0ef
commit
83314d7e2a
@ -24,19 +24,18 @@
|
|||||||
|
|
||||||
package com.owncloud.android.lib.resources.files;
|
package com.owncloud.android.lib.resources.files;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri
|
||||||
|
import com.owncloud.android.lib.common.OwnCloudClient
|
||||||
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;
|
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.http.methods.nonwebdav.DeleteMethod
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
import com.owncloud.android.lib.common.network.WebdavUtils
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
import timber.log.Timber;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode
|
||||||
|
import com.owncloud.android.lib.common.utils.isOneOf
|
||||||
import java.net.URL;
|
import timber.log.Timber
|
||||||
|
import java.net.URL
|
||||||
import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote operation performing the removal of a remote file or folder in the ownCloud server.
|
* 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 David A. Velasco
|
||||||
* @author masensio
|
* @author masensio
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
|
* @author Abel García de Prada
|
||||||
*/
|
*/
|
||||||
public class RemoveRemoteFileOperation extends RemoteOperation {
|
open class RemoveRemoteFileOperation(
|
||||||
private String mRemotePath;
|
private val mRemotePath: String
|
||||||
|
) : RemoteOperation<Unit>() {
|
||||||
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;
|
|
||||||
|
|
||||||
|
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> {
|
||||||
|
var result: RemoteOperationResult<Unit>
|
||||||
try {
|
try {
|
||||||
Uri srcWebDavUri = removeChunksFolder ? client.getUploadsWebDavUri() : client.getUserFilesWebDavUri();
|
val srcWebDavUri = getSrcWebDavUriForClient(client)
|
||||||
|
val deleteMethod = DeleteMethod(
|
||||||
DeleteMethod deleteMethod = new DeleteMethod(
|
URL(srcWebDavUri.toString() + WebdavUtils.encodePath(mRemotePath))
|
||||||
new URL(srcWebDavUri + WebdavUtils.encodePath(mRemotePath)));
|
)
|
||||||
|
val status = client.executeHttpMethod(deleteMethod)
|
||||||
int status = client.executeHttpMethod(deleteMethod);
|
result = if (isSuccess(status)) RemoteOperationResult<Unit>(ResultCode.OK) else RemoteOperationResult<Unit>(deleteMethod)
|
||||||
|
Timber.i("Remove $mRemotePath: ${result.logMessage}")
|
||||||
result = isSuccess(status) ?
|
} catch (e: Exception) {
|
||||||
new RemoteOperationResult<>(OK) :
|
result = RemoteOperationResult<Unit>(e)
|
||||||
new RemoteOperationResult<>(deleteMethod);
|
Timber.e(e, "Remove $mRemotePath: ${result.logMessage}")
|
||||||
|
|
||||||
Timber.i("Remove " + mRemotePath + ": " + result.getLogMessage());
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
result = new RemoteOperationResult<>(e);
|
|
||||||
Timber.e(e, "Remove " + mRemotePath + ": " + result.getLogMessage());
|
|
||||||
}
|
}
|
||||||
|
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.
|
* 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;
|
class RemoveRemoteChunksFolderOperation(remotePath: String) : RemoveRemoteFileOperation(remotePath) {
|
||||||
|
override fun getSrcWebDavUriForClient(client: OwnCloudClient): Uri = client.uploadsWebDavUri
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user