Hide future events

This commit is contained in:
Herbert Reiter
2020-01-05 12:55:18 +01:00
parent cb92d6c7b2
commit 06f968058a
@@ -204,14 +204,12 @@ public class CalendarSyncAdapter extends AbstractThreadedSyncAdapter {
private void addEvents(@NotNull String calendarId, @NotNull List<TerminPlugin.Event> events) { private void addEvents(@NotNull String calendarId, @NotNull List<TerminPlugin.Event> events) {
Log.d(TAG, "Create calendar events"); Log.d(TAG, "Create calendar events");
for (TerminPlugin.Event event : 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; String title = event.description;
if (title == null) { if (title == null) {
title = PathUtils.extractWebName(event.pagePath); title = PathUtils.extractWebName(event.pagePath);
} }
String description = getContext().getString(R.string.calendar_date) + ": " + TerminPlugin.formatGermanDate(event.dateFields); 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) { if (eventId != null) {
addReminder(eventId); addReminder(eventId);
} }
@@ -223,8 +221,8 @@ public class CalendarSyncAdapter extends AbstractThreadedSyncAdapter {
* Adds a single event to the calendar. * Adds a single event to the calendar.
*/ */
@Nullable @Nullable
private String addEvent(@NotNull String calendarId, int day, int month, @NotNull String title, @NotNull String description) { 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 Log.d(TAG, "Create calendar event: day=" + day + ", month=" + month + ", year=" + year
+ ", title=" + title + ", description=" + description); + ", title=" + title + ", description=" + description);
ContentValues cv = new ContentValues(); ContentValues cv = new ContentValues();
cv.put(CalendarContract.Events.CALENDAR_ID, calendarId); cv.put(CalendarContract.Events.CALENDAR_ID, calendarId);
@@ -233,9 +231,18 @@ public class CalendarSyncAdapter extends AbstractThreadedSyncAdapter {
TimeZone utc = TimeZone.getTimeZone("UTC"); TimeZone utc = TimeZone.getTimeZone("UTC");
Calendar beginTime = Calendar.getInstance(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.clear();
beginTime.set(currentYear, month - 1, day); beginTime.set(year, month - 1, day);
cv.put(CalendarContract.Events.DTSTART, beginTime.getTimeInMillis()); cv.put(CalendarContract.Events.DTSTART, beginTime.getTimeInMillis());
cv.put(CalendarContract.Events.DURATION, "PT1D"); cv.put(CalendarContract.Events.DURATION, "PT1D");
cv.put(CalendarContract.Events.ALL_DAY, 1); cv.put(CalendarContract.Events.ALL_DAY, 1);