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

Merge pull request #421 from owncloud/master

1.0.12 stable
This commit is contained in:
Jesús Recio 2021-07-20 13:26:37 +02:00 committed by GitHub
commit 0267ffa3f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 113 additions and 7 deletions

View File

@ -1,6 +1,6 @@
buildscript {
ext {
kotlinVersion = '1.4.32'
kotlinVersion = '1.5.21'
moshiVersion = "1.12.0"
}
@ -10,8 +10,8 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.jlleitschuh.gradle:ktlint-gradle:10.0.0"
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jlleitschuh.gradle:ktlint-gradle:10.1.0"
classpath 'com.android.tools.build:gradle:4.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -25,8 +25,8 @@ android {
minSdkVersion 21
targetSdkVersion 29
versionCode = 10001100
versionName = "1.0.11"
versionCode = 10001200
versionName = "1.0.12"
}
lintOptions {

View File

@ -56,6 +56,7 @@ public class HttpConstants {
public static final String OAUTH_HEADER_GRANT_TYPE = "grant_type";
public static final String OAUTH_HEADER_REDIRECT_URI = "redirect_uri";
public static final String OAUTH_HEADER_REFRESH_TOKEN = "refresh_token";
public static final String OAUTH_HEADER_CODE_VERIFIER = "code_verifier";
/***********************************************************************************************************
************************************************ CONTENT TYPES ********************************************

View File

@ -0,0 +1,103 @@
/* 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
import android.content.ContentResolver
import android.net.Uri
import android.provider.OpenableColumns
import com.owncloud.android.lib.common.OwnCloudClient
import com.owncloud.android.lib.common.http.HttpConstants
import com.owncloud.android.lib.common.http.methods.webdav.PutMethod
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 okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import okio.BufferedSink
import okio.source
import timber.log.Timber
import java.io.IOException
import java.net.URL
class UploadFileFromContentUriOperation(
private val uploadPath: String,
private val lastModified: String,
private val requestBody: ContentUriRequestBody
) : RemoteOperation<Unit>() {
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> {
val putMethod = PutMethod(URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(uploadPath)), requestBody).apply {
setRetryOnConnectionFailure(false)
addRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER, requestBody.contentLength().toString())
addRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER, lastModified)
}
return try {
val status = client.executeHttpMethod(putMethod)
if (isSuccess(status)) {
RemoteOperationResult<Unit>(RemoteOperationResult.ResultCode.OK).apply { data = Unit }
} else {
RemoteOperationResult<Unit>(putMethod)
}
} catch (e: Exception) {
val result = RemoteOperationResult<Unit>(e)
Timber.e(e, "Upload from content uri failed : ${result.logMessage}")
result
}
}
fun isSuccess(status: Int): Boolean {
return status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_CREATED || status == HttpConstants.HTTP_NO_CONTENT
}
}
class ContentUriRequestBody(
private val contentResolver: ContentResolver,
private val contentUri: Uri
) : RequestBody() {
override fun contentType(): MediaType? {
val contentType = contentResolver.getType(contentUri) ?: return null
return contentType.toMediaTypeOrNull()
}
override fun contentLength(): Long {
contentResolver.query(contentUri, null, null, null, null)?.use { cursor ->
val sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE)
cursor.moveToFirst()
return cursor.getLong(sizeIndex)
} ?: return -1
}
override fun writeTo(sink: BufferedSink) {
val inputStream = contentResolver.openInputStream(contentUri)
?: throw IOException("Couldn't open content URI for reading: $contentUri")
inputStream.source().use { source ->
sink.writeAll(source)
}
}
}

View File

@ -39,7 +39,8 @@ sealed class TokenRequestParams(
clientAuth: String,
grantType: String,
val authorizationCode: String,
val redirectUri: String
val redirectUri: String,
val codeVerifier: String,
) : TokenRequestParams(tokenEndpoint, clientAuth, grantType) {
override fun toRequestBody(): RequestBody =
@ -47,6 +48,7 @@ sealed class TokenRequestParams(
.add(HttpConstants.OAUTH_HEADER_AUTHORIZATION_CODE, authorizationCode)
.add(HttpConstants.OAUTH_HEADER_GRANT_TYPE, grantType)
.add(HttpConstants.OAUTH_HEADER_REDIRECT_URI, redirectUri)
.add(HttpConstants.OAUTH_HEADER_CODE_VERIFIER, codeVerifier)
.build()
}