-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Further replaced OwnCloudClient with NextcloudClient - Moved to and implemented OkHttp/DAV methods - Added DavResponse to encapsulate dav responses - Added ArrayExtensions.kt to allow converting to legacy PropSet - Ported some classes to Kotlin - Improved typing on several remote operations - Added some comments - Minor fixes Signed-off-by: ZetaTom <[email protected]>
- Loading branch information
Showing
39 changed files
with
1,277 additions
and
1,501 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 ZetaTom <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package com.nextcloud.common | ||
|
||
import okhttp3.Headers | ||
import okhttp3.internal.http.StatusLine | ||
|
||
/** | ||
* Encapsulates essential data returned as responses from various DAV calls. | ||
*/ | ||
data class DavResponse( | ||
var success: Boolean = false, | ||
var status: StatusLine? = null, | ||
var headers: Headers? = null | ||
) { | ||
/** | ||
* Return value of specified header. | ||
* | ||
* Simple helper to aid with nullability when called from Java. | ||
* | ||
* @param key name of header to get | ||
* @return value of header or `null` when header is not set | ||
*/ | ||
fun getHeader(key: String): String? = headers?.get(key) | ||
|
||
/** | ||
* Return value of status code. | ||
* | ||
* Simple helper to aid with nullability when called from Java. | ||
* | ||
* @return HTTP status code or `0` if not set. | ||
*/ | ||
fun getStatusCode(): Int = status?.code ?: 0 | ||
} |
26 changes: 26 additions & 0 deletions
26
library/src/main/java/com/nextcloud/extensions/ArrayExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 ZetaTom <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package com.nextcloud.extensions | ||
|
||
import at.bitfire.dav4jvm.Property | ||
import org.apache.jackrabbit.webdav.property.DavPropertyName | ||
import org.apache.jackrabbit.webdav.property.DavPropertyNameSet | ||
import org.apache.jackrabbit.webdav.xml.Namespace | ||
|
||
/** | ||
* Returns DavPropertyNameSet for given array of Property.Name. | ||
* | ||
* TODO: remove - only intended as a transitional aid | ||
*/ | ||
fun Array<Property.Name>.toLegacyPropset(): DavPropertyNameSet { | ||
val propertySet = DavPropertyNameSet() | ||
for (property in this) { | ||
propertySet.add(DavPropertyName.create(property.name, Namespace.getNamespace(property.namespace))) | ||
} | ||
return propertySet | ||
} |
20 changes: 20 additions & 0 deletions
20
library/src/main/java/com/nextcloud/extensions/ParcelableExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 ZetaTom <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package com.nextcloud.extensions | ||
|
||
import android.os.Build | ||
import android.os.Parcel | ||
|
||
@Suppress("DEPRECATION") | ||
inline fun <reified T> Parcel.readParcelableArrayBridge(type: Class<T>): Any? { | ||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | ||
this.readParcelableArray(type::class.java.classLoader, this::class.java) | ||
} else { | ||
this.readParcelableArray(type::class.java.classLoader) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
library/src/main/java/com/nextcloud/operations/MkColMethod.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 ZetaTom <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package com.nextcloud.operations | ||
|
||
import android.net.Uri | ||
import at.bitfire.dav4jvm.DavResource | ||
import com.nextcloud.common.DavMethod | ||
import com.nextcloud.common.DavResponse | ||
import okhttp3.Headers.Companion.toHeaders | ||
import okhttp3.HttpUrl | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Response | ||
import okhttp3.internal.http.StatusLine | ||
|
||
class MkColMethod(httpUrl: HttpUrl) : DavMethod<DavResponse>(httpUrl){ | ||
private val headers = mutableMapOf<String, String>() | ||
|
||
override fun apply(client: OkHttpClient, httpUrl: HttpUrl, filesDavUri: Uri): DavResponse { | ||
val result = DavResponse() | ||
|
||
DavResource(client, httpUrl).mkCol( | ||
xmlBody = null, | ||
headers = headers.toHeaders() | ||
) { response: Response -> | ||
result.success = response.isSuccessful | ||
result.status = StatusLine.get(response) | ||
result.headers = response.headers | ||
} | ||
|
||
return result | ||
} | ||
|
||
fun addRequestHeader(key: String, value: String) { | ||
headers[key] = value | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
library/src/main/java/com/nextcloud/operations/MoveMethod.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 ZetaTom <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package com.nextcloud.operations | ||
|
||
import android.net.Uri | ||
import at.bitfire.dav4jvm.DavResource | ||
import com.nextcloud.common.DavMethod | ||
import com.nextcloud.common.DavResponse | ||
import okhttp3.HttpUrl | ||
import okhttp3.OkHttpClient | ||
import okhttp3.internal.http.StatusLine | ||
|
||
class MoveMethod( | ||
httpUrl: HttpUrl, | ||
private val destination: HttpUrl, | ||
private val forceOverwrite: Boolean = false | ||
): DavMethod<DavResponse>(httpUrl) { | ||
private val headers = mutableMapOf<String, String>() | ||
|
||
override fun apply(client: OkHttpClient, httpUrl: HttpUrl, filesDavUri: Uri): DavResponse { | ||
val result = DavResponse() | ||
|
||
DavResource(client, httpUrl).move( | ||
destination = destination, | ||
overwrite = forceOverwrite | ||
) { response -> | ||
result.success = response.isSuccessful | ||
result.status = StatusLine.get(response) | ||
result.headers = response.headers | ||
} | ||
|
||
return result | ||
} | ||
|
||
fun addRequestHeader(key: String, value: String) { | ||
headers[key] = value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
library/src/main/java/com/nextcloud/operations/PropPatchMethod.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 ZetaTom <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package com.nextcloud.operations | ||
|
||
import android.net.Uri | ||
import at.bitfire.dav4jvm.DavResource | ||
import at.bitfire.dav4jvm.Property | ||
import at.bitfire.dav4jvm.Response | ||
import com.nextcloud.common.DavMethod | ||
import com.nextcloud.common.DavResponse | ||
import okhttp3.HttpUrl | ||
import okhttp3.OkHttpClient | ||
|
||
class PropPatchMethod | ||
@JvmOverloads constructor( | ||
httpUrl: HttpUrl, | ||
private val setProperties: Map<Property.Name, String> = emptyMap(), | ||
private val removeProperties: List<Property.Name> = emptyList() | ||
) : DavMethod<DavResponse>(httpUrl){ | ||
override fun apply(client: OkHttpClient, httpUrl: HttpUrl, filesDavUri: Uri): DavResponse { | ||
val result = DavResponse() | ||
DavResource(client, httpUrl).proppatch(setProperties, removeProperties) { response: Response, hrefRelation: Response.HrefRelation? -> | ||
result.success = response.isSuccess() | ||
response.status?.let { status -> | ||
result.status = status | ||
} | ||
} | ||
|
||
return result | ||
} | ||
} |
35 changes: 8 additions & 27 deletions
35
library/src/main/java/com/owncloud/android/lib/common/network/ExtendedProperties.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,17 @@ | ||
/* Nextcloud Android Library is available under MIT license | ||
* | ||
* @author ZetaZom | ||
* Copyright (C) 2024 ZetaTom | ||
* Copyright (C) 2024 Nextcloud 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. | ||
* | ||
*/ | ||
|
||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 ZetaTom <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package com.owncloud.android.lib.common.network | ||
|
||
import at.bitfire.dav4jvm.Property | ||
|
||
enum class ExtendedProperties(val value: String, val namespace: String) { | ||
CREATION_TIME("creation_time", WebdavUtils.NAMESPACE_NC), | ||
COMMENTS_READ_MARKER("readMarker", WebdavUtils.NAMESPACE_NC), | ||
FAVORITE("favorite", WebdavUtils.NAMESPACE_OC), | ||
HAS_PREVIEW("has-preview", WebdavUtils.NAMESPACE_NC), | ||
HIDDEN("hidden", WebdavUtils.NAMESPACE_NC), | ||
|
Oops, something went wrong.