Search in sources :

Example 6 with TodoListHeader

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

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

use of de.djuelg.neuronizer.domain.model.todolist.TodoListHeader 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)

Example 9 with TodoListHeader

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

the class TodoListRepositoryImpl method getHeadersOfTodoListId.

@Override
public List<TodoListHeader> getHeadersOfTodoListId(String uuid) {
    Realm realm = Realm.getInstance(configuration);
    RealmResults<TodoListHeaderDAO> headerDAOs = realm.where(TodoListHeaderDAO.class).equalTo("parentTodoListUuid", uuid).findAll();
    List<TodoListHeader> headers = new ArrayList<>(headerDAOs.size());
    for (TodoListHeaderDAO dao : headerDAOs) {
        headers.add(RealmConverter.convert(dao));
    }
    realm.close();
    return headers;
}
Also used : TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader) ArrayList(java.util.ArrayList) TodoListHeaderDAO(de.djuelg.neuronizer.storage.model.TodoListHeaderDAO) Realm(io.realm.Realm)

Example 10 with TodoListHeader

use of de.djuelg.neuronizer.domain.model.todolist.TodoListHeader 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)

Aggregations

TodoListHeader (de.djuelg.neuronizer.domain.model.todolist.TodoListHeader)18 MediumTest (android.support.test.filters.MediumTest)6 Test (org.junit.Test)6 TodoList (de.djuelg.neuronizer.domain.model.preview.TodoList)5 TodoListHeaderDAO (de.djuelg.neuronizer.storage.model.TodoListHeaderDAO)5 TodoListItem (de.djuelg.neuronizer.domain.model.todolist.TodoListItem)4 ArrayList (java.util.ArrayList)3 TodoListHeaderViewModel (de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListHeaderViewModel)2 TodoListHeaderDAOConverter (de.djuelg.neuronizer.storage.converter.TodoListHeaderDAOConverter)2 Realm (io.realm.Realm)2 InputMismatchException (java.util.InputMismatchException)2 ArrayAdapter (android.widget.ArrayAdapter)1 TodoListPreview (de.djuelg.neuronizer.domain.model.preview.TodoListPreview)1 TodoListSection (de.djuelg.neuronizer.domain.model.todolist.TodoListSection)1 TodoListItemDAO (de.djuelg.neuronizer.storage.model.TodoListItemDAO)1 IHeader (eu.davidea.flexibleadapter.items.IHeader)1