diff --git a/.gitmodules b/.gitmodules index dd823f04c..c59c05c97 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,5 +2,5 @@ path = ical4android url = https://gitlab.com/tasks.org/ical4android.git [submodule "dav4android"] - path = dav4android - url = https://gitlab.com/tasks.org/dav4android.git + path = dav4jvm + url = https://gitlab.com/tasks.org/dav4jvm.git diff --git a/app/build.gradle b/app/build.gradle index d121af1bd..47e29aa90 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' apply plugin: 'checkstyle' apply plugin: 'io.fabric' apply plugin: 'com.cookpad.android.licensetools' @@ -126,7 +127,7 @@ final CRASHLYTICS_VERSION = '2.10.1' final FIREBASE_VERSION = '16.0.9' dependencies { - implementation project(":dav4android") + implementation project(":dav4jvm") implementation project(":ical4android") annotationProcessor "com.google.dagger:dagger-compiler:${DAGGER_VERSION}" @@ -147,6 +148,7 @@ dependencies { debugImplementation "com.squareup.leakcanary:leakcanary-android:${LEAKCANARY_VERSION}" debugImplementation "com.squareup.leakcanary:leakcanary-support-fragment:${LEAKCANARY_VERSION}" + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" implementation 'io.github.luizgrp.sectionedrecyclerviewadapter:sectionedrecyclerviewadapter:2.0.0' implementation 'androidx.multidex:multidex:2.0.1' implementation 'me.saket:better-link-movement-method:2.2.0' diff --git a/app/licenses.yml b/app/licenses.yml index 47dc757dc..2b542e821 100644 --- a/app/licenses.yml +++ b/app/licenses.yml @@ -1,5 +1,5 @@ -- artifact: at.bitfire:dav4android:+ - name: dav4android +- artifact: at.bitfire:dav4jvm:+ + name: dav4jvm copyrightHolder: bitfire web engineering (Ricki Hirner, Bernhard Stockmann) license: Mozilla Public License, Version 2.0 licenseUrl: https://www.mozilla.org/en-US/MPL/2.0/ @@ -714,3 +714,25 @@ license: The Apache Software License, Version 2.0 licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt url: https://developer.android.com/topic/libraries/architecture/index.html +- artifact: org.ogce:xpp3:+ + name: XPP3 + copyrightHolder: Aleksander Slominski + license: The Apache Software License, Version 2.0 + licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt + url: http://www.extreme.indiana.edu/xpp/ +- artifact: junit:junit:+ + name: JUnit + copyrightHolder: junit-team + license: Common Public License Version 1.0 + licenseUrl: http://www.opensource.org/licenses/cpl1.0.txt + url: http://junit.org +- artifact: jakarta-regexp:jakarta-regexp:+ + name: jakarta-regexp + copyrightHolder: The Apache Software Foundation + license: The Apache Software License, Version 2.0 +- artifact: androidx.core:core-ktx:+ + name: Core Kotlin Extensions + copyrightHolder: The Android Open Source Project + license: The Apache Software License, Version 2.0 + licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt + url: http://developer.android.com/tools/extras/support-library.html \ No newline at end of file diff --git a/app/src/main/assets/licenses.json b/app/src/main/assets/licenses.json index 652bba604..2c5c08e1f 100644 --- a/app/src/main/assets/licenses.json +++ b/app/src/main/assets/licenses.json @@ -9,9 +9,9 @@ "normalizedLicense": "mpl2", "year": null, "url": null, - "libraryName": "dav4android", + "libraryName": "dav4jvm", "artifactId": { - "name": "dav4android", + "name": "dav4jvm", "group": "at.bitfire", "version": "+" } @@ -397,7 +397,7 @@ "artifactId": { "name": "commons-codec", "group": "commons-codec", - "version": "1.10" + "version": "1.11" } }, { @@ -445,7 +445,7 @@ "artifactId": { "name": "annotation", "group": "androidx.annotation", - "version": "1.1.0-rc01" + "version": "1.0.2" } }, { @@ -605,7 +605,7 @@ "artifactId": { "name": "commons-lang3", "group": "org.apache.commons", - "version": "3.6" + "version": "3.8.1" } }, { @@ -909,7 +909,7 @@ "artifactId": { "name": "ical4j", "group": "org.mnode.ical4j", - "version": "2.2.3" + "version": "2.2.4" } }, { @@ -1501,7 +1501,7 @@ "artifactId": { "name": "kotlin-stdlib", "group": "org.jetbrains.kotlin", - "version": "1.3.31" + "version": "1.2.60" } }, { @@ -1565,7 +1565,7 @@ "artifactId": { "name": "okhttp", "group": "com.squareup.okhttp3", - "version": "3.10.0" + "version": "3.12.3" } }, { @@ -1576,12 +1576,12 @@ "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.txt", "normalizedLicense": "apache2", "year": null, - "url": "", + "url": "https://github.com/square/okio/", "libraryName": "Okio", "artifactId": { "name": "okio", "group": "com.squareup.okio", - "version": "1.15.0" + "version": "2.2.2" } }, { @@ -1629,7 +1629,7 @@ "artifactId": { "name": "kotlin-stdlib-common", "group": "org.jetbrains.kotlin", - "version": "1.3.31" + "version": "1.2.60" } }, { @@ -1919,6 +1919,70 @@ "group": "androidx.paging", "version": "2.1.0" } + }, + { + "notice": null, + "copyrightHolder": "Aleksander Slominski", + "copyrightStatement": "Copyright © Aleksander Slominski. All rights reserved.", + "license": "The Apache Software License, Version 2.0", + "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "normalizedLicense": "apache2", + "year": null, + "url": "http://www.extreme.indiana.edu/xpp/", + "libraryName": "XPP3", + "artifactId": { + "name": "xpp3", + "group": "org.ogce", + "version": "1.1.6" + } + }, + { + "notice": null, + "copyrightHolder": "junit-team", + "copyrightStatement": "Copyright © junit-team. All rights reserved.", + "license": "Common Public License Version 1.0", + "licenseUrl": "http://www.opensource.org/licenses/cpl1.0.txt", + "normalizedLicense": "cpl1", + "year": null, + "url": "http://junit.org", + "libraryName": "JUnit", + "artifactId": { + "name": "junit", + "group": "junit", + "version": "4.7" + } + }, + { + "notice": null, + "copyrightHolder": "The Apache Software Foundation", + "copyrightStatement": "Copyright © The Apache Software Foundation. All rights reserved.", + "license": "The Apache Software License, Version 2.0", + "licenseUrl": "", + "normalizedLicense": "apache2", + "year": null, + "url": "", + "libraryName": "jakarta-regexp", + "artifactId": { + "name": "jakarta-regexp", + "group": "jakarta-regexp", + "version": "1.4" + } + }, + { + "notice": null, + "copyrightHolder": "The Android Open Source Project", + "copyrightStatement": "Copyright © The Android Open Source Project. All rights reserved.", + "license": "The Apache Software License, Version 2.0", + "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "normalizedLicense": "apache2", + "year": null, + "url": "http://developer.android.com/tools/extras/support-library.html", + "libraryName": "Core Kotlin Extensions", + "artifactId": { + "name": "core-ktx", + "group": "androidx.core", + "version": "1.0.2" + } } ] } \ No newline at end of file diff --git a/app/src/main/java/org/tasks/caldav/CaldavAccountSettingsActivity.java b/app/src/main/java/org/tasks/caldav/CaldavAccountSettingsActivity.java index b882843fe..d59cc5ece 100644 --- a/app/src/main/java/org/tasks/caldav/CaldavAccountSettingsActivity.java +++ b/app/src/main/java/org/tasks/caldav/CaldavAccountSettingsActivity.java @@ -13,7 +13,7 @@ import android.widget.LinearLayout; import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import androidx.lifecycle.ViewModelProviders; -import at.bitfire.dav4android.exception.HttpException; +import at.bitfire.dav4jvm.exception.HttpException; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnFocusChange; diff --git a/app/src/main/java/org/tasks/caldav/CaldavCalendarSettingsActivity.java b/app/src/main/java/org/tasks/caldav/CaldavCalendarSettingsActivity.java index 832d3cd72..909d7d2aa 100644 --- a/app/src/main/java/org/tasks/caldav/CaldavCalendarSettingsActivity.java +++ b/app/src/main/java/org/tasks/caldav/CaldavCalendarSettingsActivity.java @@ -14,7 +14,7 @@ import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar.OnMenuItemClickListener; import androidx.core.content.ContextCompat; import androidx.lifecycle.ViewModelProviders; -import at.bitfire.dav4android.exception.HttpException; +import at.bitfire.dav4jvm.exception.HttpException; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; diff --git a/app/src/main/java/org/tasks/caldav/CaldavClient.java b/app/src/main/java/org/tasks/caldav/CaldavClient.java index 68a3ff936..de0db366b 100644 --- a/app/src/main/java/org/tasks/caldav/CaldavClient.java +++ b/app/src/main/java/org/tasks/caldav/CaldavClient.java @@ -1,23 +1,24 @@ package org.tasks.caldav; import static android.text.TextUtils.isEmpty; -import static at.bitfire.dav4android.XmlUtils.NS_CALDAV; -import static at.bitfire.dav4android.XmlUtils.NS_CARDDAV; -import static at.bitfire.dav4android.XmlUtils.NS_WEBDAV; +import static at.bitfire.dav4jvm.XmlUtils.NS_CALDAV; +import static at.bitfire.dav4jvm.XmlUtils.NS_CARDDAV; +import static at.bitfire.dav4jvm.XmlUtils.NS_WEBDAV; import static java.util.Arrays.asList; -import at.bitfire.dav4android.BasicDigestAuthHandler; -import at.bitfire.dav4android.DavResource; -import at.bitfire.dav4android.DavResponse; -import at.bitfire.dav4android.XmlUtils; -import at.bitfire.dav4android.exception.DavException; -import at.bitfire.dav4android.exception.HttpException; -import at.bitfire.dav4android.property.CalendarHomeSet; -import at.bitfire.dav4android.property.CurrentUserPrincipal; -import at.bitfire.dav4android.property.DisplayName; -import at.bitfire.dav4android.property.GetCTag; -import at.bitfire.dav4android.property.ResourceType; -import at.bitfire.dav4android.property.SupportedCalendarComponentSet; +import at.bitfire.dav4jvm.BasicDigestAuthHandler; +import at.bitfire.dav4jvm.DavResource; +import at.bitfire.dav4jvm.Property.Name; +import at.bitfire.dav4jvm.Response; +import at.bitfire.dav4jvm.XmlUtils; +import at.bitfire.dav4jvm.exception.DavException; +import at.bitfire.dav4jvm.exception.HttpException; +import at.bitfire.dav4jvm.property.CalendarHomeSet; +import at.bitfire.dav4jvm.property.CurrentUserPrincipal; +import at.bitfire.dav4jvm.property.DisplayName; +import at.bitfire.dav4jvm.property.GetCTag; +import at.bitfire.dav4jvm.property.ResourceType; +import at.bitfire.dav4jvm.property.SupportedCalendarComponentSet; import com.todoroo.astrid.helper.UUIDHelper; import java.io.IOException; import java.io.StringWriter; @@ -50,9 +51,7 @@ public class CaldavClient { @Inject public CaldavClient( - Encryption encryption, - Preferences preferences, - DebugNetworkInterceptor interceptor) { + Encryption encryption, Preferences preferences, DebugNetworkInterceptor interceptor) { this.encryption = encryption; this.preferences = preferences; this.interceptor = interceptor; @@ -106,19 +105,18 @@ public class CaldavClient { HttpUrl url = httpUrl.resolve(link); Timber.d("Checking for principal: %s", url); DavResource davResource = new DavResource(httpClient, url); - DavResponse response = null; + ResponseList responses = new ResponseList(); try { - response = davResource.propfind(0, CurrentUserPrincipal.NAME); + davResource.propfind(0, new Name[] {CurrentUserPrincipal.NAME}, responses); } catch (HttpException e) { - switch (e.getCode()) { - case 405: - Timber.w(e); - break; - default: - throw e; + if (e.getCode() == 405) { + Timber.w(e); + } else { + throw e; } } - if (response != null) { + if (!responses.isEmpty()) { + Response response = responses.get(0); CurrentUserPrincipal currentUserPrincipal = response.get(CurrentUserPrincipal.class); if (currentUserPrincipal != null) { String href = currentUserPrincipal.getHref(); @@ -133,7 +131,9 @@ public class CaldavClient { private String findHomeset(HttpUrl httpUrl) throws DavException, IOException { DavResource davResource = new DavResource(httpClient, httpUrl); - DavResponse response = davResource.propfind(0, CalendarHomeSet.NAME); + ResponseList responses = new ResponseList(); + davResource.propfind(0, new Name[] {CalendarHomeSet.NAME}, responses); + Response response = responses.get(0); CalendarHomeSet calendarHomeSet = response.get(CalendarHomeSet.class); if (calendarHomeSet == null) { throw new DisplayableException(R.string.caldav_home_set_not_found); @@ -154,17 +154,17 @@ public class CaldavClient { return findHomeset(isEmpty(principal) ? httpUrl : httpUrl.resolve(principal)); } - public List getCalendars() throws IOException, DavException { + public List getCalendars() throws IOException, DavException { DavResource davResource = new DavResource(httpClient, httpUrl); - DavResponse response = - davResource.propfind( - 1, - ResourceType.NAME, - DisplayName.NAME, - SupportedCalendarComponentSet.NAME, - GetCTag.NAME); - List urls = new ArrayList<>(); - for (DavResponse member : response.getMembers()) { + ResponseList responses = new ResponseList(); + davResource.propfind( + 1, + new Name[] { + ResourceType.NAME, DisplayName.NAME, SupportedCalendarComponentSet.NAME, GetCTag.NAME + }, + responses); + List urls = new ArrayList<>(); + for (Response member : responses) { ResourceType resourceType = member.get(ResourceType.class); if (resourceType == null || !resourceType.getTypes().contains(ResourceType.Companion.getCALENDAR())) { @@ -184,7 +184,7 @@ public class CaldavClient { } public void deleteCollection() throws IOException, HttpException { - new DavResource(httpClient, httpUrl).delete(null); + new DavResource(httpClient, httpUrl).delete(null, response -> null); } public String makeCollection(String displayName) @@ -192,7 +192,7 @@ public class CaldavClient { DavResource davResource = new DavResource(httpClient, httpUrl.resolve(UUIDHelper.newUUID() + "/")); String mkcolString = getMkcolString(displayName); - davResource.mkCol(mkcolString); + davResource.mkCol(mkcolString, response -> null); return davResource.getLocation().toString(); } @@ -230,7 +230,7 @@ public class CaldavClient { return stringWriter.toString(); } - public OkHttpClient getHttpClient() { + OkHttpClient getHttpClient() { return httpClient; } } diff --git a/app/src/main/java/org/tasks/caldav/CaldavSynchronizer.java b/app/src/main/java/org/tasks/caldav/CaldavSynchronizer.java index 348215c0d..b1d40fba1 100644 --- a/app/src/main/java/org/tasks/caldav/CaldavSynchronizer.java +++ b/app/src/main/java/org/tasks/caldav/CaldavSynchronizer.java @@ -10,20 +10,19 @@ import static com.google.common.collect.Sets.newHashSet; import static org.tasks.time.DateTimeUtils.currentTimeMillis; import android.content.Context; -import at.bitfire.dav4android.DavCalendar; -import at.bitfire.dav4android.DavResource; -import at.bitfire.dav4android.DavResponse; -import at.bitfire.dav4android.exception.DavException; -import at.bitfire.dav4android.exception.HttpException; -import at.bitfire.dav4android.property.CalendarData; -import at.bitfire.dav4android.property.DisplayName; -import at.bitfire.dav4android.property.GetCTag; -import at.bitfire.dav4android.property.GetETag; +import at.bitfire.dav4jvm.DavCalendar; +import at.bitfire.dav4jvm.DavResource; +import at.bitfire.dav4jvm.Response; +import at.bitfire.dav4jvm.exception.DavException; +import at.bitfire.dav4jvm.exception.HttpException; +import at.bitfire.dav4jvm.property.CalendarData; +import at.bitfire.dav4jvm.property.DisplayName; +import at.bitfire.dav4jvm.property.GetCTag; +import at.bitfire.dav4jvm.property.GetETag; import at.bitfire.ical4android.ICalendar; import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.common.io.CharStreams; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.data.SyncFlags; @@ -33,7 +32,6 @@ import com.todoroo.astrid.service.TaskCreator; import com.todoroo.astrid.service.TaskDeleter; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.Reader; import java.io.StringReader; import java.util.ArrayList; import java.util.List; @@ -43,7 +41,6 @@ import net.fortuna.ical4j.model.property.ProdId; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.RequestBody; -import okhttp3.ResponseBody; import org.tasks.BuildConfig; import org.tasks.LocalBroadcastManager; import org.tasks.R; @@ -99,45 +96,49 @@ public class CaldavSynchronizer { // required for dav4android (ServiceLoader) Thread.currentThread().setContextClassLoader(context.getClassLoader()); for (CaldavAccount account : caldavDao.getAccounts()) { - if (!inventory.hasPro()) { - setError(account, context.getString(R.string.requires_pro_subscription)); - continue; - } - if (isNullOrEmpty(account.getPassword())) { - setError(account, context.getString(R.string.password_required)); - continue; - } - CaldavClient caldavClient = client.forAccount(account); - List resources; - try { - resources = caldavClient.getCalendars(); - } catch (IOException | DavException e) { - setError(account, e.getMessage()); - tracker.reportException(e); - continue; - } - Set urls = newHashSet(transform(resources, c -> c.getUrl().toString())); - Timber.d("Found calendars: %s", urls); - for (CaldavCalendar calendar : - caldavDao.findDeletedCalendars(account.getUuid(), newArrayList(urls))) { - taskDeleter.delete(calendar); - } - for (DavResponse resource : resources) { - String url = resource.getUrl().toString(); - - CaldavCalendar calendar = caldavDao.getCalendarByUrl(account.getUuid(), url); - if (calendar == null) { - calendar = new CaldavCalendar(); - calendar.setName(resource.get(DisplayName.class).getDisplayName()); - calendar.setAccount(account.getUuid()); - calendar.setUrl(url); - calendar.setUuid(UUIDHelper.newUUID()); - calendar.setId(caldavDao.insert(calendar)); - } - sync(calendar, resource, caldavClient.getHttpClient()); + sync(account); + } + } + + private void sync(CaldavAccount account) { + if (!inventory.hasPro()) { + setError(account, context.getString(R.string.requires_pro_subscription)); + return; + } + if (isNullOrEmpty(account.getPassword())) { + setError(account, context.getString(R.string.password_required)); + return; + } + CaldavClient caldavClient = client.forAccount(account); + List resources; + try { + resources = caldavClient.getCalendars(); + } catch (IOException | DavException e) { + setError(account, e.getMessage()); + tracker.reportException(e); + return; + } + Set urls = newHashSet(transform(resources, c -> c.getHref().toString())); + Timber.d("Found calendars: %s", urls); + for (CaldavCalendar calendar : + caldavDao.findDeletedCalendars(account.getUuid(), newArrayList(urls))) { + taskDeleter.delete(calendar); + } + for (Response resource : resources) { + String url = resource.getHref().toString(); + + CaldavCalendar calendar = caldavDao.getCalendarByUrl(account.getUuid(), url); + if (calendar == null) { + calendar = new CaldavCalendar(); + calendar.setName(resource.get(DisplayName.class).getDisplayName()); + calendar.setAccount(account.getUuid()); + calendar.setUrl(url); + calendar.setUuid(UUIDHelper.newUUID()); + calendar.setId(caldavDao.insert(calendar)); } - setError(account, ""); + sync(calendar, resource, caldavClient.getHttpClient()); } + setError(account, ""); } private void setError(CaldavAccount account, String message) { @@ -149,9 +150,9 @@ public class CaldavSynchronizer { } } - private void sync(CaldavCalendar caldavCalendar, DavResponse resource, OkHttpClient httpClient) { + private void sync(CaldavCalendar caldavCalendar, Response resource, OkHttpClient httpClient) { Timber.d("sync(%s)", caldavCalendar); - HttpUrl httpUrl = resource.getUrl(); + HttpUrl httpUrl = resource.getHref(); try { pushLocalChanges(caldavCalendar, httpClient, httpUrl); @@ -173,11 +174,12 @@ public class CaldavSynchronizer { DavCalendar davCalendar = new DavCalendar(httpClient, httpUrl); - List members = davCalendar.calendarQuery("VTODO", null, null).getMembers(); + ResponseList members = new ResponseList(); + davCalendar.calendarQuery("VTODO", null, null, members); - Set remoteObjects = newHashSet(transform(members, DavResponse::fileName)); + Set remoteObjects = newHashSet(transform(members, Response::hrefName)); - Iterable changed = + Iterable changed = filter( ImmutableSet.copyOf(members), vCard -> { @@ -186,51 +188,44 @@ public class CaldavSynchronizer { return false; } CaldavTask caldavTask = - caldavDao.getTask(caldavCalendar.getUuid(), vCard.fileName()); + caldavDao.getTask(caldavCalendar.getUuid(), vCard.hrefName()); return caldavTask == null || !eTag.getETag().equals(caldavTask.getEtag()); }); - for (List items : partition(changed, 30)) { + for (List items : partition(changed, 30)) { if (items.size() == 1) { - DavResponse vCard = items.get(0); + Response vCard = items.get(0); GetETag eTag = vCard.get(GetETag.class); + HttpUrl url = vCard.getHref(); if (eTag == null || isNullOrEmpty(eTag.getETag())) { - throw new DavException( - "Received CalDAV GET response without ETag for " + vCard.getUrl()); - } - Timber.d("SINGLE %s", vCard.getUrl()); - DavResponse response = new DavResource(httpClient, vCard.getUrl()).get("text/calendar"); - ResponseBody responseBody = response.getBody(); - Reader reader = null; - try { - reader = responseBody.charStream(); - processVTodo( - vCard.fileName(), caldavCalendar, eTag.getETag(), CharStreams.toString(reader)); - } finally { - if (reader != null) { - reader.close(); - } + throw new DavException("Received CalDAV GET response without ETag for " + url); } + Timber.d("SINGLE %s", url); + + org.tasks.caldav.Response response = new org.tasks.caldav.Response(true); + new DavResource(httpClient, url).get("text/calendar", response); + processVTodo(vCard.hrefName(), caldavCalendar, eTag.getETag(), response.getBody()); } else { - ArrayList urls = newArrayList(Iterables.transform(items, DavResponse::getUrl)); - DavResponse response = davCalendar.multiget(urls); + ArrayList urls = newArrayList(Iterables.transform(items, Response::getHref)); + ResponseList responses = new ResponseList(); + davCalendar.multiget(urls, responses); Timber.d("MULTI %s", urls); - for (DavResponse vCard : response.getMembers()) { + for (Response vCard : responses) { GetETag eTag = vCard.get(GetETag.class); + HttpUrl url = vCard.getHref(); if (eTag == null || isNullOrEmpty(eTag.getETag())) { - throw new DavException( - "Received CalDAV GET response without ETag for " + vCard.getUrl()); + throw new DavException("Received CalDAV GET response without ETag for " + url); } CalendarData calendarData = vCard.get(CalendarData.class); if (calendarData == null || isNullOrEmpty(calendarData.getICalendar())) { throw new DavException( - "Received CalDAV GET response without CalendarData for " + vCard.getUrl()); + "Received CalDAV GET response without CalendarData for " + url); } processVTodo( - vCard.fileName(), caldavCalendar, eTag.getETag(), calendarData.getICalendar()); + vCard.hrefName(), caldavCalendar, eTag.getETag(), calendarData.getICalendar()); } } } @@ -278,7 +273,7 @@ public class CaldavSynchronizer { DavResource remote = new DavResource( httpClient, httpUrl.newBuilder().addPathSegment(caldavTask.getObject()).build()); - remote.delete(null); + remote.delete(null, response -> null); } } catch (HttpException e) { if (e.getCode() != 404) { @@ -327,8 +322,9 @@ public class CaldavSynchronizer { DavResource remote = new DavResource( httpClient, httpUrl.newBuilder().addPathSegment(caldavTask.getObject()).build()); - DavResponse response = remote.put(requestBody, null, false); - GetETag getETag = response.get(GetETag.class); + org.tasks.caldav.Response response = new org.tasks.caldav.Response(); + remote.put(requestBody, null, false, response); + GetETag getETag = GetETag.Companion.fromResponse(response.get()); if (getETag != null && !isNullOrEmpty(getETag.getETag())) { caldavTask.setEtag(getETag.getETag()); caldavTask.setVtodo(new String(data)); diff --git a/app/src/main/java/org/tasks/caldav/Response.java b/app/src/main/java/org/tasks/caldav/Response.java new file mode 100644 index 000000000..72250e334 --- /dev/null +++ b/app/src/main/java/org/tasks/caldav/Response.java @@ -0,0 +1,42 @@ +package org.tasks.caldav; + +import java.io.IOException; +import kotlin.Unit; +import kotlin.jvm.functions.Function1; +import timber.log.Timber; + +public class Response implements Function1 { + + private final boolean parseBody; + private okhttp3.Response response; + private String body; + + public Response() { + this(false); + } + + public Response(boolean parseBody) { + this.parseBody = parseBody; + } + + @Override + public Unit invoke(okhttp3.Response response) { + this.response = response; + if (parseBody) { + try { + body = response.body().string(); + } catch (IOException e) { + Timber.e(e); + } + } + return null; + } + + public okhttp3.Response get() { + return response; + } + + public String getBody() { + return body; + } +} diff --git a/app/src/main/java/org/tasks/caldav/ResponseList.java b/app/src/main/java/org/tasks/caldav/ResponseList.java new file mode 100644 index 000000000..47a08c3dc --- /dev/null +++ b/app/src/main/java/org/tasks/caldav/ResponseList.java @@ -0,0 +1,17 @@ +package org.tasks.caldav; + +import at.bitfire.dav4jvm.Response; +import at.bitfire.dav4jvm.Response.HrefRelation; +import java.util.ArrayList; +import kotlin.Unit; +import kotlin.jvm.functions.Function2; + +public class ResponseList extends ArrayList + implements Function2 { + + @Override + public Unit invoke(Response response, HrefRelation hrefRelation) { + add(response); + return null; + } +} diff --git a/build.gradle b/build.gradle index 12fc35b0c..74857a35d 100644 --- a/build.gradle +++ b/build.gradle @@ -6,6 +6,8 @@ wrapper { } buildscript { + ext.kotlinVersion = '1.3.31' + repositories { jcenter() google() @@ -21,5 +23,6 @@ buildscript { classpath 'io.fabric.tools:gradle:1.28.1' classpath 'com.github.ben-manes:gradle-versions-plugin:0.21.0' classpath 'com.cookpad.android.licensetools:license-tools-plugin:1.7.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" } } diff --git a/dav4android b/dav4android deleted file mode 160000 index ce20774b0..000000000 --- a/dav4android +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ce20774b04d3fe6f7632d2f265df580e2d4dd987 diff --git a/dav4jvm b/dav4jvm new file mode 160000 index 000000000..753df939c --- /dev/null +++ b/dav4jvm @@ -0,0 +1 @@ +Subproject commit 753df939cbfa821414240e5cea1afc0b4390b4a0 diff --git a/ical4android b/ical4android index 491a10392..c8d53d688 160000 --- a/ical4android +++ b/ical4android @@ -1 +1 @@ -Subproject commit 491a1039228cf3e6ca6fc2222355f76a9649d953 +Subproject commit c8d53d6880374b2330d98ef5c43ff662a003abe7 diff --git a/settings.gradle b/settings.gradle index 14aa0a7d9..fc459fcf4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include 'dav4android', 'ical4android', 'app' +include 'dav4jvm', 'ical4android', 'app'