コード例 #1
0
ファイル: TaskListFragment.java プロジェクト: kflux/tasks
  @Override
  public boolean onOptionsItemSelected(final MenuItem item) {
    long itemId;

    if (!isCurrentTaskListFragment()) {
      return false;
    }

    switch (item.getItemId()) {
        // --- context menu items

      case CONTEXT_MENU_EDIT_TASK_ID:
        itemId = item.getGroupId();
        mListener.onTaskListItemClicked(itemId);
        return true;
      case CONTEXT_MENU_COPY_TASK_ID:
        itemId = item.getGroupId();
        duplicateTask(itemId);
        return true;
      case CONTEXT_MENU_DELETE_TASK_ID:
        {
          itemId = item.getGroupId();
          Task task = taskService.fetchById(itemId, Task.ID, Task.UUID);
          if (task != null) {
            deleteTask(task);
          }
          return true;
        }
      case CONTEXT_MENU_UNDELETE_TASK_ID:
        {
          itemId = item.getGroupId();
          Task task = new Task();
          task.setId(itemId);
          task.setDeletionDate(0L);
          taskService.save(task);
          loadTaskListContent();
          return true;
        }
      case CONTEXT_MENU_PURGE_TASK_ID:
        {
          itemId = item.getGroupId();
          Task task = new Task();
          task.setId(itemId);
          TimerPlugin.updateTimer(notificationManager, taskService, getActivity(), task, false);
          taskDeleter.purge(itemId);
          loadTaskListContent();
          return true;
        }
      default:
        return super.onOptionsItemSelected(item);
    }
  }
コード例 #2
0
ファイル: TaskDeleter.java プロジェクト: kflux/tasks
  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);
    }
  }
コード例 #3
0
  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();
    }
  }
コード例 #4
0
 private void titleMatchWithActFm(Task task) {
   String title = task.getValue(Task.TITLE);
   TodorooCursor<Task> match =
       taskService.query(
           Query.select(Task.ID)
               .join(
                   Join.left(
                       Metadata.TABLE,
                       Criterion.and(
                           Metadata.KEY.eq(GtasksMetadata.METADATA_KEY),
                           Metadata.TASK.eq(Task.ID))))
               .where(Criterion.and(Task.TITLE.eq(title), GtasksMetadata.ID.isNull())));
   try {
     if (match.getCount() > 0) {
       match.moveToFirst();
       task.setId(match.get(Task.ID));
     }
   } finally {
     match.close();
   }
 }
コード例 #5
0
ファイル: TaskDao.java プロジェクト: atexit/astrid
  /**
   * Saves the given task to the database.getDatabase(). Task must already exist. Returns true on
   * success.
   *
   * @param task
   * @return true if save occurred, false otherwise (i.e. nothing changed)
   */
  public boolean save(Task task) {
    boolean saveSuccessful = false;
    if (task.getId() == Task.NO_ID) {
      try {
        saveSuccessful = createNew(task);
      } catch (SQLiteConstraintException e) {
        if (e.getMessage().contains(Task.REMOTE_ID_PROPERTY_NAME)) {
          // Tried to create task with remote id that already exists
          saveSuccessful = false;
          TodorooCursor<Task> cursor =
              query(Query.select(Task.ID).where(Task.REMOTE_ID.eq(task.getValue(Task.REMOTE_ID))));
          if (cursor.getCount() > 0) {
            cursor.moveToFirst();
            task.setId(cursor.get(Task.ID));
            saveSuccessful = saveExisting(task);
          }
        }
      }
    } else {
      saveSuccessful = saveExisting(task);
    }

    return saveSuccessful;
  }
コード例 #6
0
ファイル: TaskListFragment.java プロジェクト: junekai/astrid
  @Override
  public boolean onOptionsItemSelected(final MenuItem item) {
    Intent intent;
    long itemId;

    if (!isCurrentTaskListFragment()) return false;

    // handle my own menus
    if (handleOptionsMenuItemSelected(item.getItemId(), item.getIntent())) return true;

    switch (item.getItemId()) {
        // --- context menu items

      case CONTEXT_MENU_BROADCAST_INTENT_ID:
        {
          intent = item.getIntent();
          getActivity().sendBroadcast(intent);
          return true;
        }
      case CONTEXT_MENU_EDIT_TASK_ID:
        {
          itemId = item.getGroupId();
          mListener.onTaskListItemClicked(itemId);
          return true;
        }
      case CONTEXT_MENU_COPY_TASK_ID:
        {
          itemId = item.getGroupId();
          duplicateTask(itemId);
          return true;
        }
      case CONTEXT_MENU_DELETE_TASK_ID:
        {
          itemId = item.getGroupId();
          Task task = new Task();
          task.setId(itemId);
          deleteTask(task);
          return true;
        }
      case CONTEXT_MENU_UNDELETE_TASK_ID:
        {
          itemId = item.getGroupId();
          Task task = new Task();
          task.setId(itemId);
          task.setValue(Task.DELETION_DATE, 0L);
          taskService.save(task);
          loadTaskListContent(true);
          return true;
        }
      case CONTEXT_MENU_PURGE_TASK_ID:
        {
          itemId = item.getGroupId();
          Task task = new Task();
          task.setId(itemId);
          TimerPlugin.updateTimer(getActivity(), task, false);
          taskService.purge(itemId);
          loadTaskListContent(true);
          return true;
        }
      default:
        {
          if (item.getItemId() < CONTEXT_MENU_PLUGIN_ID_FIRST) return false;
          if (item.getItemId() - CONTEXT_MENU_PLUGIN_ID_FIRST >= contextItemExposers.length)
            return false;

          AdapterContextMenuInfo adapterInfo = (AdapterContextMenuInfo) item.getMenuInfo();
          Task task = ((ViewHolder) adapterInfo.targetView.getTag()).task;
          contextItemExposers[item.getItemId() - CONTEXT_MENU_PLUGIN_ID_FIRST].invoke(task);

          return true;
        }
    }
  }