Merge pull request #10928 from nextcloud/test/calendar-skip-empty

Fix issues with calendar exporting
This commit is contained in:
Álvaro Brey 2022-11-23 22:11:31 +01:00 committed by GitHub
commit 1c4a1063f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 15 deletions

View file

@ -60,7 +60,9 @@ class CalendarBackupWork(
val force = inputData.getBoolean(FORCE, false)
if (force || lastExecution + JOB_INTERVAL_MS < Calendar.getInstance().timeInMillis) {
AndroidCalendar.loadAll(contentResolver).forEach { calendar ->
val calendars = AndroidCalendar.loadAll(contentResolver)
Log_OC.d(TAG, "Saving ${calendars.size} calendars")
calendars.forEach { calendar ->
SaveCalendar(
applicationContext,
calendar,

View file

@ -101,7 +101,7 @@ public class AndroidCalendar {
calendar.mTimezone = getString(cur, Calendars.CALENDAR_TIME_ZONE);
final String[] args = new String[]{calendar.mIdStr};
Cursor eventsCur = resolver.query(Events.CONTENT_URI, CAL_ID_COLS, CAL_ID_WHERE, args, null);
Cursor eventsCur = resolver.query(Events.CONTENT_URI, CAL_ID_COLS, CAL_ID_WHERE + " AND deleted=0", args, null);
calendar.mNumEntries = eventsCur.getCount();
eventsCur.close();
calendars.add(calendar);

View file

@ -433,18 +433,24 @@ public class ProcessVEvent {
// - Check the calendars max number of alarms
if (t.getDateTime() != null) {
alarmMs = t.getDateTime().getTime(); // Absolute
} else if (t.getDuration() != null && t.getDuration().isNegative()) {
} else if (t.getDuration() != null && t.getDuration().isNegative()) { //alarm trigger before start of event
Related rel = (Related) t.getParameter(Parameter.RELATED);
if (rel != null && rel == Related.END) {
alarmStartMs = e.getEndDate().getDate().getTime();
}
alarmMs = alarmStartMs - durationToMs(t.getDuration()); // Relative
alarmMs = alarmStartMs - durationToMs(t.getDuration()); // Relative "-"
} else if (t.getDuration() != null && !t.getDuration().isNegative()) { //alarm trigger after start of event
Related rel = (Related) t.getParameter(Parameter.RELATED);
if (rel != null && rel == Related.END) {
alarmStartMs = e.getEndDate().getDate().getTime();
}
alarmMs = alarmStartMs + durationToMs(t.getDuration()); // Relative "+"
} else {
continue;
}
int reminder = (int) ((startMs - alarmMs) / DateUtils.MINUTE_IN_MILLIS);
if (reminder >= 0 && !reminders.contains(reminder)) {
if (!reminders.contains(reminder)) {
reminders.add(reminder);
}
}
@ -520,7 +526,7 @@ public class ProcessVEvent {
}
private Cursor queryEvents(ContentResolver resolver, StringBuilder b, List<String> argsList) {
final String where = b.toString();
final String where = b.toString() + " AND deleted=0";
final String[] args = argsList.toArray(new String[argsList.size()]);
return resolver.query(Events.CONTENT_URI, EVENT_QUERY_COLUMNS, where, args, null);
}

View file

@ -190,17 +190,21 @@ public class SaveCalendar {
cal.getComponents().add(v);
}
new CalendarOutputter().output(cal, new FileOutputStream(fileName));
if (!cal.getComponents().isEmpty()) {
new CalendarOutputter().output(cal, new FileOutputStream(fileName));
Resources res = activity.getResources();
String msg = res.getQuantityString(R.plurals.wrote_n_events_to, events.size(), events.size(), file);
if (numberOfCreatedUids > 0) {
msg += "\n" + res.getQuantityString(R.plurals.created_n_uids_to, numberOfCreatedUids, numberOfCreatedUids);
Resources res = activity.getResources();
String msg = res.getQuantityString(R.plurals.wrote_n_events_to, events.size(), events.size(), file);
if (numberOfCreatedUids > 0) {
msg += "\n" + res.getQuantityString(R.plurals.created_n_uids_to, numberOfCreatedUids, numberOfCreatedUids);
}
// TODO replace DisplayUtils.showSnackMessage(activity, msg);
upload(fileName);
} else {
Log_OC.w(TAG, "Calendar '" + selectedCal.mIdStr + "' has no components");
}
// TODO replace DisplayUtils.showSnackMessage(activity, msg);
upload(fileName);
}
private int ensureUids(Context activity, ContentResolver resolver, AndroidCalendar cal) {