diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/AnyExt.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/AnyExt.kt new file mode 100644 index 00000000..462ca975 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/utils/AnyExt.kt @@ -0,0 +1,29 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2020 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.common.utils + +fun Any.isOneOf(vararg values: Any): Boolean { + return this in values +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.kt index 82f14ab1..40747ace 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.kt @@ -26,7 +26,8 @@ package com.owncloud.android.lib.resources.files import at.bitfire.dav4jvm.PropertyRegistry import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.accounts.AccountUtils -import com.owncloud.android.lib.common.http.HttpConstants +import com.owncloud.android.lib.common.http.HttpConstants.HTTP_MULTI_STATUS +import com.owncloud.android.lib.common.http.HttpConstants.HTTP_OK import com.owncloud.android.lib.common.http.methods.webdav.DavConstants import com.owncloud.android.lib.common.http.methods.webdav.DavUtils import com.owncloud.android.lib.common.http.methods.webdav.PropfindMethod @@ -35,6 +36,7 @@ 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 @@ -105,6 +107,5 @@ class ReadRemoteFolderOperation( } } - private fun isSuccess(status: Int): Boolean = - status == HttpConstants.HTTP_MULTI_STATUS || status == HttpConstants.HTTP_OK + private fun isSuccess(status: Int): Boolean = status.isOneOf(HTTP_OK, HTTP_MULTI_STATUS) } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFile.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFile.kt index ad81c287..715bdf1e 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFile.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFile.kt @@ -46,6 +46,7 @@ import com.owncloud.android.lib.common.http.methods.webdav.properties.OCShareTyp import com.owncloud.android.lib.resources.shares.ShareType import com.owncloud.android.lib.resources.shares.ShareType.Companion.fromValue import kotlinx.parcelize.Parcelize +import com.owncloud.android.lib.common.utils.isOneOf import okhttp3.HttpUrl import timber.log.Timber import java.io.File @@ -81,7 +82,9 @@ data class RemoteFile( // TODO: Quotas not used. Use or remove them. init { - require(!(remotePath.isEmpty() || !remotePath.startsWith(File.separator))) { "Trying to create a OCFile with a non valid remote path: $remotePath" } + require( + !(remotePath.isEmpty() || !remotePath.startsWith(File.separator)) + ) { "Trying to create a OCFile with a non valid remote path: $remotePath" } } /** @@ -90,7 +93,7 @@ data class RemoteFile( * @return true if it is a folder */ val isFolder - get() = mimeType == MIME_DIR || mimeType == MIME_DIR_UNIX + get() = mimeType.isOneOf(MIME_DIR, MIME_DIR_UNIX) companion object { @@ -170,7 +173,7 @@ data class RemoteFile( private fun getRemotePathFromUrl(url: HttpUrl, userId: String): String { val davFilesPath = OwnCloudClient.WEBDAV_FILES_PATH_4_0 + userId val absoluteDavPath = Uri.decode(url.encodedPath) - val pathToOc = absoluteDavPath.split(davFilesPath)[0] + val pathToOc = absoluteDavPath.split(davFilesPath).first() return absoluteDavPath.replace(pathToOc + davFilesPath, "") }