Search in sources :

Example 11 with OrgHead

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());
}
Also used : OrgHead(com.orgzly.org.OrgHead)

Example 12 with OrgHead

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

Example 13 with OrgHead

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();
}
Also used : LoremIpsum(de.svenjacobs.loremipsum.LoremIpsum) OrgHead(com.orgzly.org.OrgHead) OrgParserWriter(com.orgzly.org.parser.OrgParserWriter)

Example 14 with OrgHead

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();
    }
}
Also used : Book(com.orgzly.android.Book) OrgHead(com.orgzly.org.OrgHead) Note(com.orgzly.android.Note) Cursor(android.database.Cursor) HashSet(java.util.HashSet) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Aggregations

OrgHead (com.orgzly.org.OrgHead)14 Note (com.orgzly.android.Note)4 Cursor (android.database.Cursor)2 DbNote (com.orgzly.android.provider.models.DbNote)2 OrgRange (com.orgzly.org.datetime.OrgRange)2 OrgParserWriter (com.orgzly.org.parser.OrgParserWriter)2 ContentProviderOperation (android.content.ContentProviderOperation)1 ContentValues (android.content.ContentValues)1 Intent (android.content.Intent)1 OperationApplicationException (android.content.OperationApplicationException)1 RemoteException (android.os.RemoteException)1 View (android.view.View)1 MultiAutoCompleteTextView (android.widget.MultiAutoCompleteTextView)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 AppIntent (com.orgzly.android.AppIntent)1 Book (com.orgzly.android.Book)1 NotePosition (com.orgzly.android.NotePosition)1 OrgzlyTest (com.orgzly.android.OrgzlyTest)1 CircularArrayList (com.orgzly.android.util.CircularArrayList)1