Search in sources :

Example 11 with TodoListHeader

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

the class ItemFragment method addOrEditItemWithCurrentViewInput.

private void addOrEditItemWithCurrentViewInput(boolean addAnother) {
    String title = titleEditText.getText().toString();
    if (title.isEmpty() || mPresenter == null) {
        Toast.makeText(getActivity(), R.string.title_mandatory, Toast.LENGTH_SHORT).show();
        return;
    }
    TodoListHeader header = ((TodoListHeader) headerSpinner.getSelectedItem());
    boolean important = importantSwitch.isChecked();
    String details = (richEditor.getHtml() != null) ? richEditor.getHtml() : "";
    if (isEditMode()) {
        mPresenter.editItem(itemUuid, title, item.getPosition(), important, details, item.isDone(), todoListUuid, header.getUuid());
    } else {
        mPresenter.expandHeaderOfItem(header.getUuid(), header.getTitle(), header.getPosition());
        if (addAnother) {
            mPresenter.addItemAndAnother(title, important, details, todoListUuid, header.getUuid());
        } else {
            mPresenter.addItem(title, important, details, todoListUuid, header.getUuid());
        }
    }
}
Also used : TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader)

Example 12 with TodoListHeader

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

the class ItemFragment method onHeadersLoaded.

@Override
public void onHeadersLoaded(List<TodoListHeader> headers) {
    ArrayAdapter<TodoListHeader> spinnerAdapter = new ArrayAdapter<>(getContext(), R.layout.spinner_item, headers);
    headerSpinner.setAdapter(spinnerAdapter);
    for (TodoListHeader header : headers) {
        if (isEditMode() && header.getUuid().equals(item.getParentHeaderUuid()))
            headerSpinner.setSelection(headers.indexOf(header));
    }
}
Also used : TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader) ArrayAdapter(android.widget.ArrayAdapter)

Example 13 with TodoListHeader

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

the class TodoListRepositoryImpl method getHeaderById.

@Override
public Optional<TodoListHeader> getHeaderById(String uuid) {
    Realm realm = Realm.getInstance(configuration);
    Optional<TodoListHeaderDAO> headerDAO = Optional.fromNullable(realm.where(TodoListHeaderDAO.class).equalTo("uuid", uuid).findFirst());
    Optional<TodoListHeader> header = headerDAO.transform(new TodoListHeaderDAOConverter());
    realm.close();
    return header;
}
Also used : TodoListHeaderDAOConverter(de.djuelg.neuronizer.storage.converter.TodoListHeaderDAOConverter) TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader) TodoListHeaderDAO(de.djuelg.neuronizer.storage.model.TodoListHeaderDAO) Realm(io.realm.Realm)

Example 14 with TodoListHeader

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

the class EditHeaderInteractorImpl method run.

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

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

Example 15 with TodoListHeader

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

the class TodoListRepositoryImplTest method testTodoListHeaderInsert.

@Test
public void testTodoListHeaderInsert() {
    TodoListHeader header = createHeader();
    boolean success = repository.insert(header);
    assertTrue(success);
    TodoListHeaderDAO dao = realm.where(TodoListHeaderDAO.class).equalTo("uuid", header.getUuid()).findFirst();
    assertNotNull(dao);
}
Also used : TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader) TodoListHeaderDAO(de.djuelg.neuronizer.storage.model.TodoListHeaderDAO) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

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