Search in sources :

Example 11 with TodoListItem

use of de.djuelg.neuronizer.domain.model.todolist.TodoListItem in project Neuronizer by djuelg.

the class PreviewRepositoryImpl method getItemPreviewOfHeader.

private List<TodoListItem> getItemPreviewOfHeader(Realm realm, TodoListHeader header, ItemsPerPreview itemsPerPreview) {
    if (header == null || itemsPerPreview.areZero())
        return new ArrayList<>(0);
    RealmResults<TodoListItemDAO> itemDAOs = realm.where(TodoListItemDAO.class).equalTo("parentTodoListUuid", header.getParentTodoListUuid()).equalTo("parentHeaderUuid", header.getUuid()).findAllSorted("position", Sort.DESCENDING);
    int size = Math.min(itemDAOs.size(), itemsPerPreview.getCount());
    List<TodoListItem> items = new ArrayList<>(size);
    if (size > 0) {
        for (TodoListItemDAO itemDAO : itemDAOs.subList(0, size)) {
            items.add(RealmConverter.convert(itemDAO));
        }
    }
    return items;
}
Also used : ArrayList(java.util.ArrayList) TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem) TodoListItemDAO(de.djuelg.neuronizer.storage.model.TodoListItemDAO)

Example 12 with TodoListItem

use of de.djuelg.neuronizer.domain.model.todolist.TodoListItem in project Neuronizer by djuelg.

the class TodoListRepositoryImpl method constructSection.

private TodoListSection constructSection(Realm realm, TodoListHeaderDAO headerDAO) {
    RealmResults<TodoListItemDAO> itemDAOs = realm.where(TodoListItemDAO.class).equalTo("parentTodoListUuid", headerDAO.getParentTodoListUuid()).equalTo("parentHeaderUuid", headerDAO.getUuid()).findAll();
    List<TodoListItem> items = new ArrayList<>(itemDAOs.size());
    TodoListHeader header = RealmConverter.convert(headerDAO);
    for (TodoListItemDAO dao : itemDAOs) {
        items.add(RealmConverter.convert(dao));
    }
    return new TodoListSection(header, items);
}
Also used : TodoListSection(de.djuelg.neuronizer.domain.model.todolist.TodoListSection) TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader) ArrayList(java.util.ArrayList) TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem) TodoListItemDAO(de.djuelg.neuronizer.storage.model.TodoListItemDAO)

Example 13 with TodoListItem

use of de.djuelg.neuronizer.domain.model.todolist.TodoListItem in project Neuronizer by djuelg.

the class TodoListRepositoryImpl method getItemById.

@Override
public Optional<TodoListItem> getItemById(String uuid) {
    Realm realm = Realm.getInstance(configuration);
    Optional<TodoListItemDAO> itemDAO = Optional.fromNullable(realm.where(TodoListItemDAO.class).equalTo("uuid", uuid).findFirst());
    Optional<TodoListItem> item = itemDAO.transform(new TodoListItemDAOConverter());
    realm.close();
    return item;
}
Also used : TodoListItemDAOConverter(de.djuelg.neuronizer.storage.converter.TodoListItemDAOConverter) Realm(io.realm.Realm) TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem) TodoListItemDAO(de.djuelg.neuronizer.storage.model.TodoListItemDAO)

Example 14 with TodoListItem

use of de.djuelg.neuronizer.domain.model.todolist.TodoListItem 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 15 with TodoListItem

use of de.djuelg.neuronizer.domain.model.todolist.TodoListItem in project Neuronizer by djuelg.

the class TodoListRepositoryMock method getSectionsOfTodoListId.

@Override
public // - are presenters tested? if yes then test DisplayTodoListPresenter
List<TodoListSection> getSectionsOfTodoListId(String uuid) {
    List<TodoListSection> sections = new ArrayList<>(1);
    List<TodoListItem> items = new ArrayList<TodoListItem>(1);
    items.add(alwaysSameItem);
    sections.add(new TodoListSection(alwaysSameHeader, items));
    return sections;
}
Also used : TodoListSection(de.djuelg.neuronizer.domain.model.todolist.TodoListSection) ArrayList(java.util.ArrayList) TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem)

Aggregations

TodoListItem (de.djuelg.neuronizer.domain.model.todolist.TodoListItem)17 MediumTest (android.support.test.filters.MediumTest)6 Test (org.junit.Test)6 TodoListItemDAO (de.djuelg.neuronizer.storage.model.TodoListItemDAO)5 ArrayList (java.util.ArrayList)5 TodoListHeader (de.djuelg.neuronizer.domain.model.todolist.TodoListHeader)4 TodoList (de.djuelg.neuronizer.domain.model.preview.TodoList)3 TodoListSection (de.djuelg.neuronizer.domain.model.todolist.TodoListSection)3 TodoListItemViewModel (de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListItemViewModel)3 PositionComparator (de.djuelg.neuronizer.domain.comparator.PositionComparator)2 EditItemInteractor (de.djuelg.neuronizer.domain.interactors.todolist.EditItemInteractor)1 EditItemInteractorImpl (de.djuelg.neuronizer.domain.interactors.todolist.impl.EditItemInteractorImpl)1 TodoListPreview (de.djuelg.neuronizer.domain.model.preview.TodoListPreview)1 TodoListHeaderDAOConverter (de.djuelg.neuronizer.storage.converter.TodoListHeaderDAOConverter)1 TodoListItemDAOConverter (de.djuelg.neuronizer.storage.converter.TodoListItemDAOConverter)1 TodoListHeaderDAO (de.djuelg.neuronizer.storage.model.TodoListHeaderDAO)1 AbstractFlexibleItem (eu.davidea.flexibleadapter.items.AbstractFlexibleItem)1 ISectionable (eu.davidea.flexibleadapter.items.ISectionable)1 Realm (io.realm.Realm)1 InputMismatchException (java.util.InputMismatchException)1