use of de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListItemViewModel in project Neuronizer by djuelg.
the class DisplayTodoListPresenterImpl method createSubItemList.
private List<TodoListItemViewModel> createSubItemList(TodoListHeaderViewModel headerVM, List<TodoListItem> items) {
Collections.sort(items, new PositionComparator());
List<TodoListItemViewModel> itemVMs = new ArrayList<>();
for (TodoListItem item : items) {
itemVMs.add(new TodoListItemViewModel(headerVM, item));
}
return itemVMs;
}
use of de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListItemViewModel in project Neuronizer by djuelg.
the class DisplayTodoListPresenterImpl method syncSubItems.
private void syncSubItems(List<ISectionable> subItems) {
List<ISectionable> reversedItems = Lists.reverse(Optional.fromNullable(subItems).or(new ArrayList<ISectionable>(0)));
for (ISectionable vm : reversedItems) {
TodoListItem item = ((TodoListItemViewModel) vm).getItem();
EditItemInteractor interactor = new EditItemInteractorImpl(mExecutor, mMainThread, this, repository, item.getUuid(), item.getTitle(), reversedItems.indexOf(vm), item.isImportant(), item.getDetails(), item.isDone(), ((TodoListItemViewModel) vm).getHeader().getHeader().getUuid());
interactor.execute();
}
}
use of de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListItemViewModel in project Neuronizer by djuelg.
the class TodoListFragment method onItemClick.
@Override
public boolean onItemClick(View view, int position) {
AbstractFlexibleItem vm = mAdapter.getItem(position);
if (vm instanceof TodoListItemViewModel) {
TodoListItem item = ((TodoListItemViewModel) vm).getItem().toggleDoneState();
// update view now, update database later via sync
mAdapter.updateItem(position, new TodoListItemViewModel(((TodoListItemViewModel) vm).getHeader(), item), Payload.CHANGE);
}
// return true if you want to activate action mode
return false;
}
use of de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListItemViewModel in project Neuronizer by djuelg.
the class TodoListFragment method shouldMoveItem.
@Override
public boolean shouldMoveItem(int fromPosition, int toPosition) {
AbstractFlexibleItem itemFromPosition = mAdapter.getItem(fromPosition);
AbstractFlexibleItem itemToPosition = mAdapter.getItem(toPosition);
// Section Item can't be at pos 0
if (itemFromPosition instanceof TodoListItemViewModel && toPosition == 0) {
return false;
}
// Case: User holds SectionItem and drags over HeaderItem
if (itemFromPosition instanceof TodoListItemViewModel && itemToPosition instanceof TodoListHeaderViewModel) {
// Section Item can't be set under collapsed Header
if (!((TodoListHeaderViewModel) itemToPosition).isExpanded()) {
return false;
}
}
// Case: User holds SectionItem and drags over SectionItem
if (itemFromPosition instanceof TodoListItemViewModel && itemToPosition instanceof TodoListItemViewModel) {
// If Header is currently unset, don't allow drop
TodoListHeaderViewModel newHeader = (TodoListHeaderViewModel) mAdapter.getHeaderOf(itemToPosition);
if (newHeader == null) {
return false;
}
}
return true;
}
use of de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListItemViewModel in project Neuronizer by djuelg.
the class TodoListFragment method onItemMove.
@Override
public void onItemMove(int fromPosition, int toPosition) {
AbstractFlexibleItem draggedItem = mAdapter.getItem(toPosition);
AbstractFlexibleItem movedItem = mAdapter.getItem(fromPosition);
if (draggedItem instanceof TodoListItemViewModel && movedItem instanceof TodoListHeaderViewModel) {
TodoListHeaderViewModel newHeader = (TodoListHeaderViewModel) mAdapter.getHeaderOf(draggedItem);
TodoListHeaderViewModel oldHeader = mAdapter.evaluateOldHeader(fromPosition, toPosition);
int location = mAdapter.evaluateDistanceToHeader(draggedItem);
oldHeader.removeSubItem((TodoListItemViewModel) draggedItem);
newHeader.addSubItem(location, (TodoListItemViewModel) draggedItem);
newHeader.setExpanded(true);
mAdapter.updateItem(newHeader);
}
}
Aggregations