Search in sources :

Example 16 with TodoListItem

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

the class TodoListRepositoryImplTest method testTodoListItemInsertTwice.

@Test
public void testTodoListItemInsertTwice() {
    clearRealm();
    TodoListItem item = createItem();
    repository.insert(item);
    boolean success = repository.insert(item);
    assertFalse(success);
    TodoListItemDAO dao = realm.where(TodoListItemDAO.class).equalTo("uuid", item.getUuid()).findFirst();
    assertNotNull(dao);
    fillRealm();
}
Also used : TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem) TodoListItemDAO(de.djuelg.neuronizer.storage.model.TodoListItemDAO) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 17 with TodoListItem

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

the class AddItemInteractorImpl method run.

@Override
public void run() {
    final Optional<TodoList> todoList = repository.todoList().getTodoListById(parentTodoListUuid);
    final Optional<TodoListHeader> header = repository.todoList().getHeaderById(parentHeaderUuid);
    final int position = repository.todoList().getSubItemCountOfHeader(parentHeaderUuid);
    if (!todoList.isPresent() || !header.isPresent()) {
        callback.onParentNotFound();
        return;
    }
    // try to insert with new UUID on failure
    TodoListItem item = new TodoListItem(title, position, important, details, parentTodoListUuid, parentHeaderUuid);
    while (!repository.todoList().insert(item)) {
        item = new TodoListItem(title, position, important, details, parentTodoListUuid, parentHeaderUuid);
    }
    repository.todoList().update(todoList.get().updateLastChange());
    // notify on the main thread that we have inserted this item
    mMainThread.post(new Runnable() {

        @Override
        public void run() {
            callback.onItemAdded();
        }
    });
}
Also used : TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader) TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem) 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