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());
}
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;
}
}
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;
}
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);
}
}
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());
}
}
Aggregations