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

Commit 2123198b authored by Nihar Thakkar's avatar Nihar Thakkar Committed by Sumit Pundir
Browse files

Implemented Google Account setup.

parent d698dd30
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ open class DavCollection @JvmOverloads constructor(
        httpClient: OkHttpClient,
        location: HttpUrl,
        log: Logger = Constants.log
): DavResource(httpClient, location, log) {
): DavResource(httpClient, location, null, log) {

    /**
     * Sends a REPORT sync-collection request.
+36 −14
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import java.util.logging.Logger
open class DavResource @JvmOverloads constructor(
        val httpClient: OkHttpClient,
        location: HttpUrl,
	var accessToken: String? = null,
        val log: Logger = Constants.log
) {

@@ -75,6 +76,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")
@@ -83,6 +85,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)
            }
	}	
    }

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

        followRedirects {
	    if (accessToken.isNullOrEmpty()) {
                httpClient.newCall(Request.Builder()
                        .url(location)
                        .method("PROPFIND", RequestBody.create(MIME_XML, writer.toString()))
                        .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)
        }