Search in sources :

Example 1 with OrgInterval

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;
}
Also used : ReadableInstant(org.joda.time.ReadableInstant) OrgInterval(com.orgzly.org.datetime.OrgInterval) ArrayList(java.util.ArrayList) OrgDateTime(com.orgzly.org.datetime.OrgDateTime) DateTime(org.joda.time.DateTime) OrgDateTime(com.orgzly.org.datetime.OrgDateTime)

Aggregations

OrgDateTime (com.orgzly.org.datetime.OrgDateTime)1 OrgInterval (com.orgzly.org.datetime.OrgInterval)1 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 ReadableInstant (org.joda.time.ReadableInstant)1