Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f1344b6a authored by Nihar Thakkar's avatar Nihar Thakkar Committed by Fahim Salam Chowdhury
Browse files

Implemented Google Account setup.

parent 587e8d5d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ open class DavCollection @JvmOverloads constructor(
        httpClient: OkHttpClient,
        location: HttpUrl,
        log: Logger = Dav4jvm.log
): DavResource(httpClient, location, log) {
): DavResource(httpClient, location, null, log) {

    companion object {
        val SYNC_COLLECTION = Property.Name(XmlUtils.NS_WEBDAV, "sync-collection")
+27 −5
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import at.bitfire.dav4jvm.Response as DavResponse
open class DavResource @JvmOverloads constructor(
        val httpClient: OkHttpClient,
        location: HttpUrl,
	    var accessToken: String? = null,
        val log: Logger = Dav4jvm.log
) {

@@ -94,6 +95,7 @@ open class DavResource @JvmOverloads constructor(
     */
    @Throws(IOException::class, HttpException::class)
    fun options(callback: (davCapabilities: Set<String>, response: Response) -> Unit) {
	    if (accessToken.isNullOrEmpty()) {
            httpClient.newCall(Request.Builder()
                .method("OPTIONS", null)
                .header("Content-Length", "0")
@@ -103,6 +105,17 @@ open class DavResource @JvmOverloads constructor(
                    checkStatus(response)
                    callback(HttpUtils.listHeader(response, "DAV").map { it.trim() }.toSet(), response)
                }
        } else {
            httpClient.newCall(Request.Builder()
                .method("OPTIONS", null)
                .header("Content-Length", "0")
                .header("Authorization", "Bearer $accessToken")
                .url(location)
                .build()).execute().use { response ->
                    checkStatus(response)
                    callback(HttpUtils.listHeader(response, "DAV").map { it.trim() }.toSet(), response)
                }
	    }
    }

    /**
@@ -431,11 +444,20 @@ open class DavResource @JvmOverloads constructor(
        serializer.endDocument()

        followRedirects {
	        if (accessToken.isNullOrEmpty()) {
                httpClient.newCall(Request.Builder()
                    .url(location)
                    .method("PROPFIND", writer.toString().toRequestBody(MIME_XML))
                    .header("Depth", if (depth >= 0) depth.toString() else "infinity")
                    .build()).execute()
            } else {
                httpClient.newCall(Request.Builder()
                    .url(location)
                    .method("PROPFIND", RequestBody.create(MIME_XML, writer.toString()))
                    .header("Depth", if (depth >= 0) depth.toString() else "infinity")
                    .header("Authorization", "Bearer $accessToken")
                    .build()).execute()
	        }
        }.use {
            processMultiStatus(it, callback)
        }