From 33958ab548fd495cbb26bb0258747af6d48741e0 Mon Sep 17 00:00:00 2001 From: Ricki Hirner Date: Sun, 3 May 2015 22:36:16 +0200 Subject: [PATCH] Better reminder (VALARM) handling * handle WEEKS in duration correctly (fixes #398) * handle positive and negative TRIGGER duration values correctly --- .../davdroid/resource/LocalCalendar.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java index abbac808..f0845f5d 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java @@ -511,7 +511,7 @@ public class LocalCalendar extends LocalCollection { } void populateReminder(Event event, ContentValues row) throws RemoteException { - VAlarm alarm = new VAlarm(new Dur(0, 0, row.getAsInteger(Reminders.MINUTES), 0)); + VAlarm alarm = new VAlarm(new Dur(0, 0, -row.getAsInteger(Reminders.MINUTES), 0)); PropertyList props = alarm.getProperties(); props.add(Action.DISPLAY); @@ -722,12 +722,18 @@ public class LocalCalendar extends LocalCollection { protected Builder buildReminder(Builder builder, VAlarm alarm) { int minutes = 0; - Dur duration; - if (alarm.getTrigger() != null && (duration = alarm.getTrigger().getDuration()) != null) - minutes = duration.getDays() * 24*60 + duration.getHours()*60 + duration.getMinutes(); - - Log.d(TAG, "Adding alarm " + minutes + " min before"); - + if (alarm.getTrigger() != null) { + Dur duration = alarm.getTrigger().getDuration(); + if (duration != null) { + // negative value in TRIGGER means positive value in Reminders.MINUTES and vice versa + minutes = -(((duration.getWeeks() * 7 + duration.getDays()) * 24 + duration.getHours()) * 60 + duration.getMinutes()); + if (duration.isNegative()) + minutes *= -1; + } + } + + Log.d(TAG, "Adding alarm " + minutes + " minutes before"); + return builder .withValue(Reminders.METHOD, Reminders.METHOD_ALERT) .withValue(Reminders.MINUTES, minutes);