Hide future events
This commit is contained in:
@@ -204,14 +204,12 @@ public class CalendarSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
private void addEvents(@NotNull String calendarId, @NotNull List<TerminPlugin.Event> events) {
|
||||
Log.d(TAG, "Create calendar events");
|
||||
for (TerminPlugin.Event event : events) {
|
||||
int day = event.dateFields.day != null ? event.dateFields.day : 1;
|
||||
int month = event.dateFields.month != null ? event.dateFields.month : 1; // 1=January
|
||||
String title = event.description;
|
||||
if (title == null) {
|
||||
title = PathUtils.extractWebName(event.pagePath);
|
||||
}
|
||||
String description = getContext().getString(R.string.calendar_date) + ": " + TerminPlugin.formatGermanDate(event.dateFields);
|
||||
String eventId = addEvent(calendarId, day, month, title, description);
|
||||
String eventId = addEvent(calendarId, event.dateFields.day, event.dateFields.month, event.dateFields.year, title, description);
|
||||
if (eventId != null) {
|
||||
addReminder(eventId);
|
||||
}
|
||||
@@ -223,8 +221,8 @@ public class CalendarSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
* Adds a single event to the calendar.
|
||||
*/
|
||||
@Nullable
|
||||
private String addEvent(@NotNull String calendarId, int day, int month, @NotNull String title, @NotNull String description) {
|
||||
Log.d(TAG, "Create calendar event: day=" + day + ", month=" + month
|
||||
private String addEvent(@NotNull String calendarId, @Nullable Integer day, @Nullable Integer month, @Nullable Integer year, @NotNull String title, @NotNull String description) {
|
||||
Log.d(TAG, "Create calendar event: day=" + day + ", month=" + month + ", year=" + year
|
||||
+ ", title=" + title + ", description=" + description);
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(CalendarContract.Events.CALENDAR_ID, calendarId);
|
||||
@@ -233,9 +231,18 @@ public class CalendarSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
|
||||
TimeZone utc = TimeZone.getTimeZone("UTC");
|
||||
Calendar beginTime = Calendar.getInstance(utc);
|
||||
int currentYear = beginTime.get(Calendar.YEAR);
|
||||
if (day == null) {
|
||||
day = 1;
|
||||
}
|
||||
if (month == null) {
|
||||
month = 1;
|
||||
}
|
||||
if (year == null) {
|
||||
year = beginTime.get(Calendar.YEAR);
|
||||
}
|
||||
beginTime.clear();
|
||||
beginTime.set(currentYear, month - 1, day);
|
||||
beginTime.set(year, month - 1, day);
|
||||
|
||||
cv.put(CalendarContract.Events.DTSTART, beginTime.getTimeInMillis());
|
||||
cv.put(CalendarContract.Events.DURATION, "PT1D");
|
||||
cv.put(CalendarContract.Events.ALL_DAY, 1);
|
||||
|
||||
Reference in New Issue
Block a user