mirror of
https://github.com/etesync/android
synced 2024-12-23 15:18:14 +00:00
Provide DTEND for single-time events and DURATION for recurring events to Android calendar data provider (fixes #60)
This commit is contained in:
parent
3cbfcbee9b
commit
44cf628dd6
@ -240,13 +240,16 @@ public class Event extends Resource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public long getDtEndInMillis() {
|
public Long getDtEndInMillis() {
|
||||||
if (hasNoTime(dtStart) && dtEnd == null) {
|
if (hasNoTime(dtStart) && dtEnd == null) { // "event on that day"
|
||||||
// dtEnd = dtStart + 1 day
|
// dtEnd = dtStart + 1 day
|
||||||
Calendar c = Calendar.getInstance(TimeZone.getTimeZone(Time.TIMEZONE_UTC));
|
Calendar c = Calendar.getInstance(TimeZone.getTimeZone(Time.TIMEZONE_UTC));
|
||||||
c.setTime(dtStart.getDate());
|
c.setTime(dtStart.getDate());
|
||||||
c.add(Calendar.DATE, 1);
|
c.add(Calendar.DATE, 1);
|
||||||
return c.getTimeInMillis();
|
return c.getTimeInMillis();
|
||||||
|
|
||||||
|
} else if (dtEnd == null || dtEnd.getDate() == null) { // no DTEND provided (maybe DURATION instead)
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return dtEnd.getDate().getTime();
|
return dtEnd.getDate().getTime();
|
||||||
@ -317,7 +320,7 @@ public class Event extends Resource {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i(TAG, "Assuming time zone " + localTZ + " for " + tzID);
|
Log.d(TAG, "Assuming time zone " + localTZ + " for " + tzID);
|
||||||
date.setTimeZone(tzRegistry.getTimeZone(localTZ));
|
date.setTimeZone(tzRegistry.getTimeZone(localTZ));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ package at.bitfire.davdroid.resource;
|
|||||||
|
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@ -427,25 +428,49 @@ public class LocalCalendar extends LocalCollection<Event> {
|
|||||||
.withValue(entryColumnUID(), event.getUid())
|
.withValue(entryColumnUID(), event.getUid())
|
||||||
.withValue(Events.ALL_DAY, event.isAllDay() ? 1 : 0)
|
.withValue(Events.ALL_DAY, event.isAllDay() ? 1 : 0)
|
||||||
.withValue(Events.DTSTART, event.getDtStartInMillis())
|
.withValue(Events.DTSTART, event.getDtStartInMillis())
|
||||||
.withValue(Events.DTEND, event.getDtEndInMillis())
|
|
||||||
.withValue(Events.EVENT_TIMEZONE, event.getDtStartTzID())
|
.withValue(Events.EVENT_TIMEZONE, event.getDtStartTzID())
|
||||||
.withValue(Events.HAS_ATTENDEE_DATA, event.getAttendees().isEmpty() ? 0 : 1);
|
.withValue(Events.HAS_ATTENDEE_DATA, event.getAttendees().isEmpty() ? 0 : 1);
|
||||||
|
|
||||||
if (event.getDtEndTzID() != null)
|
boolean recurring = false;
|
||||||
builder = builder.withValue(Events.EVENT_END_TIMEZONE, event.getDtEndTzID());
|
if (event.getRrule() != null) {
|
||||||
|
recurring = true;
|
||||||
if (event.getDuration() != null)
|
|
||||||
builder = builder.withValue(Events.DURATION, event.getDuration().getValue());
|
|
||||||
|
|
||||||
if (event.getRrule() != null)
|
|
||||||
builder = builder.withValue(Events.RRULE, event.getRrule().getValue());
|
builder = builder.withValue(Events.RRULE, event.getRrule().getValue());
|
||||||
if (event.getRdate() != null)
|
}
|
||||||
|
if (event.getRdate() != null) {
|
||||||
|
recurring = true;
|
||||||
builder = builder.withValue(Events.RDATE, event.getRdate().getValue());
|
builder = builder.withValue(Events.RDATE, event.getRdate().getValue());
|
||||||
|
}
|
||||||
if (event.getExrule() != null)
|
if (event.getExrule() != null)
|
||||||
builder = builder.withValue(Events.EXRULE, event.getExrule().getValue());
|
builder = builder.withValue(Events.EXRULE, event.getExrule().getValue());
|
||||||
if (event.getExdate() != null)
|
if (event.getExdate() != null)
|
||||||
builder = builder.withValue(Events.EXDATE, event.getExdate().getValue());
|
builder = builder.withValue(Events.EXDATE, event.getExdate().getValue());
|
||||||
|
|
||||||
|
// set DTEND for single-time events or DURATION for recurring events
|
||||||
|
// because that's the way Android likes it
|
||||||
|
if (!recurring) {
|
||||||
|
// not recurring: set DTEND
|
||||||
|
long dtEnd = 0;
|
||||||
|
String tzEnd = null;
|
||||||
|
if (event.getDtEndInMillis() != null) {
|
||||||
|
dtEnd = event.getDtEndInMillis();
|
||||||
|
tzEnd = event.getDtEndTzID();
|
||||||
|
} else if (event.getDuration() != null) {
|
||||||
|
Date dateEnd = event.getDuration().getDuration().getTime(event.getDtStart().getDate());
|
||||||
|
dtEnd = dateEnd.getTime();
|
||||||
|
}
|
||||||
|
builder = builder
|
||||||
|
.withValue(Events.DTEND, dtEnd)
|
||||||
|
.withValue(Events.EVENT_END_TIMEZONE, tzEnd);
|
||||||
|
} else {
|
||||||
|
// recurring: set DURATION
|
||||||
|
String duration = null;
|
||||||
|
if (event.getDuration() != null)
|
||||||
|
duration = event.getDuration().getValue();
|
||||||
|
else if (event.getDtEnd() != null)
|
||||||
|
duration = new Duration(event.getDtStart().getDate(), event.getDtEnd().getDate()).getValue();
|
||||||
|
builder = builder.withValue(Events.DURATION, duration);
|
||||||
|
}
|
||||||
|
|
||||||
if (event.getSummary() != null)
|
if (event.getSummary() != null)
|
||||||
builder = builder.withValue(Events.TITLE, event.getSummary());
|
builder = builder.withValue(Events.TITLE, event.getSummary());
|
||||||
if (event.getLocation() != null)
|
if (event.getLocation() != null)
|
||||||
|
Loading…
Reference in New Issue
Block a user