|
|
|
|
@ -34,10 +34,14 @@ import com.todoroo.astrid.service.TaskDeleter;
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.StringReader;
|
|
|
|
|
import java.net.ConnectException;
|
|
|
|
|
import java.net.SocketTimeoutException;
|
|
|
|
|
import java.net.UnknownHostException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
import javax.net.ssl.SSLException;
|
|
|
|
|
import net.fortuna.ical4j.model.property.ProdId;
|
|
|
|
|
import okhttp3.HttpUrl;
|
|
|
|
|
import okhttp3.OkHttpClient;
|
|
|
|
|
@ -102,15 +106,20 @@ public class CaldavSynchronizer {
|
|
|
|
|
setError(account, context.getString(R.string.password_required));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
CaldavClient caldavClient = client.forAccount(account);
|
|
|
|
|
List<Response> resources;
|
|
|
|
|
try {
|
|
|
|
|
resources = caldavClient.getCalendars();
|
|
|
|
|
synchronize(account);
|
|
|
|
|
} catch (SocketTimeoutException | SSLException | ConnectException | UnknownHostException e) {
|
|
|
|
|
Timber.e(e);
|
|
|
|
|
account.setError(e.getMessage());
|
|
|
|
|
} catch (IOException | DavException e) {
|
|
|
|
|
setError(account, e.getMessage());
|
|
|
|
|
tracker.reportException(e);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void synchronize(CaldavAccount account) throws IOException, DavException {
|
|
|
|
|
CaldavClient caldavClient = client.forAccount(account);
|
|
|
|
|
List<Response> resources = caldavClient.getCalendars();
|
|
|
|
|
Set<String> urls = newHashSet(transform(resources, c -> c.getHref().toString()));
|
|
|
|
|
Timber.d("Found calendars: %s", urls);
|
|
|
|
|
for (CaldavCalendar calendar :
|
|
|
|
|
@ -143,10 +152,10 @@ public class CaldavSynchronizer {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sync(CaldavCalendar caldavCalendar, Response resource, OkHttpClient httpClient) {
|
|
|
|
|
private void sync(CaldavCalendar caldavCalendar, Response resource, OkHttpClient httpClient)
|
|
|
|
|
throws IOException, DavException {
|
|
|
|
|
Timber.d("sync(%s)", caldavCalendar);
|
|
|
|
|
HttpUrl httpUrl = resource.getHref();
|
|
|
|
|
try {
|
|
|
|
|
pushLocalChanges(caldavCalendar, httpClient, httpUrl);
|
|
|
|
|
|
|
|
|
|
String remoteName = resource.get(DisplayName.class).getDisplayName();
|
|
|
|
|
@ -180,8 +189,7 @@ public class CaldavSynchronizer {
|
|
|
|
|
if (eTag == null || isNullOrEmpty(eTag.getETag())) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
CaldavTask caldavTask =
|
|
|
|
|
caldavDao.getTask(caldavCalendar.getUuid(), vCard.hrefName());
|
|
|
|
|
CaldavTask caldavTask = caldavDao.getTask(caldavCalendar.getUuid(), vCard.hrefName());
|
|
|
|
|
return caldavTask == null || !eTag.getETag().equals(caldavTask.getEtag());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@ -213,8 +221,7 @@ public class CaldavSynchronizer {
|
|
|
|
|
}
|
|
|
|
|
CalendarData calendarData = vCard.get(CalendarData.class);
|
|
|
|
|
if (calendarData == null || isNullOrEmpty(calendarData.getICalendar())) {
|
|
|
|
|
throw new DavException(
|
|
|
|
|
"Received CalDAV GET response without CalendarData for " + url);
|
|
|
|
|
throw new DavException("Received CalDAV GET response without CalendarData for " + url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
processVTodo(
|
|
|
|
|
@ -236,9 +243,6 @@ public class CaldavSynchronizer {
|
|
|
|
|
caldavCalendar.setCtag(remoteCtag);
|
|
|
|
|
Timber.d("UPDATE %s", caldavCalendar);
|
|
|
|
|
caldavDao.update(caldavCalendar);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
tracker.reportException(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
localBroadcastManager.broadcastRefresh();
|
|
|
|
|
}
|
|
|
|
|
|