public void testDailyAndGreaterFreqs() throws ParseException {
    task.setValue(
        Task.DUE_DATE,
        Task.createDueDate(
            Task.URGENCY_SPECIFIC_DAY, DateUtilities.now() - DateUtilities.ONE_WEEK));
    task.setFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION, true);

    for (int interval = 1; interval < 7; interval++) {
      for (Frequency freq : Frequency.values()) {
        long next = DateUtilities.now();
        switch (freq) {
          case DAILY:
            next += interval * DateUtilities.ONE_DAY;
            break;
          case WEEKLY:
            next += interval * DateUtilities.ONE_WEEK;
            break;
          case MONTHLY:
            next = DateUtilities.addCalendarMonthsToUnixtime(next, interval);
            break;
          case YEARLY:
            next = DateUtilities.addCalendarMonthsToUnixtime(next, interval * 12);
            break;
          default:
            continue;
        }

        buildRRule(interval, freq);
        nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal());
        assertDateEquals(freq.toString() + "x" + interval, next, nextDueDate);
        task.setValue(Task.DUE_DATE, nextDueDate);
        assertFalse(task.hasDueTime());
      }
    }
  }
 /** Compute long due date from DateValue */
 private static long buildNewDueDate(DateTime original, DateValue nextDate) {
   long newDueDate;
   if (nextDate instanceof DateTimeValueImpl) {
     DateTimeValueImpl newDateTime = (DateTimeValueImpl) nextDate;
     DateTime date =
         newDateUtc(
                 newDateTime.year(),
                 newDateTime.month(),
                 newDateTime.day(),
                 newDateTime.hour(),
                 newDateTime.minute(),
                 newDateTime.second())
             .toLocal();
     // time may be inaccurate due to DST, force time to be same
     date =
         date.withHourOfDay(original.getHourOfDay()).withMinuteOfHour(original.getMinuteOfHour());
     newDueDate = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, date.getMillis());
   } else {
     newDueDate =
         Task.createDueDate(
             Task.URGENCY_SPECIFIC_DAY,
             newDate(nextDate.year(), nextDate.month(), nextDate.day()).getMillis());
   }
   return newDueDate;
 }
Esempio n. 3
0
 private synchronized void pushUpdated(GtasksInvoker invoker, SyncResultCallback callback) {
   TodorooCursor<Task> queued =
       taskService.query(
           Query.select(Task.PROPERTIES)
               .join(
                   Join.left(
                       Metadata.TABLE,
                       Criterion.and(
                           MetadataCriteria.withKey(GtasksMetadata.METADATA_KEY),
                           Task.ID.eq(Metadata.TASK))))
               .where(
                   Criterion.or(
                       Task.MODIFICATION_DATE.gt(GtasksMetadata.LAST_SYNC),
                       Criterion.and(
                           Task.USER_ID.neq(Task.USER_ID_SELF), GtasksMetadata.ID.isNotNull()),
                       Metadata.KEY.isNull())));
   callback.incrementMax(queued.getCount() * 10);
   try {
     Task task = new Task();
     for (queued.moveToFirst(); !queued.isAfterLast(); queued.moveToNext()) {
       task.readFromCursor(queued);
       try {
         gtasksSyncService.pushTaskOnSave(task, task.getMergedValues(), invoker, false);
       } catch (GoogleTasksException e) {
         handler.handleException("gtasks-sync-io", e, e.getType()); // $NON-NLS-1$
       } catch (IOException e) {
         handler.handleException("gtasks-sync-io", e, e.toString()); // $NON-NLS-1$
       } finally {
         callback.incrementProgress(10);
       }
     }
   } finally {
     queued.close();
   }
 }
Esempio n. 4
0
 void createStartAndEndDate(Task task, ContentValues values) {
   long dueDate = task.getDueDate();
   long tzCorrectedDueDate = dueDate + TimeZone.getDefault().getOffset(dueDate);
   long tzCorrectedDueDateNow =
       DateUtilities.now() + TimeZone.getDefault().getOffset(DateUtilities.now());
   // FIXME: doesnt respect timezones, see story 17443653
   if (task.hasDueDate()) {
     if (task.hasDueTime()) {
       long estimatedTime = task.getEstimatedSeconds() * 1000;
       if (estimatedTime <= 0) {
         estimatedTime = DEFAULT_CAL_TIME;
       }
       if (preferences.getBoolean(R.string.p_end_at_deadline, true)) {
         values.put("dtstart", dueDate);
         values.put("dtend", dueDate + estimatedTime);
       } else {
         values.put("dtstart", dueDate - estimatedTime);
         values.put("dtend", dueDate);
       }
       // setting a duetime to a previously timeless event requires explicitly setting allDay=0
       values.put("allDay", "0");
       values.put("eventTimezone", TimeZone.getDefault().getID());
     } else {
       values.put("dtstart", tzCorrectedDueDate);
       values.put("dtend", tzCorrectedDueDate);
       values.put("allDay", "1");
     }
   } else {
     values.put("dtstart", tzCorrectedDueDateNow);
     values.put("dtend", tzCorrectedDueDateNow);
     values.put("allDay", "1");
   }
   adjustDateForIcs(values);
 }
Esempio n. 5
0
  // priorityHelper parses the string and sets the Task's importance
  private static boolean priorityHelper(Task task) {
    String inputText = task.getValue(Task.TITLE);
    String[] importanceStrings = {
      "()((^|[^\\w!])!+|(^|[^\\w!])!\\d)($|[^\\w!])",
      "()(?i)((\\s?bang){1,})$",
      "(?i)(\\spriority\\s?(\\d)$)",
      "(?i)(\\sbang\\s?(\\d)$)",
      "(?i)()(\\shigh(est)?|\\slow(est)?|\\stop|\\sleast) ?priority$"
    };
    boolean result = false;
    for (String importanceString : importanceStrings) {
      Pattern importancePattern = Pattern.compile(importanceString);
      while (true) {
        Matcher m = importancePattern.matcher(inputText);
        if (m.find()) {
          result = true;
          task.setValue(Task.IMPORTANCE, strToPriority(m.group(2).trim()));
          int start = m.start() == 0 ? 0 : m.start() + 1;
          inputText = inputText.substring(0, start) + inputText.substring(m.end());

        } else {
          break;
        }
      }
    }
    task.setValue(Task.TITLE, inputText.trim());
    return result;
  }
 /** Compute long due date from DateValue */
 private static long buildNewDueDate(Date original, DateValue nextDate) {
   long newDueDate;
   if (nextDate instanceof DateTimeValueImpl) {
     DateTimeValueImpl newDateTime = (DateTimeValueImpl) nextDate;
     Date date =
         new Date(
             Date.UTC(
                 newDateTime.year() - 1900,
                 newDateTime.month() - 1,
                 newDateTime.day(),
                 newDateTime.hour(),
                 newDateTime.minute(),
                 newDateTime.second()));
     // time may be inaccurate due to DST, force time to be same
     date.setHours(original.getHours());
     date.setMinutes(original.getMinutes());
     newDueDate = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, date.getTime());
   } else {
     newDueDate =
         Task.createDueDate(
             Task.URGENCY_SPECIFIC_DAY,
             new Date(nextDate.year() - 1900, nextDate.month() - 1, nextDate.day()).getTime());
   }
   return newDueDate;
 }
Esempio n. 7
0
  /**
   * Create a task container for the given remote task
   *
   * @throws JSONException
   */
  private GtasksTaskContainer parseRemoteTask(
      com.google.api.services.tasks.model.Task remoteTask, String listId) {
    Task task = new Task();

    ArrayList<Metadata> metadata = new ArrayList<Metadata>();

    task.setValue(Task.TITLE, remoteTask.getTitle());
    task.setValue(Task.CREATION_DATE, DateUtilities.now());
    task.setValue(
        Task.COMPLETION_DATE,
        GtasksApiUtilities.gtasksCompletedTimeToUnixTime(remoteTask.getCompleted(), 0));
    if (remoteTask.getDeleted() == null || !remoteTask.getDeleted().booleanValue())
      task.setValue(Task.DELETION_DATE, 0L);
    else if (remoteTask.getDeleted().booleanValue())
      task.setValue(Task.DELETION_DATE, DateUtilities.now());
    if (remoteTask.getHidden() != null && remoteTask.getHidden().booleanValue())
      task.setValue(Task.DELETION_DATE, DateUtilities.now());

    long dueDate = GtasksApiUtilities.gtasksDueTimeToUnixTime(remoteTask.getDue(), 0);
    long createdDate = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY, dueDate);
    task.setValue(Task.DUE_DATE, createdDate);
    task.setValue(Task.NOTES, remoteTask.getNotes());

    Metadata gtasksMetadata = GtasksMetadata.createEmptyMetadata(AbstractModel.NO_ID);
    gtasksMetadata.setValue(GtasksMetadata.ID, remoteTask.getId());
    gtasksMetadata.setValue(GtasksMetadata.LIST_ID, listId);

    GtasksTaskContainer container = new GtasksTaskContainer(task, metadata, gtasksMetadata);
    return container;
  }
Esempio n. 8
0
  private void write(GtasksTaskContainer task) throws IOException {
    //  merge astrid dates with google dates
    if (!task.task.isSaved() && actFmPreferenceService.isLoggedIn()) titleMatchWithActFm(task.task);

    if (task.task.isSaved()) {
      Task local =
          PluginServices.getTaskService()
              .fetchById(task.task.getId(), Task.DUE_DATE, Task.COMPLETION_DATE);
      if (local == null) {
        task.task.clearValue(Task.ID);
      } else {
        mergeDates(task.task, local);
        if (task.task.isCompleted() && !local.isCompleted())
          StatisticsService.reportEvent(StatisticsConstants.GTASKS_TASK_COMPLETED);
      }
    } else { // Set default importance and reminders for remotely created tasks
      task.task.setValue(
          Task.IMPORTANCE,
          Preferences.getIntegerFromString(
              R.string.p_default_importance_key, Task.IMPORTANCE_SHOULD_DO));
      TaskDao.setDefaultReminders(task.task);
    }
    if (!TextUtils.isEmpty(task.task.getValue(Task.TITLE))) {
      task.task.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true);
      gtasksMetadataService.saveTaskAndMetadata(task);
    }
  }
Esempio n. 9
0
  @Override
  public String writeToModel(Task task) {
    Metadata metadata = ProducteevDataService.getInstance().getTaskMetadata(task.getId());
    try {
      if (metadata == null) {
        metadata = new Metadata();
        metadata.setValue(Metadata.KEY, ProducteevTask.METADATA_KEY);
        metadata.setValue(Metadata.TASK, task.getId());
        metadata.setValue(ProducteevTask.ID, 0L);
      }

      ProducteevDashboard dashboard = (ProducteevDashboard) dashboardSelector.getSelectedItem();
      metadata.setValue(ProducteevTask.DASHBOARD_ID, dashboard.getId());

      ProducteevUser responsibleUser = (ProducteevUser) responsibleSelector.getSelectedItem();

      if (responsibleUser == null) metadata.setValue(ProducteevTask.RESPONSIBLE_ID, 0L);
      else metadata.setValue(ProducteevTask.RESPONSIBLE_ID, responsibleUser.getId());

      // Erase PDTV-repeating-info if task itself is repeating with Astrid-repeat
      if (task.containsNonNullValue(Task.RECURRENCE)
          && task.getValue(Task.RECURRENCE).length() > 0) {
        metadata.setValue(ProducteevTask.REPEATING_SETTING, "");
      }

      if (metadata.getSetValues().size() > 0) {
        metadataService.save(metadata);
        task.setValue(Task.MODIFICATION_DATE, DateUtilities.now());
      }
    } catch (Exception e) {
      Log.e("error-saving-pdv", "Error Saving Metadata", e); // $NON-NLS-1$ //$NON-NLS-2$
    }
    return null;
  }
Esempio n. 10
0
 public static void createDefaultHideUntil(Task item) {
   if (!item.containsValue(Task.HIDE_UNTIL)) {
     int setting =
         Preferences.getIntegerFromString(R.string.p_default_hideUntil_key, Task.HIDE_UNTIL_NONE);
     item.setValue(Task.HIDE_UNTIL, item.createHideUntil(setting, 0));
   }
 }
Esempio n. 11
0
    @Override
    public void readFromTask(Task task) {
      long date = task.getValue(Task.HIDE_UNTIL);

      Date dueDay = new Date(task.getValue(Task.DUE_DATE) / 1000L * 1000L);
      dueDay.setHours(0);
      dueDay.setMinutes(0);
      dueDay.setSeconds(0);

      int selection = 0;
      if (date == 0) {
        selection = 0;
        date = 0;
      } else if (date == dueDay.getTime()) {
        selection = 1;
        date = 0;
      } else if (date + DateUtilities.ONE_DAY == dueDay.getTime()) {
        selection = 2;
        date = 0;
      } else if (date + DateUtilities.ONE_WEEK == dueDay.getTime()) {
        selection = 3;
        date = 0;
      }

      HideUntilValue[] list = createHideUntilList(date);
      adapter =
          new ArrayAdapter<HideUntilValue>(
              TaskEditActivity.this, android.R.layout.simple_spinner_item, list);
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spinner.setAdapter(adapter);

      spinner.setSelection(selection);
    }
Esempio n. 12
0
 @Override
 public String writeToModel(Task task) {
   task.setValue(Task.REMINDER_FLAGS, getValue());
   // clear snooze if task is being edited
   task.setValue(Task.REMINDER_SNOOZE, 0L);
   return null;
 }
  public void testSubDailyFreqs() throws ParseException {
    task.setValue(Task.DUE_DATE, DateUtilities.now() - DateUtilities.ONE_WEEK);
    task.setFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION, true);

    for (Frequency freq : Frequency.values()) {
      long interval = -1;
      switch (freq) {
        case MINUTELY:
          interval = DateUtilities.ONE_MINUTE;
          break;
        case HOURLY:
          interval = DateUtilities.ONE_HOUR;
          break;
        default:
          continue;
      }

      buildRRule(1, freq);
      nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal());

      buildRRule(6, freq);
      nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal());
      assertDateTimeEquals(freq.toString() + "x6", DateUtilities.now() + 6 * interval, nextDueDate);
      task.setValue(Task.DUE_DATE, nextDueDate);
      assertTrue(task.hasDueTime());
    }
  }
Esempio n. 14
0
  protected Task createTask(String title) {
    Task task = new Task();
    task.setTitle(title);
    task.setImportance(SYNC_TASK_IMPORTANCE);

    taskDao.createNew(task);
    return task;
  }
Esempio n. 15
0
 @Override
 protected String writeToModelAfterInitialized(Task task) {
   long dueDate = dateAndTimePicker.constructDueDate();
   if (dueDate != task.getValue(Task.DUE_DATE)) // Clear snooze if due date has changed
   task.setValue(Task.REMINDER_SNOOZE, 0L);
   task.setValue(Task.DUE_DATE, dueDate);
   return null;
 }
Esempio n. 16
0
 private void addComment() {
   addComment(
       commentField.getText().toString(),
       UserActivity.ACTION_TASK_COMMENT,
       task.getUuid(),
       task.getValue(Task.TITLE),
       true);
 }
Esempio n. 17
0
 @Override
 public String writeToModel(Task task) {
   if (settingCheckbox.isChecked()) {
     int hourValue = hours[periodSpinner.getSelectedItemPosition()];
     task.setValue(Task.REMINDER_PERIOD, hourValue * DateUtilities.ONE_HOUR);
   } else task.setValue(Task.REMINDER_PERIOD, 0L);
   return null;
 }
Esempio n. 18
0
 @Override
 public String writeToModel(Task task) {
   if (adapter == null || spinner == null) return null;
   HideUntilValue item = adapter.getItem(spinner.getSelectedItemPosition());
   if (item == null) return null;
   long value = task.createHideUntil(item.setting, item.date);
   task.setValue(Task.HIDE_UNTIL, value);
   return null;
 }
  public void testTimeZoneLate() throws ParseException {
    TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
    task.setValue(Task.DUE_DATE, DateUtilities.now() + DateUtilities.ONE_WEEK);
    task.setFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION, true);
    nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal());

    long expected = Task.createDueDate(Task.URGENCY_TOMORROW, 0);
    assertDateEquals("tomorrow", expected, nextDueDate);
  }
Esempio n. 20
0
  @Override
  public boolean createNew(Task item) {
    if (!item.containsValue(Task.CREATION_DATE))
      item.setValue(Task.CREATION_DATE, DateUtilities.now());
    item.setValue(Task.MODIFICATION_DATE, DateUtilities.now());

    // set up task defaults
    if (!item.containsValue(Task.IMPORTANCE))
      item.setValue(
          Task.IMPORTANCE,
          Preferences.getIntegerFromString(
              R.string.p_default_importance_key, Task.IMPORTANCE_SHOULD_DO));
    if (!item.containsValue(Task.DUE_DATE)) {
      int setting =
          Preferences.getIntegerFromString(R.string.p_default_urgency_key, Task.URGENCY_NONE);
      item.setValue(Task.DUE_DATE, Task.createDueDate(setting, 0));
    }
    createDefaultHideUntil(item);

    setDefaultReminders(item);

    ContentValues values = item.getSetValues();
    boolean result = super.createNew(item);
    if (result) {
      userRetentionMetrics();
      afterSave(item, values);
    }
    return result;
  }
Esempio n. 21
0
  // Parses through the text and sets the frequency of the task.
  private static boolean repeatHelper(Task task) {
    if (task.containsNonNullValue(Task.RECURRENCE)) {
      return false;
    }
    String inputText = task.getValue(Task.TITLE);
    HashMap<String, Frequency> repeatTimes = new HashMap<String, Frequency>();
    repeatTimes.put("(?i)\\bevery ?\\w{0,6} days?\\b", Frequency.DAILY);
    repeatTimes.put("(?i)\\bevery ?\\w{0,6} ?nights?\\b", Frequency.DAILY);
    repeatTimes.put("(?i)\\bevery ?\\w{0,6} ?mornings?\\b", Frequency.DAILY);
    repeatTimes.put("(?i)\\bevery ?\\w{0,6} ?evenings?\\b", Frequency.DAILY);
    repeatTimes.put("(?i)\\bevery ?\\w{0,6} ?afternoons?\\b", Frequency.DAILY);
    repeatTimes.put("(?i)\\bevery \\w{0,6} ?weeks?\\b", Frequency.WEEKLY);
    repeatTimes.put(
        "(?i)\\bevery \\w{0,6} ?(mon|tues|wednes|thurs|fri|satur|sun)days?\\b", Frequency.WEEKLY);
    repeatTimes.put("(?i)\\bevery \\w{0,6} ?months?\\b", Frequency.MONTHLY);
    repeatTimes.put("(?i)\\bevery \\w{0,6} ?years?\\b", Frequency.YEARLY);

    HashMap<String, Frequency> repeatTimesIntervalOne = new HashMap<String, Frequency>();
    // pre-determined intervals of 1
    repeatTimesIntervalOne.put("(?i)\\bdaily\\b", Frequency.DAILY);
    repeatTimesIntervalOne.put("(?i)\\beveryday\\b", Frequency.DAILY);
    repeatTimesIntervalOne.put("(?i)\\bweekly\\b", Frequency.WEEKLY);
    repeatTimesIntervalOne.put("(?i)\\bmonthly\\b", Frequency.MONTHLY);
    repeatTimesIntervalOne.put("(?i)\\byearly\\b", Frequency.YEARLY);

    Set<String> keys = repeatTimes.keySet();
    for (String repeatTime : keys) {
      Pattern pattern = Pattern.compile(repeatTime);
      Matcher m = pattern.matcher(inputText);
      if (m.find()) {
        Frequency rtime = repeatTimes.get(repeatTime);
        RRule rrule = new RRule();
        rrule.setFreq(rtime);
        rrule.setInterval(findInterval(inputText));
        task.setValue(Task.RECURRENCE, rrule.toIcal());
        return true;
      }
    }

    for (String repeatTimeIntervalOne : repeatTimesIntervalOne.keySet()) {
      Pattern pattern = Pattern.compile(repeatTimeIntervalOne);
      Matcher m = pattern.matcher(inputText);
      if (m.find()) {
        Frequency rtime = repeatTimesIntervalOne.get(repeatTimeIntervalOne);
        RRule rrule = new RRule();
        rrule.setFreq(rtime);
        rrule.setInterval(1);
        String thing = rrule.toIcal();
        task.setValue(Task.RECURRENCE, thing);
        return true;
      }
    }
    return false;
  }
Esempio n. 22
0
 @Override
 protected String writeToModelAfterInitialized(Task task) {
   if (settingCheckbox.isChecked()) {
     int hourValue = hours[periodSpinner.getSelectedItemPosition()];
     task.setValue(Task.REMINDER_PERIOD, hourValue * DateUtilities.ONE_HOUR);
     if (task.getSetValues().containsKey(Task.REMINDER_PERIOD.name)) {}
   } else {
     task.setValue(Task.REMINDER_PERIOD, 0L);
   }
   return null;
 }
Esempio n. 23
0
 @Override
 public void timerStarted(Task t) {
   addComment(
       String.format(
           "%s %s", //$NON-NLS-1$
           getContext().getString(R.string.TEA_timer_comment_started),
           DateUtilities.getTimeString(getContext(), new Date())),
       UserActivity.ACTION_TASK_COMMENT,
       t.getUuid(),
       t.getValue(Task.TITLE),
       false);
 }
Esempio n. 24
0
  /**
   * Show a new notification about the given task. Returns false if there was some sort of error or
   * the alarm should be disabled.
   */
  public boolean showTaskNotification(long id, int type, String reminder) {
    Task task;
    try {
      task =
          taskDao.fetch(
              id,
              Task.ID,
              Task.TITLE,
              Task.HIDE_UNTIL,
              Task.COMPLETION_DATE,
              Task.DUE_DATE,
              Task.DELETION_DATE,
              Task.REMINDER_FLAGS);
      if (task == null)
        throw new IllegalArgumentException("cound not find item with id"); // $NON-NLS-1$

    } catch (Exception e) {
      exceptionService.reportError("show-notif", e); // $NON-NLS-1$
      return false;
    }

    // you're done - don't sound, do delete
    if (task.isCompleted() || task.isDeleted()) return false;

    // it's hidden - don't sound, don't delete
    if (task.isHidden() && type == ReminderService.TYPE_RANDOM) return true;

    // task due date was changed, but alarm wasn't rescheduled
    if ((type == ReminderService.TYPE_DUE || type == ReminderService.TYPE_OVERDUE)
        && (!task.hasDueDate() || task.getValue(Task.DUE_DATE) > DateUtilities.now())) return true;

    // read properties
    String taskTitle = task.getValue(Task.TITLE);
    boolean nonstopMode = task.getFlag(Task.REMINDER_FLAGS, Task.NOTIFY_MODE_NONSTOP);
    boolean ringFiveMode = task.getFlag(Task.REMINDER_FLAGS, Task.NOTIFY_MODE_FIVE);
    int ringTimes = nonstopMode ? -1 : (ringFiveMode ? 5 : 1);

    // update last reminder time
    task.setValue(Task.REMINDER_LAST, DateUtilities.now());
    taskDao.saveExisting(task);

    Context context = ContextManager.getContext();
    String title = context.getString(R.string.app_name);
    String text = reminder + " " + taskTitle; // $NON-NLS-1$

    Intent notifyIntent = new Intent(context, NotificationActivity.class);
    notifyIntent.setAction("NOTIFY" + id); // $NON-NLS-1$
    notifyIntent.putExtra(NotificationActivity.TOKEN_ID, id);
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

    showNotification((int) id, notifyIntent, type, title, text, ringTimes);
    return true;
  }
Esempio n. 25
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. 26
0
 @Override
 public boolean saveExisting(Task item) {
   ContentValues values = item.getSetValues();
   if (values == null || values.size() == 0) return false;
   if (!TaskApiDao.insignificantChange(values)) {
     item.setValue(Task.DETAILS, null);
     if (!values.containsKey(Task.MODIFICATION_DATE.name))
       item.setValue(Task.MODIFICATION_DATE, DateUtilities.now());
   }
   boolean result = super.saveExisting(item);
   if (result) afterSave(item, values);
   return result;
 }
 private void assertDateEquals(String message, long expected, long actual) {
   expected = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY, expected);
   actual = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY, actual);
   assertEquals(
       message
           + ": Due Date is '"
           + DateUtilities.getDateStringWithWeekday(getContext(), new Date(actual))
           + "', expected '"
           + DateUtilities.getDateStringWithWeekday(getContext(), new Date(expected))
           + "'",
       expected,
       actual);
 }
  @Test
  public void testDueDateSpecificTime() throws ParseException {
    buildRRule(1, Frequency.DAILY);

    // test specific day & time
    long dayWithTime =
        Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, newDate(2010, 8, 1, 10, 4, 0).getTime());
    task.setValue(Task.DUE_DATE, dayWithTime);

    long nextDayWithTime = dayWithTime + DateUtilities.ONE_DAY;
    nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal(), false);
    assertDateTimeEquals(nextDayWithTime, nextDueDate);
  }
Esempio n. 29
0
  public String getTaskEventUri(Task task) {
    String uri;
    if (!TextUtils.isEmpty(task.getCalendarURI())) {
      uri = task.getCalendarURI();
    } else {
      task = taskService.fetchById(task.getId(), Task.CALENDAR_URI);
      if (task == null) {
        return null;
      }
      uri = task.getCalendarURI();
    }

    return uri;
  }
Esempio n. 30
0
 @Override
 public void timerStopped(Task t) {
   String elapsedTime = DateUtils.formatElapsedTime(t.getValue(Task.ELAPSED_SECONDS));
   addComment(
       String.format(
           "%s %s\n%s %s", //$NON-NLS-1$
           getContext().getString(R.string.TEA_timer_comment_stopped),
           DateUtilities.getTimeString(getContext(), new Date()),
           getContext().getString(R.string.TEA_timer_comment_spent),
           elapsedTime),
       UserActivity.ACTION_TASK_COMMENT,
       t.getUuid(),
       t.getValue(Task.TITLE),
       false);
 }