mirror of
https://github.com/etesync/android
synced 2024-12-23 07:08:16 +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() {
|
||||
if (hasNoTime(dtStart) && dtEnd == null) {
|
||||
public Long getDtEndInMillis() {
|
||||
if (hasNoTime(dtStart) && dtEnd == null) { // "event on that day"
|
||||
// dtEnd = dtStart + 1 day
|
||||
Calendar c = Calendar.getInstance(TimeZone.getTimeZone(Time.TIMEZONE_UTC));
|
||||
c.setTime(dtStart.getDate());
|
||||
c.add(Calendar.DATE, 1);
|
||||
return c.getTimeInMillis();
|
||||
|
||||
} else if (dtEnd == null || dtEnd.getDate() == null) { // no DTEND provided (maybe DURATION instead)
|
||||
return null;
|
||||
}
|
||||
|
||||
return dtEnd.getDate().getTime();
|
||||
@ -317,7 +320,7 @@ public class Event extends Resource {
|
||||
break;
|
||||
}
|
||||
|
||||
Log.i(TAG, "Assuming time zone " + localTZ + " for " + tzID);
|
||||
Log.d(TAG, "Assuming time zone " + localTZ + " for " + tzID);
|
||||
date.setTimeZone(tzRegistry.getTimeZone(localTZ));
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ package at.bitfire.davdroid.resource;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
@ -427,25 +428,49 @@ public class LocalCalendar extends LocalCollection<Event> {
|
||||
.withValue(entryColumnUID(), event.getUid())
|
||||
.withValue(Events.ALL_DAY, event.isAllDay() ? 1 : 0)
|
||||
.withValue(Events.DTSTART, event.getDtStartInMillis())
|
||||
.withValue(Events.DTEND, event.getDtEndInMillis())
|
||||
.withValue(Events.EVENT_TIMEZONE, event.getDtStartTzID())
|
||||
.withValue(Events.HAS_ATTENDEE_DATA, event.getAttendees().isEmpty() ? 0 : 1);
|
||||
|
||||
if (event.getDtEndTzID() != null)
|
||||
builder = builder.withValue(Events.EVENT_END_TIMEZONE, event.getDtEndTzID());
|
||||
|
||||
if (event.getDuration() != null)
|
||||
builder = builder.withValue(Events.DURATION, event.getDuration().getValue());
|
||||
|
||||
if (event.getRrule() != null)
|
||||
boolean recurring = false;
|
||||
if (event.getRrule() != null) {
|
||||
recurring = true;
|
||||
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());
|
||||
}
|
||||
if (event.getExrule() != null)
|
||||
builder = builder.withValue(Events.EXRULE, event.getExrule().getValue());
|
||||
if (event.getExdate() != null)
|
||||
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)
|
||||
builder = builder.withValue(Events.TITLE, event.getSummary());
|
||||
if (event.getLocation() != null)
|
||||
|
Loading…
Reference in New Issue
Block a user