Search in sources :

Example 11 with TodoList

use of de.djuelg.neuronizer.domain.model.preview.TodoList in project Neuronizer by djuelg.

the class AddHeaderInteractorImpl method run.

@Override
public void run() {
    final Optional<TodoList> todoList = repository.todoList().getTodoListById(parentTodoListUuid);
    final int position = repository.todoList().getHeaderCountOfTodoList(parentTodoListUuid);
    if (!todoList.isPresent()) {
        callback.onParentNotFound();
        return;
    }
    // try to insert with new UUID on failure
    TodoListHeader header = new TodoListHeader(title, position, parentTodoListUuid);
    while (!repository.todoList().insert(header)) {
        header = new TodoListHeader(title, position, parentTodoListUuid);
    }
    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.onHeaderAdded();
        }
    });
}
Also used : TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader) TodoList(de.djuelg.neuronizer.domain.model.preview.TodoList)

Example 12 with TodoList

use of de.djuelg.neuronizer.domain.model.preview.TodoList 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

TodoList (de.djuelg.neuronizer.domain.model.preview.TodoList)12 TodoListHeader (de.djuelg.neuronizer.domain.model.todolist.TodoListHeader)5 TodoListItem (de.djuelg.neuronizer.domain.model.todolist.TodoListItem)3 TodoListRepositoryImpl (de.djuelg.neuronizer.storage.TodoListRepositoryImpl)2 TodoListDAO (de.djuelg.neuronizer.storage.model.TodoListDAO)2 Realm (io.realm.Realm)2 InputMismatchException (java.util.InputMismatchException)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 RemoteViews (android.widget.RemoteViews)1 BaseModel (de.djuelg.neuronizer.domain.model.BaseModel)1 Note (de.djuelg.neuronizer.domain.model.preview.Note)1 TodoListPreview (de.djuelg.neuronizer.domain.model.preview.TodoListPreview)1 PreviewViewModel (de.djuelg.neuronizer.presentation.ui.flexibleadapter.PreviewViewModel)1 TodoListDAOConverter (de.djuelg.neuronizer.storage.converter.TodoListDAOConverter)1 TodoListHeaderDAOConverter (de.djuelg.neuronizer.storage.converter.TodoListHeaderDAOConverter)1 TodoListHeaderDAO (de.djuelg.neuronizer.storage.model.TodoListHeaderDAO)1 ArrayList (java.util.ArrayList)1