Search in sources :

Example 1 with TodoList

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

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

the class TodoListAppWidgetProvider method createRemoteViews.

private static RemoteViews createRemoteViews(Context context, int appWidgetId, String repositoryName, String uuid) {
    Optional<TodoList> todoList = new TodoListRepositoryImpl(repositoryName).getTodoListById(uuid);
    String title = todoList.isPresent() ? todoList.get().getTitle() : context.getResources().getString(R.string.widget_empty);
    // Pending intent, used to start correct fragment from widget button
    Intent intent = new Intent(context, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(KEY_SWITCH_FRAGMENT, KEY_TODO_LIST);
    intent.putExtra(KEY_WIDGET_REPOSITORY, repositoryName);
    intent.putExtra(KEY_UUID, uuid);
    intent.putExtra(KEY_TITLE, title);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    // RemoteView setup fro WidgetListFactory
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_todo_list);
    remoteViews.setOnClickPendingIntent(R.id.widget_todo_list_bar_container, pendingIntent);
    remoteViews.setOnClickPendingIntent(R.id.widget_todo_list_bar_button, pendingIntent);
    remoteViews.setTextViewText(R.id.widget_todo_list_bar_title, title);
    return remoteViews;
}
Also used : RemoteViews(android.widget.RemoteViews) TodoListRepositoryImpl(de.djuelg.neuronizer.storage.TodoListRepositoryImpl) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TodoList(de.djuelg.neuronizer.domain.model.preview.TodoList)

Example 3 with TodoList

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

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

the class TodoListRepositoryImpl method getTodoListById.

@Override
public Optional<TodoList> getTodoListById(String uuid) {
    Realm realm = Realm.getInstance(configuration);
    Optional<TodoListDAO> todoListDAO = Optional.fromNullable(realm.where(TodoListDAO.class).equalTo("uuid", uuid).findFirst());
    Optional<TodoList> todoList = todoListDAO.transform(new TodoListDAOConverter());
    realm.close();
    return todoList;
}
Also used : TodoListDAOConverter(de.djuelg.neuronizer.storage.converter.TodoListDAOConverter) Realm(io.realm.Realm) TodoListDAO(de.djuelg.neuronizer.storage.model.TodoListDAO) TodoList(de.djuelg.neuronizer.domain.model.preview.TodoList)

Example 5 with TodoList

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

the class TodoListRepositoryImpl method getAll.

@Override
public List<TodoList> getAll() {
    Realm realm = Realm.getInstance(configuration);
    RealmResults<TodoListDAO> todoListDAOs = realm.where(TodoListDAO.class).findAll();
    List<TodoList> todoLists = new ArrayList<>(todoListDAOs.size());
    for (TodoListDAO dao : todoListDAOs) {
        todoLists.add(RealmConverter.convert(dao));
    }
    realm.close();
    return todoLists;
}
Also used : ArrayList(java.util.ArrayList) Realm(io.realm.Realm) TodoListDAO(de.djuelg.neuronizer.storage.model.TodoListDAO) 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