Search in sources :

Example 6 with TodoListItem

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

the class TodoListRepositoryImplTest method testUpdateItem.

@Test
public void testUpdateItem() throws InterruptedException {
    TodoListItem item = createItem();
    repository.insert(item);
    Thread.sleep(200);
    repository.update(item.update("New Title", 0, false, "", false, "uuid1"));
    Optional<TodoListItem> fromDb = repository.getItemById(item.getUuid());
    assertEquals(item.getCreatedAt(), fromDb.get().getCreatedAt());
    assertNotEquals(item.getChangedAt(), fromDb.get().getChangedAt());
    assertNotEquals(item.getTitle(), fromDb.get().getTitle());
}
Also used : TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 7 with TodoListItem

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

the class TodoListRepositoryImplTest method testItemDelete.

@Test
public void testItemDelete() {
    TodoListItem item = createItem();
    repository.insert(item);
    repository.delete(item);
    Optional<TodoListItem> fromDb = repository.getItemById(item.getUuid());
    assertFalse(fromDb.isPresent());
}
Also used : TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 8 with TodoListItem

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

the class EditItemInteractorImpl method run.

@Override
public void run() {
    final Optional<TodoListHeader> header = repository.todoList().getHeaderById(parentHeaderUuid);
    final Optional<TodoListItem> outDatedItem = repository.todoList().getItemById(uuid);
    if (!header.isPresent() || !outDatedItem.isPresent()) {
        throw new InputMismatchException("Header, or Item were not existing!");
    }
    final TodoListItem updatedItem = outDatedItem.get().update(title, position, important, details, done, parentHeaderUuid);
    repository.todoList().update(updatedItem);
    final Optional<TodoList> todoList = repository.todoList().getTodoListById(updatedItem.getParentTodoListUuid());
    final TodoListItem itemFromUI = new TodoListItem(uuid, title, outDatedItem.get().getCreatedAt(), outDatedItem.get().getChangedAt(), position, important, details, done, outDatedItem.get().getParentTodoListUuid(), parentHeaderUuid);
    if (todoList.isPresent() && !outDatedItem.get().equals(itemFromUI))
        repository.todoList().update(todoList.get().updateLastChange());
    mMainThread.post(new Runnable() {

        @Override
        public void run() {
            callback.onItemUpdated(updatedItem);
        }
    });
}
Also used : TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader) InputMismatchException(java.util.InputMismatchException) TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem) TodoList(de.djuelg.neuronizer.domain.model.preview.TodoList)

Example 9 with TodoListItem

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

the class WidgetListFactory method onDataSetChanged.

@Override
public void onDataSetChanged() {
    itemList.clear();
    List<TodoListSection> sections = Lists.newArrayList(repository.getSectionsOfTodoListId(uuid));
    Collections.sort(sections, new PositionComparator());
    for (TodoListSection section : sections) {
        itemList.add(section.getHeader());
        List<TodoListItem> items = Lists.newArrayList(section.getItems());
        Collections.sort(items, new PositionComparator());
        itemList.addAll(items);
    }
}
Also used : TodoListSection(de.djuelg.neuronizer.domain.model.todolist.TodoListSection) PositionComparator(de.djuelg.neuronizer.domain.comparator.PositionComparator) TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem)

Example 10 with TodoListItem

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

the class PreviewRepositoryImpl method constructPreview.

private TodoListPreview constructPreview(Realm realm, TodoListDAO todoListDAO, ItemsPerPreview itemsPerPreview) {
    TodoList todoList = RealmConverter.convert(todoListDAO);
    Optional<TodoListHeaderDAO> headerDAO = Optional.fromNullable(realm.where(TodoListHeaderDAO.class).equalTo("parentTodoListUuid", todoListDAO.getUuid()).findAllSorted("position", Sort.DESCENDING).where().findFirst());
    TodoListHeader header = headerDAO.transform(new TodoListHeaderDAOConverter()).orNull();
    List<TodoListItem> items = getItemPreviewOfHeader(realm, header, itemsPerPreview);
    return new TodoListPreview(todoList, header, items);
}
Also used : TodoListHeaderDAOConverter(de.djuelg.neuronizer.storage.converter.TodoListHeaderDAOConverter) TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader) TodoListHeaderDAO(de.djuelg.neuronizer.storage.model.TodoListHeaderDAO) TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem) TodoListPreview(de.djuelg.neuronizer.domain.model.preview.TodoListPreview) TodoList(de.djuelg.neuronizer.domain.model.preview.TodoList)

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