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);
}
});
}
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();
}
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);
}
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;
}
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);
}
Aggregations