Search in sources :

Example 11 with OrgDateTime

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);
}
Also used : Calendar(java.util.Calendar) OrgDateTime(com.orgzly.org.datetime.OrgDateTime)

Example 12 with OrgDateTime

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

Example 13 with OrgDateTime

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

Example 14 with OrgDateTime

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());
    }
}
Also used : OrgHead(com.orgzly.org.OrgHead) Calendar(java.util.Calendar) OrgDateTime(com.orgzly.org.datetime.OrgDateTime) OrgRange(com.orgzly.org.datetime.OrgRange)

Example 15 with OrgDateTime

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);
}
Also used : OrgDateTime(com.orgzly.org.datetime.OrgDateTime) TimestampDialogFragment(com.orgzly.android.ui.dialogs.TimestampDialogFragment)

Aggregations

OrgDateTime (com.orgzly.org.datetime.OrgDateTime)16 ArrayList (java.util.ArrayList)4 Cursor (android.database.Cursor)3 Calendar (java.util.Calendar)3 DateTime (org.joda.time.DateTime)3 ContentValues (android.content.ContentValues)2 DbNote (com.orgzly.android.provider.models.DbNote)2 OrgRepeater (com.orgzly.org.datetime.OrgRepeater)2 SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.app.AlertDialog)1 DatePickerDialog (android.app.DatePickerDialog)1 Dialog (android.app.Dialog)1 TimePickerDialog (android.app.TimePickerDialog)1 ContentProviderOperation (android.content.ContentProviderOperation)1 Context (android.content.Context)1 OperationApplicationException (android.content.OperationApplicationException)1 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)1 Bundle (android.os.Bundle)1 RemoteException (android.os.RemoteException)1 DialogFragment (android.support.v4.app.DialogFragment)1