use of com.orgzly.org.datetime.OrgDateTime in project orgzly-android by orgzly.
the class OrgzlyTest method defaultDialogUserDate.
protected String defaultDialogUserDate() {
OrgDateTime time = new OrgDateTime(true);
/* Default time is now + 1h.
* TODO: We shouldn't be able to do this - make OrgDateTime immutable.
*/
Calendar cal = time.getCalendar();
cal.add(Calendar.HOUR_OF_DAY, 1);
return userTimeFormatter.formatDate(time);
}
use of com.orgzly.org.datetime.OrgDateTime in project orgzly-android by orgzly.
the class AgendaUtils method expandOrgDateTime.
private static List<DateTime> expandOrgDateTime(OrgRange range, DateTime now, int days) {
List<DateTime> result = new ArrayList<>();
OrgDateTime rangeStart = range.getStartTime();
OrgDateTime rangeEnd = range.getEndTime();
// Add today if task is overdue
if (rangeStart.getCalendar().before(now.toGregorianCalendar())) {
result.add(now.withTimeAtStartOfDay());
}
DateTime to = now.plusDays(days).withTimeAtStartOfDay();
if (rangeEnd == null) {
result.addAll(OrgDateTimeUtils.getTimesInInterval(rangeStart, now, to, true, 0));
} else {
// a time range
if (to.isAfter(rangeEnd.getCalendar().getTimeInMillis())) {
to = new DateTime(rangeEnd.getCalendar()).withTimeAtStartOfDay().plusDays(1);
}
// if start time has no repeater, use a daily repeater
if (!rangeStart.hasRepeater()) {
DateTime start = new DateTime(rangeStart.getCalendar());
rangeStart = buildOrgDateTimeFromDate(start, OrgRepeater.parse("++1d"));
}
result.addAll(OrgDateTimeUtils.getTimesInInterval(rangeStart, now, to, true, 0));
}
return result;
}
use of com.orgzly.org.datetime.OrgDateTime in project orgzly-android by orgzly.
the class ReminderService method onSnoozeTriggered.
private void onSnoozeTriggered(final Context context, final long noteId, final int noteTimeType, final long timestamp) {
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, noteId, timestamp);
String msg;
// FIXME TODO replace this with a simpler query, may need to create it in notesclient
final List<NoteReminder> result = new ArrayList<>();
TimesClient.forEachTime(context, noteTime -> {
if (noteTime.noteId == noteId && noteTime.timeType == noteTimeType && isRelevantNoteTime(context, noteTime)) {
OrgDateTime orgDateTime = OrgDateTime.parse(noteTime.orgTimestampString);
NoteReminderPayload payload = new NoteReminderPayload(noteTime.noteId, noteTime.bookId, noteTime.bookName, noteTime.title, noteTime.timeType, orgDateTime);
DateTime timestampDateTime = new DateTime(timestamp);
result.add(new NoteReminder(timestampDateTime, payload));
}
});
if (!result.isEmpty()) {
msg = "Found " + result.size() + " notes";
showNotification(this, result);
} else {
msg = "No notes found";
}
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, msg);
}
use of com.orgzly.org.datetime.OrgDateTime in project orgzly-android by orgzly.
the class NoteFragment method updateNewNoteValues.
/**
* Set new Note's initial values.
*/
private void updateNewNoteValues() {
OrgHead head = mNote.getHead();
/* Set scheduled time for a new note. */
if (AppPreferences.isNewNoteScheduled(getContext())) {
Calendar cal = Calendar.getInstance();
OrgDateTime timestamp = new OrgDateTime.Builder().setIsActive(true).setYear(cal.get(Calendar.YEAR)).setMonth(cal.get(Calendar.MONTH)).setDay(cal.get(Calendar.DAY_OF_MONTH)).build();
OrgRange time = new OrgRange(timestamp);
head.setScheduled(time);
}
/* Set state for a new note. */
String stateKeyword = AppPreferences.newNoteState(getContext());
if (NoteStates.Companion.isKeyword(stateKeyword)) {
head.setState(stateKeyword);
} else {
head.setState(null);
}
/* Initial title. */
if (mInitialTitle != null) {
head.setTitle(mInitialTitle);
}
StringBuilder content = new StringBuilder();
/* Initial content. */
if (mInitialContent != null) {
if (content.length() > 0) {
content.append("\n\n");
}
content.append(mInitialContent);
}
if (content.length() > 0) {
head.setContent(content.toString());
}
}
use of com.orgzly.org.datetime.OrgDateTime in project orgzly-android by orgzly.
the class NoteListFragment method displayScheduleTimestampDialog.
protected void displayScheduleTimestampDialog(int id, Set<Long> noteIds) {
OrgDateTime time = null;
/* If there is only one note, use its time as dialog's default. */
if (noteIds.size() == 1) {
time = getScheduledTimeForNote(noteIds.iterator().next());
}
TimestampDialogFragment f = TimestampDialogFragment.getInstance(id, R.string.schedule, noteIds, time);
f.setTargetFragment(this, 0);
f.show(getActivity().getSupportFragmentManager(), TimestampDialogFragment.FRAGMENT_TAG);
}
Aggregations