use of com.orgzly.org.OrgHead in project orgzly-android by orgzly.
the class NoteFragment method updateBundleFromNote.
/**
* Note -> Bundle
*/
private void updateBundleFromNote(Bundle outState) {
OrgHead head = mNote.getHead();
outState.putString(ARG_CURRENT_STATE, head.getState());
outState.putString(ARG_CURRENT_PRIORITY, head.getPriority());
outState.putString(ARG_CURRENT_TITLE, head.getTitle());
outState.putString(ARG_CURRENT_TAGS, TextUtils.join(" ", head.getTags()));
if (head.getScheduled() != null) {
outState.putString(ARG_CURRENT_SCHEDULED, head.getScheduled().toString());
}
if (head.getDeadline() != null) {
outState.putString(ARG_CURRENT_DEADLINE, head.getDeadline().toString());
}
if (head.getClosed() != null) {
outState.putString(ARG_CURRENT_CLOSED, head.getClosed().toString());
}
/* Store properties as an array of strings.
*
* name1 value1 name2 value2
*/
if (head.hasProperties()) {
ArrayList<String> list = MiscUtils.toArrayList(head.getProperties());
outState.putStringArrayList(ARG_CURRENT_PROPERTIES, list);
} else {
outState.remove(ARG_CURRENT_PROPERTIES);
}
outState.putString(ARG_CURRENT_CONTENT, head.getContent());
}
use of com.orgzly.org.OrgHead 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.OrgHead in project orgzly-android by orgzly.
the class LipsumBookGenerator method generateOrgString.
public static String generateOrgString(int content, int[] notesAndContent) {
StringBuilder result = new StringBuilder();
LoremIpsum loremIpsum = new LoremIpsum();
OrgParserWriter parserWriter = new OrgParserWriter();
result.append(parserWriter.whiteSpacedFilePreface(loremIpsum.getWords(content / CHARS_PER_WORD)));
if (notesAndContent != null) {
for (int i = 0; i < notesAndContent.length; i += 2) {
OrgHead head = new OrgHead();
head.setTitle(loremIpsum.getWords(notesAndContent[i] / CHARS_PER_WORD));
head.setContent(loremIpsum.getWords(notesAndContent[i + 1] / CHARS_PER_WORD));
result.append(parserWriter.whiteSpacedHead(head, 1, false));
}
}
return result.toString();
}
use of com.orgzly.org.OrgHead in project orgzly-android by orgzly.
the class StructureTest method testCut.
@Test
public void testCut() {
Book book = shelfTestUtils.setupBook("notebook", "" + "description\n" + "* Note #1.\n" + "* Note #2.\n" + "** Note #3.\n" + "** Note #4.\n" + "*** Note #5.\n" + "**** Note #6.\n" + "** Note #7.\n" + "* Note #8.\n" + "**** Note #9.\n" + "** Note #10.\n" + "");
Set<Long> ids = new HashSet<>();
ids.add(1L);
ids.add(2L);
shelf.cut(book.getId(), ids);
assertEquals("There should be less notes in the book", 8, NotesClient.getCount(context, book.getId()));
Cursor cursor = NotesClient.getCursorForBook(context, book.getName());
try {
Note note;
OrgHead head;
cursor.moveToFirst();
note = NotesClient.fromCursor(cursor);
head = note.getHead();
assertEquals("Title for book should match", "Note #2.", head.getTitle());
assertEquals("Level for book should match", 1, note.getPosition().getLevel());
cursor.moveToNext();
note = NotesClient.fromCursor(cursor);
head = note.getHead();
assertEquals("Title for book should match", "Note #4.", head.getTitle());
assertEquals("Level for book should match", 2, note.getPosition().getLevel());
cursor.moveToNext();
note = NotesClient.fromCursor(cursor);
head = note.getHead();
assertEquals("Title for book should match", "Note #5.", head.getTitle());
assertEquals("Level for book should match", 3, note.getPosition().getLevel());
} finally {
cursor.close();
}
}
Aggregations