1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

Apply code review suggestions

This commit is contained in:
agarcia 2020-08-05 14:00:48 +02:00 committed by Juan Carlos Garrote
parent ba4592cf37
commit 8180468f82
2 changed files with 30 additions and 10 deletions

View File

@ -56,6 +56,7 @@ class CreateRemoteFolderOperation(
result = createParentFolder(FileUtils.getParentPath(remotePath), client)
if (result.isSuccess) {
// Second and last try
result = createFolder(client)
}
}
@ -65,25 +66,32 @@ class CreateRemoteFolderOperation(
private fun createFolder(client: OwnCloudClient): RemoteOperationResult<Unit> {
var result: RemoteOperationResult<Unit>
try {
val webDavUri = if (isChunksFolder) client.uploadsWebDavUri else client.userFilesWebDavUri
val mkcol = MkColMethod(URL(webDavUri.toString() + WebdavUtils.encodePath(remotePath))).apply {
val webDavUri = if (isChunksFolder) {
client.uploadsWebDavUri
} else {
client.userFilesWebDavUri
}
val mkCol = MkColMethod(
URL(webDavUri.toString() + WebdavUtils.encodePath(remotePath))
).apply {
setReadTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
setConnectionTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS)
}
val status = client.executeHttpMethod(mkcol)
val status = client.executeHttpMethod(mkCol)
result =
if (status == HttpConstants.HTTP_CREATED) {
RemoteOperationResult<Unit>(ResultCode.OK)
RemoteOperationResult(ResultCode.OK)
} else {
RemoteOperationResult<Unit>(mkcol)
RemoteOperationResult(mkCol)
}
Timber.d("Create directory $remotePath: ${result.logMessage}")
client.exhaustResponse(mkcol.getResponseBodyAsStream())
client.exhaustResponse(mkCol.getResponseBodyAsStream())
} catch (e: Exception) {
result = RemoteOperationResult<Unit>(e)
result = RemoteOperationResult(e)
Timber.e(e, "Create directory $remotePath: ${result.logMessage}")
}
return result

View File

@ -28,8 +28,20 @@ import com.owncloud.android.lib.resources.Service
import com.owncloud.android.lib.resources.files.RemoteFile
interface FileService : Service {
fun checkPathExistence(path: String, isUserLogged: Boolean): RemoteOperationResult<Boolean>
fun getUrlToOpenInWeb(openWebEndpoint: String, fileId: String): RemoteOperationResult<String>
fun createFolder(remotePath: String, createFullPath: Boolean, isChunkFolder: Boolean = false): RemoteOperationResult<Unit>
fun refreshFolder(remotePath: String): RemoteOperationResult<ArrayList<RemoteFile>>
fun checkPathExistence(
path: String,
isUserLogged: Boolean
): RemoteOperationResult<Boolean>
fun createFolder(
remotePath: String,
createFullPath: Boolean,
isChunkFolder: Boolean = false
): RemoteOperationResult<Unit>
fun refreshFolder(
remotePath: String
): RemoteOperationResult<ArrayList<RemoteFile>>
}