Esempio n. 1
0
  @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);
    }
  }
Esempio n. 2
0
  protected void onTaskDelete(Task task) {
    decrementFilterCount();

    Activity a = getActivity();
    if (a instanceof AstridActivity) {
      AstridActivity activity = (AstridActivity) a;
      TaskEditFragment tef = activity.getTaskEditFragment();
      if (tef != null) {
        if (task.getId() == tef.model.getId()) tef.discardButtonClick();
      }
    }
    TimerPlugin.updateTimer(getActivity(), task, false);
  }
Esempio n. 3
0
 protected void onTaskDelete(Task task) {
   Activity a = getActivity();
   if (a instanceof AstridActivity) {
     AstridActivity activity = (AstridActivity) a;
     TaskEditFragment tef = activity.getTaskEditFragment();
     if (tef != null) {
       if (task.getId() == tef.model.getId()) {
         tef.discardButtonClick();
       }
     }
   }
   TimerPlugin.updateTimer(notificationManager, taskService, context, task, false);
 }
Esempio n. 4
0
  @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;
        }
    }
  }