Commit d3cb90c6 authored by Ricki Hirner's avatar Ricki Hirner

Add support for time-range filtering

* add support for calendar-query time-range
* upgrade to okhttp/3.2.0
parent 80f3b060
......@@ -22,9 +22,9 @@ android {
}
dependencies {
compile 'com.squareup.okhttp3:okhttp:3.1.2'
compile 'com.squareup.okhttp3:logging-interceptor:3.1.2'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
provided 'org.projectlombok:lombok:1.16.6'
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.1.2'
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.2.0'
}
......@@ -12,6 +12,9 @@ import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import at.bitfire.dav4android.exception.DavException;
import at.bitfire.dav4android.exception.HttpException;
......@@ -27,11 +30,14 @@ public class DavCalendar extends DavResource {
public static final MediaType
MIME_ICALENDAR = MediaType.parse("text/calendar;charset=utf-8");
protected static final SimpleDateFormat timeFormatUTC = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.US);
public DavCalendar(OkHttpClient httpClient, HttpUrl location) {
super(httpClient, location);
}
public void calendarQuery(String component) throws IOException, HttpException, DavException {
public void calendarQuery(String component, Date start, Date end) throws IOException, HttpException, DavException {
/* <!ELEMENT calendar-query ((DAV:allprop |
DAV:propname |
DAV:prop)?, filter, timezone?)>
......@@ -53,16 +59,24 @@ public class DavCalendar extends DavResource {
serializer.startTag(XmlUtils.NS_WEBDAV, "prop");
serializer.startTag(XmlUtils.NS_WEBDAV, "getetag");
serializer.endTag(XmlUtils.NS_WEBDAV, "getetag");
serializer.endTag(XmlUtils.NS_WEBDAV, "prop");
serializer.endTag(XmlUtils.NS_WEBDAV, "prop");
serializer.startTag(XmlUtils.NS_CALDAV, "filter");
serializer.startTag(XmlUtils.NS_CALDAV, "comp-filter");
serializer.attribute(null, "name", "VCALENDAR");
serializer.startTag(XmlUtils.NS_CALDAV, "comp-filter");
serializer.attribute(null, "name", component);
if (start != null || end != null) {
serializer.startTag(XmlUtils.NS_CALDAV, "time-range");
if (start != null)
serializer.attribute(null, "start", timeFormatUTC.format(start));
if (end != null)
serializer.attribute(null, "end", timeFormatUTC.format(end));
serializer.endTag(XmlUtils.NS_CALDAV, "time-range");
}
serializer.endTag(XmlUtils.NS_CALDAV, "comp-filter");
serializer.endTag(XmlUtils.NS_CALDAV, "comp-filter");
serializer.endTag(XmlUtils.NS_CALDAV, "filter");
serializer.endTag(XmlUtils.NS_CALDAV, "calendar-query");
serializer.endTag(XmlUtils.NS_CALDAV, "comp-filter");
serializer.endTag(XmlUtils.NS_CALDAV, "filter");
serializer.endTag(XmlUtils.NS_CALDAV, "calendar-query");
serializer.endDocument();
Response response = httpClient.newCall(new Request.Builder()
......
......@@ -5,6 +5,9 @@ import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;
import java.text.SimpleDateFormat;
import java.util.Locale;
import lombok.SneakyThrows;
public class XmlUtils {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment