Search in sources :

Example 1 with TodoListHeaderViewModel

use of de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListHeaderViewModel in project Neuronizer by djuelg.

the class DisplayTodoListPresenterImpl method syncTodoList.

@Override
public void syncTodoList(FlexibleAdapter<AbstractFlexibleItem> adapter) {
    List<IHeader> reversedHeaders = Lists.reverse(Optional.fromNullable(Lists.newArrayList(adapter.getHeaderItems())).or(new ArrayList<IHeader>(0)));
    for (IHeader iHeader : reversedHeaders) {
        TodoListHeaderViewModel vm = (TodoListHeaderViewModel) iHeader;
        TodoListHeader header = vm.getHeader();
        syncHeader(header, reversedHeaders.indexOf(vm), vm.isExpanded());
        syncSubItems(Lists.newArrayList(adapter.getSectionItems(iHeader)));
    }
}
Also used : IHeader(eu.davidea.flexibleadapter.items.IHeader) TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader) ArrayList(java.util.ArrayList) TodoListHeaderViewModel(de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListHeaderViewModel)

Example 2 with TodoListHeaderViewModel

use of de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListHeaderViewModel in project Neuronizer by djuelg.

the class DisplayTodoListPresenterImpl method onTodoListRetrieved.

@Override
public void onTodoListRetrieved(List<TodoListSection> sections) {
    Collections.sort(sections, new PositionComparator());
    List<AbstractFlexibleItem> headerVMs = new ArrayList<>(sections.size());
    for (TodoListSection section : sections) {
        TodoListHeaderViewModel headerVM = new TodoListHeaderViewModel(section.getHeader());
        headerVM.setSubItems(createSubItemList(headerVM, Lists.newArrayList(section.getItems())));
        headerVMs.add(headerVM);
    }
    mView.onTodoListLoaded(headerVMs);
}
Also used : TodoListSection(de.djuelg.neuronizer.domain.model.todolist.TodoListSection) AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) ArrayList(java.util.ArrayList) PositionComparator(de.djuelg.neuronizer.domain.comparator.PositionComparator) TodoListHeaderViewModel(de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListHeaderViewModel)

Example 3 with TodoListHeaderViewModel

use of de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListHeaderViewModel in project Neuronizer by djuelg.

the class TodoListFragment method editSelectedHeader.

private void editSelectedHeader() {
    int position = mAdapter.getSelectedPositions().get(0);
    TodoListHeaderViewModel headerVH = (TodoListHeaderViewModel) mAdapter.getItem(position);
    if (headerVH != null) {
        TodoListHeader header = headerVH.getHeader();
        showEditHeaderDialog(this, header.getUuid(), header.getTitle(), header.getPosition(), header.isExpanded());
    }
    mActionModeHelper.destroyActionModeIfCan();
}
Also used : TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader) TodoListHeaderViewModel(de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListHeaderViewModel)

Example 4 with TodoListHeaderViewModel

use of de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListHeaderViewModel in project Neuronizer by djuelg.

the class TodoListFragment method onActionCanceled.

@Override
public void onActionCanceled(@UndoHelper.Action int action, List<Integer> positions) {
    if (mAdapter == null || action != UndoHelper.Action.REMOVE)
        return;
    List<AbstractFlexibleItem> restoredItems = mAdapter.getDeletedItems();
    mAdapter.restoreDeletedItems();
    if (!restoredItems.isEmpty()) {
        mAdapter.clearSelection();
        AbstractFlexibleItem item = Iterables.getLast(restoredItems);
        if (item instanceof TodoListHeaderViewModel && mActionModeHelper != null)
            mActionModeHelper.onLongClick((AppCompatActivity) getActivity(), mAdapter.getGlobalPositionOf(item));
    }
}
Also used : AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) AppCompatActivity(android.support.v7.app.AppCompatActivity) TodoListHeaderViewModel(de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListHeaderViewModel)

Example 5 with TodoListHeaderViewModel

use of de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListHeaderViewModel in project Neuronizer by djuelg.

the class TodoListFragment method onDestroyActionMode.

@Override
public void onDestroyActionMode(ActionMode mode) {
    changeAppbarColor(getActivity(), R.color.colorPrimary);
    for (IHeader header : mAdapter.getHeaderItems()) {
        TodoListHeaderViewModel vm = (TodoListHeaderViewModel) header;
        boolean shouldExpand = vm.getHeader().isExpanded();
        if (shouldExpand && !omitActionModeExpansion)
            mAdapter.expand(vm);
    }
}
Also used : IHeader(eu.davidea.flexibleadapter.items.IHeader) TodoListHeaderViewModel(de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListHeaderViewModel)

Aggregations

TodoListHeaderViewModel (de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListHeaderViewModel)8 AbstractFlexibleItem (eu.davidea.flexibleadapter.items.AbstractFlexibleItem)5 TodoListItemViewModel (de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListItemViewModel)3 TodoListHeader (de.djuelg.neuronizer.domain.model.todolist.TodoListHeader)2 IHeader (eu.davidea.flexibleadapter.items.IHeader)2 ArrayList (java.util.ArrayList)2 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 PositionComparator (de.djuelg.neuronizer.domain.comparator.PositionComparator)1 TodoListSection (de.djuelg.neuronizer.domain.model.todolist.TodoListSection)1