コード例 #1
0
  /** Save task model from values in UI components */
  private void save() {
    StringBuilder toast = new StringBuilder();
    for (TaskEditControlSet controlSet : controls) {
      String toastText = controlSet.writeToModel(model);
      if (toastText != null) toast.append('\n').append(toastText);
    }

    if (title.getText().length() > 0) model.setValue(Task.DELETION_DATE, 0L);

    if (taskService.save(model) && title.getText().length() > 0) showSaveToast(toast.toString());
  }
コード例 #2
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();
    }
  }
コード例 #3
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);
    }
  }
コード例 #4
0
  public static void rescheduleTask(
      Context context, GCalHelper gcalHelper, TaskService taskService, Task task, long newDueDate) {
    long hideUntil = task.getHideUntil();
    if (hideUntil > 0 && task.getDueDate() > 0) {
      hideUntil += newDueDate - task.getDueDate();
    }

    task.setReminderSnooze(0L);
    task.setCompletionDate(0L);
    task.setDueDate(newDueDate);
    task.setHideUntil(hideUntil);
    task.putTransitory(TaskService.TRANS_REPEAT_COMPLETE, true);

    ContentResolver cr = context.getContentResolver();
    gcalHelper.rescheduleRepeatingTask(task, cr);
    taskService.save(task);
  }
コード例 #5
0
  /**
   * Save sharing settings
   *
   * @param toast toast to show after saving is finished
   * @return false if login is required & save should be halted
   */
  @SuppressWarnings("nls")
  public boolean saveSharingSettings(String toast) {
    if (task == null) return false;

    saveToast = toast;
    boolean dirty = false;
    try {
      JSONObject userJson = null;
      TextView assignedView = null;
      if (assignedCustom.getVisibility() == View.VISIBLE) {
        userJson = PeopleContainer.createUserJson(assignedCustom);
        assignedView = assignedCustom;
      } else if (assignedSpinner.getSelectedItem() != null) {
        userJson = ((AssignedToUser) assignedSpinner.getSelectedItem()).user;
      }

      if (userJson != null && userJson.optString("email").indexOf('@') == -1) {
        throw new ParseSharedException(
            assignedView,
            activity.getString(R.string.actfm_EPA_invalid_email, userJson.optString("email")));
      }

      if (userJson == null || userJson.optLong("id", -1) == 0) {
        dirty = task.getValue(Task.USER_ID) == 0L ? dirty : true;
        task.setValue(Task.USER_ID, 0L);
        if (!TextUtils.isEmpty(task.getValue(Task.USER))) task.setValue(Task.USER, "{}");
      } else {
        String user = userJson.toString();

        long taskUserId = -1;
        String taskUserEmail = "";
        try {
          JSONObject taskUser = new JSONObject(task.getValue(Task.USER));
          taskUserId = taskUser.optLong("id", -1);
          taskUserEmail = taskUser.optString("email");
        } catch (JSONException e) {
          // sad times
        }
        long userId = userJson.optLong("id", -1);
        String userEmail = userJson.optString("email");

        boolean match = (userId == taskUserId && userId != -1);
        match = match || (userEmail.equals(taskUserEmail) && !TextUtils.isEmpty(userEmail));

        dirty = match ? dirty : true;
        task.setValue(Task.USER_ID, userJson.optLong("id", -1));
        task.setValue(Task.USER, user);
      }

      JSONObject sharedWith = parseSharedWithAndTags();
      dirty = dirty || sharedWith.has("p");
      if (!TextUtils.isEmpty(task.getValue(Task.SHARED_WITH)) || sharedWith.length() != 0)
        task.setValue(Task.SHARED_WITH, sharedWith.toString());

      if (dirty) taskService.save(task);

      if (dirty && !actFmPreferenceService.isLoggedIn()) {
        activity.startActivityForResult(
            new Intent(activity, ActFmLoginActivity.class), loginRequestCode);
        return false;
      }

      if (dirty) shareTask(sharedWith);
      else showSaveToast();

      return true;
    } catch (JSONException e) {
      exceptionService.displayAndReportError(activity, "save-people", e);
    } catch (ParseSharedException e) {
      if (e.view != null) {
        e.view.setTextColor(Color.RED);
        e.view.requestFocus();
      }
      DialogUtilities.okDialog(activity, e.message, null);
    }
    return false;
  }
コード例 #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;
        }
    }
  }
コード例 #7
0
ファイル: TaskTests.java プロジェクト: mjording/astrid
 /** Check task gets a creation date at some point */
 public void checkCreationDate() {
   Task task = new Task();
   taskService.save(task);
   assertTrue(task.getValue(Task.CREATION_DATE) > 0);
 }