1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-24 09:35:50 +01:00

Xiaomi: Sync calendar event reminders

This commit is contained in:
José Rebelo 2024-04-25 15:00:48 +01:00
parent 67cf9b2f00
commit 13d6c49bb5
3 changed files with 9 additions and 3 deletions

View File

@ -106,6 +106,11 @@ public class XiaomiCalendarService extends AbstractXiaomiService {
thisSync.add(calendarEvent); thisSync.add(calendarEvent);
int notifyMinutesBefore = 0;
if (!calendarEvent.getRemindersAbsoluteTs().isEmpty()) {
notifyMinutesBefore = (int) ((calendarEvent.getBeginSeconds() * 1000L - calendarEvent.getRemindersAbsoluteTs().get(0)) / (1000 * 60));
}
final XiaomiProto.CalendarEvent xiaomiCalendarEvent = XiaomiProto.CalendarEvent.newBuilder() final XiaomiProto.CalendarEvent xiaomiCalendarEvent = XiaomiProto.CalendarEvent.newBuilder()
.setTitle(calendarEvent.getTitle()) .setTitle(calendarEvent.getTitle())
.setDescription(StringUtils.ensureNotNull(calendarEvent.getDescription())) .setDescription(StringUtils.ensureNotNull(calendarEvent.getDescription()))
@ -113,7 +118,7 @@ public class XiaomiCalendarService extends AbstractXiaomiService {
.setStart(calendarEvent.getBeginSeconds()) .setStart(calendarEvent.getBeginSeconds())
.setEnd((int) (calendarEvent.getEnd() / 1000)) .setEnd((int) (calendarEvent.getEnd() / 1000))
.setAllDay(calendarEvent.isAllDay()) .setAllDay(calendarEvent.isAllDay())
.setNotifyMinutesBefore(0) // TODO fetch from event .setNotifyMinutesBefore(notifyMinutesBefore)
.build(); .build();
calendarSync.addEvent(xiaomiCalendarEvent); calendarSync.addEvent(xiaomiCalendarEvent);

View File

@ -16,6 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. */ along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.util.calendar; package nodomain.freeyourgadget.gadgetbridge.util.calendar;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -31,7 +32,7 @@ public class CalendarEvent {
private final String organizer; private final String organizer;
private final int color; private final int color;
private final boolean allDay; private final boolean allDay;
private List<Long> remindersAbsoluteTs; private List<Long> remindersAbsoluteTs = new ArrayList<>();
public CalendarEvent(long begin, long end, long id, String title, String description, String location, String calName, String calAccountName, int color, boolean allDay, String organizer) { public CalendarEvent(long begin, long end, long id, String title, String description, String location, String calName, String calAccountName, int color, boolean allDay, String organizer) {
this.begin = begin; this.begin = begin;

View File

@ -139,7 +139,7 @@ public class CalendarManager {
LOG.debug("Reminder Method: {}, Minutes: {}", method, minutes); LOG.debug("Reminder Method: {}, Minutes: {}", method, minutes);
if (method == 1) //METHOD_ALERT if (method == 1) //METHOD_ALERT
reminders.add(calEvent.getBegin() + minutes * 60 * 1000); reminders.add(calEvent.getBegin() - minutes * 60 * 1000L);
} }
reminderCursor.close(); reminderCursor.close();