mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Add removeFile to FileService
This commit is contained in:
parent
bfade365d9
commit
86eb5fdf70
@ -22,7 +22,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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
|
||||||
@ -46,7 +46,7 @@ import java.net.URL
|
|||||||
* @author Abel García de Prada
|
* @author Abel García de Prada
|
||||||
*/
|
*/
|
||||||
open class RemoveRemoteFileOperation(
|
open class RemoveRemoteFileOperation(
|
||||||
private val mRemotePath: String
|
private val remotePath: String
|
||||||
) : RemoteOperation<Unit>() {
|
) : RemoteOperation<Unit>() {
|
||||||
|
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> {
|
||||||
@ -54,14 +54,14 @@ open class RemoveRemoteFileOperation(
|
|||||||
try {
|
try {
|
||||||
val srcWebDavUri = getSrcWebDavUriForClient(client)
|
val srcWebDavUri = getSrcWebDavUriForClient(client)
|
||||||
val deleteMethod = DeleteMethod(
|
val deleteMethod = DeleteMethod(
|
||||||
URL(srcWebDavUri.toString() + WebdavUtils.encodePath(mRemotePath))
|
URL(srcWebDavUri.toString() + WebdavUtils.encodePath(remotePath))
|
||||||
)
|
)
|
||||||
val status = client.executeHttpMethod(deleteMethod)
|
val status = client.executeHttpMethod(deleteMethod)
|
||||||
result = if (isSuccess(status)) RemoteOperationResult<Unit>(ResultCode.OK) else RemoteOperationResult<Unit>(deleteMethod)
|
result = if (isSuccess(status)) RemoteOperationResult<Unit>(ResultCode.OK) else RemoteOperationResult<Unit>(deleteMethod)
|
||||||
Timber.i("Remove $mRemotePath: ${result.logMessage}")
|
Timber.i("Remove $remotePath: ${result.logMessage}")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
result = RemoteOperationResult<Unit>(e)
|
result = RemoteOperationResult<Unit>(e)
|
||||||
Timber.e(e, "Remove $mRemotePath: ${result.logMessage}")
|
Timber.e(e, "Remove $remotePath: ${result.logMessage}")
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
/* ownCloud Android Library is available under MIT license
|
||||||
|
* Copyright (C) 2021 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.resources.files.services
|
||||||
|
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
|
import com.owncloud.android.lib.resources.Service
|
||||||
|
|
||||||
|
interface ChunkService : Service {
|
||||||
|
fun removeFile(
|
||||||
|
remotePath: String
|
||||||
|
): RemoteOperationResult<Unit>
|
||||||
|
}
|
@ -49,4 +49,8 @@ interface FileService : Service {
|
|||||||
fun refreshFolder(
|
fun refreshFolder(
|
||||||
remotePath: String
|
remotePath: String
|
||||||
): RemoteOperationResult<ArrayList<RemoteFile>>
|
): RemoteOperationResult<ArrayList<RemoteFile>>
|
||||||
|
|
||||||
|
fun removeFile(
|
||||||
|
remotePath: String
|
||||||
|
): RemoteOperationResult<Unit>
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
/* ownCloud Android Library is available under MIT license
|
||||||
|
* Copyright (C) 2021 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.resources.files.services.implementation
|
||||||
|
|
||||||
|
import com.owncloud.android.lib.common.OwnCloudClient
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
|
import com.owncloud.android.lib.resources.files.chunks.RemoveRemoteChunksFolderOperation
|
||||||
|
import com.owncloud.android.lib.resources.files.services.ChunkService
|
||||||
|
|
||||||
|
class OCChunkService(override val client: OwnCloudClient) : ChunkService {
|
||||||
|
|
||||||
|
override fun removeFile(remotePath: String): RemoteOperationResult<Unit> =
|
||||||
|
RemoveRemoteChunksFolderOperation(remotePath = remotePath).execute(client)
|
||||||
|
}
|
@ -31,6 +31,7 @@ import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation
|
|||||||
import com.owncloud.android.lib.resources.files.GetUrlToOpenInWebRemoteOperation
|
import com.owncloud.android.lib.resources.files.GetUrlToOpenInWebRemoteOperation
|
||||||
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation
|
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation
|
||||||
import com.owncloud.android.lib.resources.files.RemoteFile
|
import com.owncloud.android.lib.resources.files.RemoteFile
|
||||||
|
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation
|
||||||
import com.owncloud.android.lib.resources.files.services.FileService
|
import com.owncloud.android.lib.resources.files.services.FileService
|
||||||
|
|
||||||
class OCFileService(override val client: OwnCloudClient) : FileService {
|
class OCFileService(override val client: OwnCloudClient) : FileService {
|
||||||
@ -71,4 +72,7 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
|
|||||||
ReadRemoteFolderOperation(
|
ReadRemoteFolderOperation(
|
||||||
remotePath = remotePath
|
remotePath = remotePath
|
||||||
).execute(client)
|
).execute(client)
|
||||||
|
|
||||||
|
override fun removeFile(remotePath: String): RemoteOperationResult<Unit> =
|
||||||
|
RemoveRemoteFileOperation(remotePath = remotePath).execute(client)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user