Search in sources :

Example 1 with Note

use of com.orgzly.android.Note in project orgzly-android by orgzly.

the class NotesClient method fromCursor.

public static Note fromCursor(Cursor cursor, boolean withExtras) {
    long id = idFromCursor(cursor);
    long createdAt = cursor.getLong(cursor.getColumnIndex(DbNoteView.CREATED_AT));
    int contentLines = cursor.getInt(cursor.getColumnIndex(DbNoteView.CONTENT_LINE_COUNT));
    OrgHead head = headFromCursor(cursor);
    NotePosition position = DbNote.positionFromCursor(cursor);
    Note note = new Note();
    note.setHead(head);
    note.setId(id);
    note.setCreatedAt(createdAt);
    note.setPosition(position);
    note.setContentLines(contentLines);
    if (withExtras) {
        String inheritedTags = cursor.getString(cursor.getColumnIndex(DbNoteView.INHERITED_TAGS));
        if (!TextUtils.isEmpty(inheritedTags)) {
            note.setInheritedTags(DbNote.dbDeSerializeTags(inheritedTags));
        }
    }
    return note;
}
Also used : OrgHead(com.orgzly.org.OrgHead) NotePosition(com.orgzly.android.NotePosition) Note(com.orgzly.android.Note) DbNote(com.orgzly.android.provider.models.DbNote)

Example 2 with Note

use of com.orgzly.android.Note in project orgzly-android by orgzly.

the class MainActivity method openNote.

private void openNote(long noteId) {
    finishActionMode();
    // TODO: Avoid using Shelf from activity directly
    Shelf shelf = new Shelf(this);
    Note note = shelf.getNote(noteId);
    if (note != null) {
        long bookId = note.getPosition().getBookId();
        Intent intent = new Intent(AppIntent.ACTION_OPEN_NOTE);
        intent.putExtra(AppIntent.EXTRA_NOTE_ID, noteId);
        intent.putExtra(AppIntent.EXTRA_BOOK_ID, bookId);
        LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
    }
}
Also used : Note(com.orgzly.android.Note) Shelf(com.orgzly.android.Shelf) Intent(android.content.Intent) AppIntent(com.orgzly.android.AppIntent)

Example 3 with Note

use of com.orgzly.android.Note 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 4 with Note

use of com.orgzly.android.Note in project orgzly-android by orgzly.

the class NoteFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    if (BuildConfig.LOG_DEBUG)
        LogUtils.d(TAG, savedInstanceState);
    super.onActivityCreated(savedInstanceState);
    if (mBookId != 0) {
        // FIXME: ANR reported
        mBook = mShelf.getBook(mBookId);
    }
    if (mIsNew) {
        /* Creating new note. */
        mNote = new Note();
        mNote.getPosition().setBookId(mBookId);
        updateNewNoteValues();
        mViewFlipper.setDisplayedChild(0);
        editSwitch.setChecked(true);
        /* Open keyboard for new notes, unless fragment was given
             * some initial values (for example from ShareActivity).
             */
        if (TextUtils.isEmpty(mInitialTitle) && TextUtils.isEmpty(mInitialContent)) {
            ActivityUtils.INSTANCE.openSoftKeyboard(getActivity(), mTitleView);
        }
    } else {
        /* Get existing note from database. */
        mNote = mShelf.getNote(mNoteId);
        if (mNote != null) {
            // TODO: Cleanup: getNote(id, withProperties) or such
            mNote.getHead().setProperties(mShelf.getNoteProperties(mNoteId));
            mViewFlipper.setDisplayedChild(0);
        } else {
            mViewFlipper.setDisplayedChild(1);
        }
    }
    if (mNote != null) {
        /* Get current values from saved Bundle and populate all views. */
        if (savedInstanceState != null) {
            updateNoteFromBundle(savedInstanceState);
        }
        /* Update views from note. */
        updateViewsFromNote();
    }
    /* Store the hash value of original note. */
    if (!getArguments().containsKey(ARG_ORIGINAL_NOTE_HASH) && mNote != null) {
        getArguments().putLong(ARG_ORIGINAL_NOTE_HASH, noteHash(mNote));
    }
    /* Refresh action bar items (hide or display, depending on if book is loaded. */
    if (getActivity() != null) {
        getActivity().invalidateOptionsMenu();
    }
}
Also used : Note(com.orgzly.android.Note)

Example 5 with Note

use of com.orgzly.android.Note in project orgzly-android by orgzly.

the class SettingsTest method testStateChangeAndNotesReparse.

@Test
public void testStateChangeAndNotesReparse() throws IOException {
    Note note;
    shelfTestUtils.setupBook("booky", "* TODO [#A] Title");
    AppPreferences.states(context, "TODO|DONE");
    shelf.reParseNotesStateAndTitles();
    note = shelf.getNote(1);
    assertEquals("TODO", note.getHead().getState());
    assertEquals("A", note.getHead().getPriority());
    assertEquals("Title", note.getHead().getTitle());
    AppPreferences.states(context, "");
    shelf.reParseNotesStateAndTitles();
    note = shelf.getNote(1);
    assertNull(note.getHead().getState());
    assertNull(note.getHead().getPriority());
    assertEquals("TODO [#A] Title", note.getHead().getTitle());
    AppPreferences.states(context, "TODO|DONE");
    shelf.reParseNotesStateAndTitles();
    note = shelf.getNote(1);
    assertEquals("TODO", note.getHead().getState());
    assertEquals("A", note.getHead().getPriority());
    assertEquals("Title", note.getHead().getTitle());
}
Also used : Note(com.orgzly.android.Note) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Aggregations

Note (com.orgzly.android.Note)29 OrgzlyTest (com.orgzly.android.OrgzlyTest)21 Test (org.junit.Test)21 Book (com.orgzly.android.Book)18 NotePosition (com.orgzly.android.NotePosition)11 NotePlace (com.orgzly.android.ui.NotePlace)4 OrgHead (com.orgzly.org.OrgHead)4 DbNote (com.orgzly.android.provider.models.DbNote)3 Intent (android.content.Intent)2 Cursor (android.database.Cursor)2 AppIntent (com.orgzly.android.AppIntent)2 Shelf (com.orgzly.android.Shelf)2 ContentValues (android.content.ContentValues)1 OrgProperties (com.orgzly.org.OrgProperties)1 OrgRange (com.orgzly.org.datetime.OrgRange)1 HashSet (java.util.HashSet)1