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);
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()
.setTitle(calendarEvent.getTitle())
.setDescription(StringUtils.ensureNotNull(calendarEvent.getDescription()))
@ -113,7 +118,7 @@ public class XiaomiCalendarService extends AbstractXiaomiService {
.setStart(calendarEvent.getBeginSeconds())
.setEnd((int) (calendarEvent.getEnd() / 1000))
.setAllDay(calendarEvent.isAllDay())
.setNotifyMinutesBefore(0) // TODO fetch from event
.setNotifyMinutesBefore(notifyMinutesBefore)
.build();
calendarSync.addEvent(xiaomiCalendarEvent);

View File

@ -16,6 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.util.calendar;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@ -31,7 +32,7 @@ public class CalendarEvent {
private final String organizer;
private final int color;
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) {
this.begin = begin;

View File

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