Search in sources :

Example 1 with OrgRange

use of com.orgzly.org.datetime.OrgRange in project orgzly-android by orgzly.

the class SyncTest method testOrgRange.

@Test
public void testOrgRange() {
    shelfTestUtils.setupRepo("mock://repo-a");
    shelfTestUtils.setupRook("mock://repo-a", "mock://repo-a/remote-book-1.org", "* Note\nSCHEDULED: <2015-01-13 уто 13:00-14:14>--<2015-01-14 сре 14:10-15:20>", "0abcdef", 1400067156);
    shelf.sync();
    Note note = shelf.getNote(2);
    /* ID 1 was a root from dummy which was deleted. */
    OrgRange range = note.getHead().getScheduled();
    assertEquals("<2015-01-13 уто 13:00-14:14>--<2015-01-14 сре 14:10-15:20>", range.toString());
}
Also used : Note(com.orgzly.android.Note) OrgRange(com.orgzly.org.datetime.OrgRange) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 2 with OrgRange

use of com.orgzly.org.datetime.OrgRange in project orgzly-android by orgzly.

the class NoteFragment method onDateTimeSet.

@Override
public /* TimestampDialog */
void onDateTimeSet(int id, TreeSet<Long> noteIds, OrgDateTime time) {
    if (mNote == null) {
        return;
    }
    OrgHead head = mNote.getHead();
    OrgRange range = new OrgRange(time);
    switch(id) {
        case R.id.fragment_note_scheduled_button:
            updateTimestampView(TimeType.SCHEDULED, mScheduledButton, range);
            head.setScheduled(range);
            break;
        case R.id.fragment_note_deadline_button:
            updateTimestampView(TimeType.DEADLINE, mDeadlineButton, range);
            head.setDeadline(range);
            break;
        case R.id.fragment_note_closed_button:
            updateTimestampView(TimeType.CLOSED, mClosedButton, range);
            head.setClosed(range);
            break;
    }
}
Also used : OrgHead(com.orgzly.org.OrgHead) OrgRange(com.orgzly.org.datetime.OrgRange)

Example 3 with OrgRange

use of com.orgzly.org.datetime.OrgRange in project orgzly-android by orgzly.

the class AgendaUtils method expandOrgDateTime.

/**
 * This method returns only one {@link DateTime} per day
 * to avoid displaying the same note multiple times.
 */
public static Set<DateTime> expandOrgDateTime(String[] rangeStrings, DateTime now, int days) {
    Set<DateTime> set = new TreeSet<>();
    for (String rangeString : rangeStrings) {
        OrgRange range = OrgRange.parseOrNull(rangeString);
        if (range != null) {
            set.addAll(expandOrgDateTime(range, now, days));
        }
    }
    /* Truncate and remove duplicates. */
    Set<DateTime> result = new TreeSet<>();
    for (DateTime dt : set) {
        result.add(dt.withTimeAtStartOfDay());
    }
    return result;
}
Also used : TreeSet(java.util.TreeSet) DateTime(org.joda.time.DateTime) OrgDateTime(com.orgzly.org.datetime.OrgDateTime) OrgRange(com.orgzly.org.datetime.OrgRange)

Example 4 with OrgRange

use of com.orgzly.org.datetime.OrgRange in project orgzly-android by orgzly.

the class NotesClient method updateScheduledTime.

public static void updateScheduledTime(Context context, Set<Long> noteIds, OrgDateTime time) {
    ArrayList<ContentProviderOperation> ops = new ArrayList<>();
    String noteIdsCommaSeparated = TextUtils.join(",", noteIds);
    /* Update notes. */
    ContentValues values = new ContentValues();
    if (time != null) {
        values.put(ProviderContract.Notes.UpdateParam.SCHEDULED_STRING, new OrgRange(time).toString());
    } else {
        values.putNull(ProviderContract.Notes.UpdateParam.SCHEDULED_STRING);
    }
    ops.add(ContentProviderOperation.newUpdate(ProviderContract.Notes.ContentUri.notes()).withValues(values).withSelection(ProviderContract.Notes.UpdateParam._ID + " IN (" + noteIdsCommaSeparated + ")", null).build());
    updateBooksMtimeForNotes(context, noteIdsCommaSeparated, ops);
    /*
         * Apply batch.
         */
    try {
        context.getContentResolver().applyBatch(ProviderContract.AUTHORITY, ops);
    } catch (RemoteException | OperationApplicationException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : ContentValues(android.content.ContentValues) ContentProviderOperation(android.content.ContentProviderOperation) ArrayList(java.util.ArrayList) RemoteException(android.os.RemoteException) OrgRange(com.orgzly.org.datetime.OrgRange) OperationApplicationException(android.content.OperationApplicationException)

Example 5 with OrgRange

use of com.orgzly.org.datetime.OrgRange 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)

Aggregations

OrgRange (com.orgzly.org.datetime.OrgRange)5 OrgHead (com.orgzly.org.OrgHead)2 OrgDateTime (com.orgzly.org.datetime.OrgDateTime)2 ContentProviderOperation (android.content.ContentProviderOperation)1 ContentValues (android.content.ContentValues)1 OperationApplicationException (android.content.OperationApplicationException)1 RemoteException (android.os.RemoteException)1 Note (com.orgzly.android.Note)1 OrgzlyTest (com.orgzly.android.OrgzlyTest)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 TreeSet (java.util.TreeSet)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1