Search in sources :

Example 1 with TodoListItemViewModel

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;
}
Also used : TodoListItemViewModel(de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListItemViewModel) ArrayList(java.util.ArrayList) PositionComparator(de.djuelg.neuronizer.domain.comparator.PositionComparator) TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem)

Example 2 with TodoListItemViewModel

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();
    }
}
Also used : EditItemInteractor(de.djuelg.neuronizer.domain.interactors.todolist.EditItemInteractor) TodoListItemViewModel(de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListItemViewModel) ArrayList(java.util.ArrayList) EditItemInteractorImpl(de.djuelg.neuronizer.domain.interactors.todolist.impl.EditItemInteractorImpl) ISectionable(eu.davidea.flexibleadapter.items.ISectionable) TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem)

Example 3 with TodoListItemViewModel

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;
}
Also used : TodoListItemViewModel(de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListItemViewModel) AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem)

Example 4 with TodoListItemViewModel

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;
}
Also used : TodoListItemViewModel(de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListItemViewModel) AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) TodoListHeaderViewModel(de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListHeaderViewModel)

Example 5 with TodoListItemViewModel

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);
    }
}
Also used : TodoListItemViewModel(de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListItemViewModel) AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) TodoListHeaderViewModel(de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListHeaderViewModel)

Aggregations

TodoListItemViewModel (de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListItemViewModel)6 AbstractFlexibleItem (eu.davidea.flexibleadapter.items.AbstractFlexibleItem)4 TodoListItem (de.djuelg.neuronizer.domain.model.todolist.TodoListItem)3 TodoListHeaderViewModel (de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListHeaderViewModel)3 ArrayList (java.util.ArrayList)2 PositionComparator (de.djuelg.neuronizer.domain.comparator.PositionComparator)1 EditItemInteractor (de.djuelg.neuronizer.domain.interactors.todolist.EditItemInteractor)1 EditItemInteractorImpl (de.djuelg.neuronizer.domain.interactors.todolist.impl.EditItemInteractorImpl)1 ISectionable (eu.davidea.flexibleadapter.items.ISectionable)1