예제 #1
0
  /**
   * Schedules alarms for a single task
   *
   * @param shouldPerformPropertyCheck whether to check if task has requisite properties
   */
  private void scheduleAlarm(Task task, boolean shouldPerformPropertyCheck) {
    if (task == null || !task.isSaved()) return;

    // read data if necessary
    if (shouldPerformPropertyCheck) {
      for (Property<?> property : NOTIFICATION_PROPERTIES) {
        if (!task.containsValue(property)) {
          task = taskDao.fetch(task.getId(), NOTIFICATION_PROPERTIES);
          if (task == null) return;
          break;
        }
      }
    }

    // Make sure no alarms are scheduled other than the next one. When that one is shown, it
    // will schedule the next one after it, and so on and so forth.
    clearAllAlarms(task);
    if (task.isCompleted()
        || task.isDeleted()
        || !Task.USER_ID_SELF.equals(task.getValue(Task.USER_ID))) {
      return;
    }

    // snooze reminder
    long whenSnooze = calculateNextSnoozeReminder(task);

    // random reminders
    long whenRandom = calculateNextRandomReminder(task);

    // notifications at due date
    long whenDueDate = calculateNextDueDateReminder(task);

    // notifications after due date
    long whenOverdue = calculateNextOverdueReminder(task);

    // For alarms around/before now, increment the now value so the next one will be later
    if (whenDueDate <= now || whenOverdue <= now) {
      whenDueDate = now;
      whenOverdue = now;
      now +=
          30 * DateUtilities.ONE_MINUTE; // Prevents overdue tasks from being scheduled all at once
    }

    // if random reminders are too close to due date, favor due date
    if (whenRandom != NO_ALARM && whenDueDate - whenRandom < DateUtilities.ONE_DAY)
      whenRandom = NO_ALARM;

    // snooze trumps all
    if (whenSnooze != NO_ALARM) {
      scheduler.createAlarm(task, whenSnooze, TYPE_SNOOZE);
    } else if (whenRandom < whenDueDate && whenRandom < whenOverdue) {
      scheduler.createAlarm(task, whenRandom, TYPE_RANDOM);
    } else if (whenDueDate < whenOverdue) {
      scheduler.createAlarm(task, whenDueDate, TYPE_DUE);
    } else if (whenOverdue != NO_ALARM) {
      scheduler.createAlarm(task, whenOverdue, TYPE_OVERDUE);
    } else {
      scheduler.createAlarm(task, 0, 0);
    }
  }
예제 #2
0
  @Override
  public void finish() {
    super.finish();

    // abandon editing and delete the newly created task if
    // no title was entered

    if (title.getText().length() == 0 && isNewTask && model.isSaved()) {
      taskService.delete(model);
    }
  }
예제 #3
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);
    }
  }