use of com.orgzly.org.datetime.OrgInterval in project orgzly-android by orgzly.
the class ReminderService method getNoteReminders.
public static List<NoteReminder> getNoteReminders(final Context context, final ReadableInstant now, final LastRun lastRun, final int beforeOrAfter) {
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG);
final List<NoteReminder> result = new ArrayList<>();
TimesClient.forEachTime(context, noteTime -> {
if (isRelevantNoteTime(context, noteTime)) {
OrgDateTime orgDateTime = OrgDateTime.parse(noteTime.orgTimestampString);
NoteReminderPayload payload = new NoteReminderPayload(noteTime.noteId, noteTime.bookId, noteTime.bookName, noteTime.title, noteTime.timeType, orgDateTime);
ReadableInstant[] interval = getInterval(beforeOrAfter, now, lastRun, noteTime.timeType);
DateTime time = OrgDateTimeUtils.getFirstWarningTime(noteTime.timeType, orgDateTime, interval[0], interval[1], // Default time of day
new OrgInterval(9, OrgInterval.Unit.HOUR), // Warning period for deadlines
new OrgInterval(1, OrgInterval.Unit.DAY));
if (time != null) {
result.add(new NoteReminder(time, payload));
}
}
});
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, "Fetched times, now sorting " + result.size() + " entries by time...");
/* Sort by time, older first. */
Collections.sort(result, (o1, o2) -> o1.getRunTime().compareTo(o2.getRunTime()));
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, "Times sorted, total " + result.size());
return result;
}
Aggregations