private void setCompletedForItemAndSubtasks(final Task item, final boolean completedState) {
    final long itemId = item.getId();

    final Task model = new Task();
    final long completionDate = completedState ? DateUtilities.now() : 0;

    if (!completedState) {
      ArrayList<Long> chained = chainedCompletions.get(itemId);
      if (chained != null) {
        for (Long taskId : chained) {
          model.setId(taskId);
          model.setValue(Task.COMPLETION_DATE, completionDate);
          taskService.save(model);
          model.clear();

          taskAdapter.getCompletedItems().put(taskId, false);
        }
        taskAdapter.notifyDataSetInvalidated();
      }
      return;
    }

    final ArrayList<Long> chained = new ArrayList<>();
    final int parentIndent = item.getValue(updater.indentProperty());
    updater.applyToChildren(
        list,
        itemId,
        new OrderedListNodeVisitor() {
          @Override
          public void visitNode(Node node) {
            Task childTask = taskService.fetchById(node.taskId, Task.RECURRENCE);
            if (!TextUtils.isEmpty(childTask.getValue(Task.RECURRENCE))) {
              Metadata metadata = updater.getTaskMetadata(node.taskId);
              metadata.setValue(updater.indentProperty(), parentIndent);
              metadataService.save(metadata);
            }

            model.setId(node.taskId);
            model.setValue(Task.COMPLETION_DATE, completionDate);
            taskService.save(model);
            model.clear();

            taskAdapter.getCompletedItems().put(node.taskId, true);
            chained.add(node.taskId);
          }
        });

    if (chained.size() > 0) {
      chainedCompletions.put(itemId, chained);
      taskAdapter.notifyDataSetInvalidated();
    }
  }
Beispiel #2
0
  public void delete(Task item) {
    if (!item.isSaved()) {
      return;
    }

    if (item.containsValue(Task.TITLE) && item.getTitle().length() == 0) {
      taskDao.delete(item.getId());
      item.setId(Task.NO_ID);
    } else {
      long id = item.getId();
      item.clear();
      item.setId(id);
      gcalHelper.deleteTaskEvent(item);
      item.setDeletionDate(DateUtilities.now());
      taskService.save(item);
    }
  }