Search in sources :

Example 1 with NotePlace

use of com.orgzly.android.ui.NotePlace in project orgzly-android by orgzly.

the class BookFragment method newNoteRelativeToSelection.

/*
    * Actions
    */
private void newNoteRelativeToSelection(Place place) {
    long targetNoteId = getTargetNoteIdFromSelection(place);
    listener.onNoteNewRequest(new NotePlace(mBookId, targetNoteId, place));
}
Also used : NotePlace(com.orgzly.android.ui.NotePlace)

Example 2 with NotePlace

use of com.orgzly.android.ui.NotePlace in project orgzly-android by orgzly.

the class BookFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    if (BuildConfig.LOG_DEBUG)
        LogUtils.d(TAG, view, savedInstanceState);
    super.onViewCreated(view, savedInstanceState);
    mIsViewCreated = true;
    /* Long click listener. */
    getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            if (position > getListView().getHeaderViewsCount() - 1) {
                /* Not a header. */
                listener.onNoteLongClick(BookFragment.this, view, position, id, id);
                return true;
            } else {
                return false;
            }
        }
    });
    /* Item toolbar listener. */
    getListView().setOnItemMenuButtonClickListener((itemView, buttonId, noteId) -> {
        if (BuildConfig.LOG_DEBUG)
            LogUtils.d(TAG, buttonId, noteId);
        switch(buttonId) {
            case R.id.item_menu_delete_btn:
                delete(MiscUtils.set(noteId));
                /* Remove selection. */
                mSelection.clearSelection();
                break;
            case R.id.item_menu_new_above_btn:
                listener.onNoteNewRequest(new NotePlace(mBookId, noteId, Place.ABOVE));
                break;
            case R.id.item_menu_new_under_btn:
                listener.onNoteNewRequest(new NotePlace(mBookId, noteId, Place.UNDER));
                break;
            case R.id.item_menu_new_below_btn:
                listener.onNoteNewRequest(new NotePlace(mBookId, noteId, Place.BELOW));
                break;
            default:
                onButtonClick(listener, itemView, buttonId, noteId);
        }
    });
    /* If it's not set to null, we get java.lang.IllegalStateException:
         *   Cannot add header view to list -- setAdapter has already been called.
         * This happens when trying to set header for list, when getting fragment from back stack.
         */
    setListAdapter(null);
    /* Add selectable header to the list view. */
    getListView().addHeaderView(mHeader, null, true);
    /* Create a selection. Must be aware of number of headers. */
    mSelection = new Selection();
    mListAdapter = new HeadsListViewAdapter(getActivity(), mSelection, getListView().getItemMenus(), true);
    setListAdapter(mListAdapter);
    mSelection.restoreIds(savedInstanceState);
/* Reset from ids will be performed after loading the data. */
}
Also used : Selection(com.orgzly.android.ui.Selection) HeadsListViewAdapter(com.orgzly.android.ui.HeadsListViewAdapter) NotePlace(com.orgzly.android.ui.NotePlace) AdapterView(android.widget.AdapterView) GesturedListView(com.orgzly.android.ui.views.GesturedListView) View(android.view.View) AdapterView(android.widget.AdapterView) DbNoteView(com.orgzly.android.provider.views.DbNoteView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 3 with NotePlace

use of com.orgzly.android.ui.NotePlace in project orgzly-android by orgzly.

the class StructureTest method testParentIdForCreatedNote.

@Test
public void testParentIdForCreatedNote() throws IOException {
    Book book = shelfTestUtils.setupBook("notebook", "" + "description\n" + "\n" + "* Note 1\n");
    Note newNote = new Note();
    newNote.getPosition().setBookId(book.getId());
    newNote.getHead().setTitle("Note 1.1");
    shelf.createNote(newNote, new NotePlace(book.getId(), shelf.getNote("Note 1").getId(), Place.UNDER));
    assertEquals(1, shelf.getNote("Note 1").getPosition().getDescendantsCount());
    assertEquals(shelf.getNote("Note 1").getId(), shelf.getNote("Note 1.1").getPosition().getParentId());
}
Also used : Book(com.orgzly.android.Book) Note(com.orgzly.android.Note) NotePlace(com.orgzly.android.ui.NotePlace) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 4 with NotePlace

use of com.orgzly.android.ui.NotePlace in project orgzly-android by orgzly.

the class StructureTest method testNewBelowFoldable.

@Test
public void testNewBelowFoldable() throws IOException {
    Book book = shelfTestUtils.setupBook("notebook", "" + "description\n" + "\n" + "* Note 1\n" + "** Note 1.1\n");
    Note newNote = new Note();
    newNote.getPosition().setBookId(book.getId());
    newNote.getHead().setTitle("Note 2");
    shelf.createNote(newNote, new NotePlace(book.getId(), shelf.getNote("Note 1").getId(), Place.BELOW));
    assertEquals("description\n" + "\n" + "* Note 1\n" + "** Note 1.1\n" + "* Note 2\n", shelf.getBookContent("notebook", BookName.Format.ORG));
    NotePosition n1 = shelf.getNote("Note 1").getPosition();
    NotePosition n11 = shelf.getNote("Note 1.1").getPosition();
    NotePosition n2 = shelf.getNote("Note 2").getPosition();
    assertTrue(n1.getLft() < n11.getLft());
    assertTrue(n11.getLft() < n11.getRgt());
    assertTrue(n11.getRgt() < n1.getRgt());
    assertTrue(n1.getRgt() < n2.getLft());
    assertTrue(n2.getLft() < n2.getRgt());
    assertEquals(0, n2.getDescendantsCount());
    assertEquals(shelf.getNote("").getId(), n2.getParentId());
}
Also used : Book(com.orgzly.android.Book) NotePosition(com.orgzly.android.NotePosition) Note(com.orgzly.android.Note) NotePlace(com.orgzly.android.ui.NotePlace) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 5 with NotePlace

use of com.orgzly.android.ui.NotePlace in project orgzly-android by orgzly.

the class StructureTest method testNewNoteUnder.

@Test
public void testNewNoteUnder() throws IOException {
    Book book = shelfTestUtils.setupBook("notebook", "description\n" + "* Note 1\n" + "** Note 1.1\n" + "*** Note 1.1.1\n" + "** Note 1.2\n");
    NotePosition note1, note11, note111, note12, note112;
    note1 = shelf.getNote("Note 1").getPosition();
    note11 = shelf.getNote("Note 1.1").getPosition();
    note111 = shelf.getNote("Note 1.1.1").getPosition();
    note12 = shelf.getNote("Note 1.2").getPosition();
    assertTrue(note1.getLft() < note11.getLft());
    assertTrue(note11.getLft() < note111.getLft());
    assertTrue(note111.getLft() < note111.getRgt());
    assertTrue(note111.getRgt() < note11.getRgt());
    assertTrue(note11.getRgt() < note12.getLft());
    assertTrue(note12.getLft() < note12.getRgt());
    assertTrue(note12.getRgt() < note1.getRgt());
    assertEquals(3, note1.getDescendantsCount());
    assertEquals(1, note11.getDescendantsCount());
    assertEquals(0, note111.getDescendantsCount());
    assertEquals(0, note12.getDescendantsCount());
    /* Create new note under Note 1.1. */
    Note n = new Note();
    n.getPosition().setBookId(book.getId());
    n.getHead().setTitle("Note 1.1.2");
    NotePlace target = new NotePlace(book.getId(), shelf.getNote("Note 1.1").getId(), Place.UNDER);
    shelf.createNote(n, target);
    note1 = shelf.getNote("Note 1").getPosition();
    note11 = shelf.getNote("Note 1.1").getPosition();
    note111 = shelf.getNote("Note 1.1.1").getPosition();
    note112 = shelf.getNote("Note 1.1.2").getPosition();
    note12 = shelf.getNote("Note 1.2").getPosition();
    assertTrue(note1.getLft() < note11.getLft());
    assertTrue(note11.getLft() < note111.getLft());
    assertTrue(note111.getLft() < note111.getRgt());
    assertTrue(note111.getRgt() < note112.getLft());
    assertTrue(note112.getLft() < note112.getRgt());
    assertTrue(note112.getRgt() < note11.getRgt());
    assertTrue(note11.getRgt() < note12.getLft());
    assertTrue(note12.getLft() < note12.getRgt());
    assertTrue(note12.getRgt() < note1.getRgt());
    assertEquals(4, note1.getDescendantsCount());
    assertEquals(2, note11.getDescendantsCount());
    assertEquals(0, note111.getDescendantsCount());
    assertEquals(0, note112.getDescendantsCount());
    assertEquals(0, note12.getDescendantsCount());
}
Also used : Book(com.orgzly.android.Book) NotePosition(com.orgzly.android.NotePosition) Note(com.orgzly.android.Note) NotePlace(com.orgzly.android.ui.NotePlace) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Aggregations

NotePlace (com.orgzly.android.ui.NotePlace)7 Book (com.orgzly.android.Book)4 Note (com.orgzly.android.Note)4 NotePosition (com.orgzly.android.NotePosition)4 OrgzlyTest (com.orgzly.android.OrgzlyTest)4 Test (org.junit.Test)4 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 DbNoteView (com.orgzly.android.provider.views.DbNoteView)1 HeadsListViewAdapter (com.orgzly.android.ui.HeadsListViewAdapter)1 Selection (com.orgzly.android.ui.Selection)1 GesturedListView (com.orgzly.android.ui.views.GesturedListView)1