use of com.orgzly.android.ui.Selection 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. */
}
use of com.orgzly.android.ui.Selection in project orgzly-android by orgzly.
the class AgendaFragment 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) -> {
if (mListAdapter != null && mListAdapter.getItemViewType(position) != AgendaListViewAdapter.DIVIDER_VIEW_TYPE) {
mListener.onNoteLongClick(AgendaFragment.this, view1, position, id, originalNoteIDs.get(id).getNoteId());
}
return true;
});
getListView().setOnItemMenuButtonClickListener((itemView, buttonId, noteId) -> onButtonClick(mListener, itemView, buttonId, originalNoteIDs.get(noteId).getNoteId()));
/* Create a selection. */
mSelection = new Selection();
mListAdapter = new AgendaListViewAdapter(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);
}
use of com.orgzly.android.ui.Selection 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);
}
Aggregations