From 008ee4e0cdc46ba0097f03811f601c054c59ac16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey?= Date: Tue, 25 Oct 2022 18:19:50 +0200 Subject: [PATCH 1/3] SaveCalendar: don't try to export empty calendars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Causes crashes Signed-off-by: Álvaro Brey --- .../sufficientlysecure/SaveCalendar.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/third_parties/sufficientlysecure/SaveCalendar.java b/app/src/main/java/third_parties/sufficientlysecure/SaveCalendar.java index 259557fbaf..b49c4cd8b7 100644 --- a/app/src/main/java/third_parties/sufficientlysecure/SaveCalendar.java +++ b/app/src/main/java/third_parties/sufficientlysecure/SaveCalendar.java @@ -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 has " + selectedCal.mIdStr + "no components"); } - - // TODO replace DisplayUtils.showSnackMessage(activity, msg); - - upload(fileName); } private int ensureUids(Context activity, ContentResolver resolver, AndroidCalendar cal) { From b3eab117db80c4f2e783cec40dab54b3efe68dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey?= Date: Mon, 21 Nov 2022 17:12:57 +0100 Subject: [PATCH 2/3] calendar export: port some changes from upstream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ignore deleted events, and fix alarm triggers Signed-off-by: Álvaro Brey --- .../sufficientlysecure/AndroidCalendar.java | 2 +- .../sufficientlysecure/ProcessVEvent.java | 14 ++++++++++---- .../sufficientlysecure/SaveCalendar.java | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/third_parties/sufficientlysecure/AndroidCalendar.java b/app/src/main/java/third_parties/sufficientlysecure/AndroidCalendar.java index fb6de77838..e19b067e9c 100644 --- a/app/src/main/java/third_parties/sufficientlysecure/AndroidCalendar.java +++ b/app/src/main/java/third_parties/sufficientlysecure/AndroidCalendar.java @@ -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); diff --git a/app/src/main/java/third_parties/sufficientlysecure/ProcessVEvent.java b/app/src/main/java/third_parties/sufficientlysecure/ProcessVEvent.java index 60887c548b..baf386c98e 100644 --- a/app/src/main/java/third_parties/sufficientlysecure/ProcessVEvent.java +++ b/app/src/main/java/third_parties/sufficientlysecure/ProcessVEvent.java @@ -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 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); } diff --git a/app/src/main/java/third_parties/sufficientlysecure/SaveCalendar.java b/app/src/main/java/third_parties/sufficientlysecure/SaveCalendar.java index b49c4cd8b7..fcdf8ffc96 100644 --- a/app/src/main/java/third_parties/sufficientlysecure/SaveCalendar.java +++ b/app/src/main/java/third_parties/sufficientlysecure/SaveCalendar.java @@ -203,7 +203,7 @@ public class SaveCalendar { upload(fileName); } else { - Log_OC.w(TAG, "Calendar has " + selectedCal.mIdStr + "no components"); + Log_OC.w(TAG, "Calendar '" + selectedCal.mIdStr + "' has no components"); } } From 850e9e7ec3842c96b0fa529c7c5ca898015daead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey?= Date: Mon, 21 Nov 2022 18:17:44 +0100 Subject: [PATCH 3/3] CalendarBackupWork: log amount of calendars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Brey --- .../main/java/com/nextcloud/client/jobs/CalendarBackupWork.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/CalendarBackupWork.kt b/app/src/main/java/com/nextcloud/client/jobs/CalendarBackupWork.kt index 6dbfd5cc36..1064c6bf57 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/CalendarBackupWork.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/CalendarBackupWork.kt @@ -59,7 +59,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,