예제 #1
0
  /** Populates a view with content */
  @Override
  public void bindView(View view, Context context, Cursor c) {
    TodorooCursor<UserActivity> cursor = (TodorooCursor<UserActivity>) c;
    ModelHolder mh = ((ModelHolder) view.getTag());

    String type = cursor.getString(TYPE_PROPERTY_INDEX);

    UserActivity update = mh.activity;
    update.clear();

    User user = mh.user;
    user.clear();

    History history = mh.history;
    boolean isSelf;
    if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(type)) {
      readUserActivityProperties(cursor, update);
      isSelf = Task.USER_ID_SELF.equals(update.getValue(UserActivity.USER_UUID));
    } else {
      readHistoryProperties(cursor, history);
      isSelf = Task.USER_ID_SELF.equals(history.getValue(History.USER_UUID));
    }
    readUserProperties(cursor, user, self, isSelf);

    setFieldContentsAndVisibility(view, update, user, history, type);
  }
예제 #2
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);
    }
  }
예제 #3
0
  private void setUpListAdapter() {
    items.clear();
    this.removeAllViews();
    historyCount = 0;
    TodorooCursor<Metadata> notes =
        metadataService.query(
            Query.select(Metadata.PROPERTIES)
                .where(MetadataCriteria.byTaskAndwithKey(task.getId(), NoteMetadata.METADATA_KEY)));
    try {
      Metadata metadata = new Metadata();
      for (notes.moveToFirst(); !notes.isAfterLast(); notes.moveToNext()) {
        metadata.readFromCursor(notes);
        items.add(NoteOrUpdate.fromMetadata(metadata));
      }
    } finally {
      notes.close();
    }

    User self = UpdateAdapter.getSelfUser();

    TodorooCursor<UserActivity> updates = taskService.getActivityAndHistoryForTask(task);
    try {
      UserActivity update = new UserActivity();
      History history = new History();
      User user = new User();
      for (updates.moveToFirst(); !updates.isAfterLast(); updates.moveToNext()) {
        update.clear();
        user.clear();

        String type = updates.getString(UpdateAdapter.TYPE_PROPERTY_INDEX);
        NoteOrUpdate noa;
        boolean isSelf;
        if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(type)) {
          UpdateAdapter.readUserActivityProperties(updates, update);
          isSelf = Task.USER_ID_SELF.equals(update.getValue(UserActivity.USER_UUID));
          UpdateAdapter.readUserProperties(updates, user, self, isSelf);
          noa = NoteOrUpdate.fromUpdateOrHistory(activity, update, null, user, linkColor);
        } else {
          UpdateAdapter.readHistoryProperties(updates, history);
          isSelf = Task.USER_ID_SELF.equals(history.getValue(History.USER_UUID));
          UpdateAdapter.readUserProperties(updates, user, self, isSelf);
          noa = NoteOrUpdate.fromUpdateOrHistory(activity, null, history, user, linkColor);
          historyCount++;
        }
        if (noa != null) items.add(noa);
      }
    } finally {
      updates.close();
    }

    Collections.sort(
        items,
        new Comparator<NoteOrUpdate>() {
          @Override
          public int compare(NoteOrUpdate a, NoteOrUpdate b) {
            if (a.createdAt < b.createdAt) return 1;
            else if (a.createdAt == b.createdAt) return 0;
            else return -1;
          }
        });

    for (int i = 0; i < Math.min(items.size(), commentItems); i++) {
      View notesView = this.getUpdateNotes(items.get(i), this);
      this.addView(notesView);
    }

    if (items.size() > commentItems || task.getValue(Task.HISTORY_HAS_MORE) > 0) {
      Button loadMore = new Button(getContext());
      loadMore.setText(R.string.TEA_load_more);
      loadMore.setTextColor(activity.getResources().getColor(R.color.task_edit_deadline_gray));
      loadMore.setBackgroundColor(Color.alpha(0));
      loadMore.setOnClickListener(
          new View.OnClickListener() {
            public void onClick(View v) {
              // Perform action on click
              commentItems += 10;
              setUpListAdapter();
              if (task.getValue(Task.HISTORY_HAS_MORE) > 0)
                new FetchHistory<Task>(
                        taskDao,
                        Task.HISTORY_FETCH_DATE,
                        Task.HISTORY_HAS_MORE,
                        NameMaps.TABLE_ID_TASKS,
                        task.getUuid(),
                        task.getValue(Task.TITLE),
                        0,
                        historyCount,
                        callback)
                    .execute();
            }
          });
      this.addView(loadMore);
    } else if (items.size() == 0) {
      TextView noUpdates = new TextView(getContext());
      noUpdates.setText(R.string.TEA_no_activity);
      noUpdates.setTextColor(activity.getResources().getColor(R.color.task_edit_deadline_gray));
      noUpdates.setLayoutParams(
          new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
      noUpdates.setPadding(10, 10, 10, 10);
      noUpdates.setGravity(Gravity.CENTER);
      noUpdates.setTextSize(16);
      this.addView(noUpdates);
    }

    for (UpdatesChangedListener l : listeners) {
      l.updatesChanged();
    }
  }