Search in sources :

Example 1 with HeadsListViewAdapter

use of com.orgzly.android.ui.HeadsListViewAdapter 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 2 with HeadsListViewAdapter

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

the class SearchFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    if (BuildConfig.LOG_DEBUG)
        LogUtils.d(TAG, view, savedInstanceState);
    super.onViewCreated(view, savedInstanceState);
    /* On long click */
    getListView().setOnItemLongClickListener((parent, view1, position, id) -> {
        mListener.onNoteLongClick(SearchFragment.this, view1, position, id, id);
        return true;
    });
    getListView().setOnItemMenuButtonClickListener((itemView, buttonId, noteId) -> onButtonClick(mListener, itemView, buttonId, noteId));
    /* Create a selection. */
    mSelection = new Selection();
    mListAdapter = new HeadsListViewAdapter(getActivity(), mSelection, getListView().getItemMenus(), false);
    setListAdapter(mListAdapter);
    /*
         * Restore selected items, now that adapter is set.
         * Saved with {@link Selection#saveSelectedIds(android.os.Bundle, String)}.
         */
    mSelection.restoreIds(savedInstanceState);
}
Also used : Selection(com.orgzly.android.ui.Selection) HeadsListViewAdapter(com.orgzly.android.ui.HeadsListViewAdapter)

Aggregations

HeadsListViewAdapter (com.orgzly.android.ui.HeadsListViewAdapter)2 Selection (com.orgzly.android.ui.Selection)2 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 NotePlace (com.orgzly.android.ui.NotePlace)1 GesturedListView (com.orgzly.android.ui.views.GesturedListView)1