Пример #1
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();
   }
 }
Пример #2
0
 /** Schedules all alarms */
 public void scheduleAllAlarms() {
   TodorooCursor<Task> cursor = getTasksWithReminders(NOTIFICATION_PROPERTIES);
   try {
     Task task = new Task();
     now = DateUtilities.now(); // Before mass scheduling, initialize now variable
     for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
       task.readFromCursor(cursor);
       scheduleAlarm(task, false);
     }
   } catch (Exception e) {
     // suppress
   } finally {
     cursor.close();
     now = -1; // Signal done with now variable
   }
 }
Пример #3
0
  /**
   * Cursor with the following columns
   *
   * <ol>
   *   <li>task title, string
   *   <li>task importance color, int android RGB color
   *   <li>task due date (was: preferred due date), long millis since epoch
   *   <li>task due date (was: absolute due date), long millis since epoch
   *   <li>task importance, integer from 0 to 3 (0 => most important)
   *   <li>task id, long
   *   <li>task tags, string tags separated by |
   * </ol>
   *
   * @return cursor as described above
   */
  public Cursor getTasks() {

    MatrixCursor ret = new MatrixCursor(TASK_FIELD_LIST);

    TodorooCursor<Task> cursor =
        taskService.query(
            Query.select(Task.ID, Task.TITLE, Task.IMPORTANCE, Task.DUE_DATE)
                .where(Criterion.and(TaskCriteria.isActive(), TaskCriteria.isVisible()))
                .orderBy(SortHelper.defaultTaskOrder())
                .limit(MAX_NUMBER_OF_TASKS));
    try {
      int[] importanceColors = Task.getImportanceColors(ctx.getResources());
      Task task = new Task();
      for (int i = 0; i < cursor.getCount(); i++) {
        cursor.moveToNext();
        task.readFromCursor(cursor);

        StringBuilder taskTags = new StringBuilder();
        TodorooCursor<Metadata> tagCursor = TagService.getInstance().getTags(task.getId());
        try {
          for (tagCursor.moveToFirst(); !tagCursor.isAfterLast(); tagCursor.moveToNext())
            taskTags.append(tagCursor.get(TagService.TAG)).append(TAG_SEPARATOR);
        } finally {
          tagCursor.close();
        }

        Object[] values = new Object[7];
        values[0] = task.getValue(Task.TITLE);
        values[1] = importanceColors[task.getValue(Task.IMPORTANCE)];
        values[2] = task.getValue(Task.DUE_DATE);
        values[3] = task.getValue(Task.DUE_DATE);
        values[4] = task.getValue(Task.IMPORTANCE);
        values[5] = task.getId();
        values[6] = taskTags.toString();

        ret.addRow(values);
      }
    } finally {
      cursor.close();
    }

    return ret;
  }
Пример #4
0
  private void serializeTasks() throws IOException {
    TodorooCursor<Task> cursor =
        taskService.query(Query.select(Task.PROPERTIES).orderBy(Order.asc(Task.ID)));
    try {
      Task task = new Task();
      int length = cursor.getCount();
      for (int i = 0; i < length; i++) {
        cursor.moveToNext();
        task.readFromCursor(cursor);

        setProgress(i, length);

        xml.startTag(null, BackupConstants.TASK_TAG);
        serializeModel(task, Task.PROPERTIES, Task.ID);
        serializeMetadata(task);
        xml.endTag(null, BackupConstants.TASK_TAG);
        this.exportCount++;
      }
    } finally {
      cursor.close();
    }
  }
Пример #5
0
  /** Fixes task filter missing tasks bug, migrate PDV/RTM notes */
  @SuppressWarnings("nls")
  private void upgrade3To3_7() {
    TodorooCursor<Task> t =
        taskService.query(Query.select(Task.ID, Task.DUE_DATE).where(Task.DUE_DATE.gt(0)));
    Task task = new Task();
    for (t.moveToFirst(); !t.isAfterLast(); t.moveToNext()) {
      task.readFromCursor(t);
      if (task.hasDueDate()) {
        task.setValue(Task.DUE_DATE, task.getValue(Task.DUE_DATE) / 1000L * 1000L);
        taskService.save(task);
      }
    }
    t.close();

    TodorooCursor<Metadata> m =
        metadataService.query(
            Query.select(Metadata.PROPERTIES)
                .where(
                    Criterion.or(
                        Metadata.KEY.eq("producteev-note"), Metadata.KEY.eq("rmilk-note"))));

    StringProperty PDV_NOTE_ID = Metadata.VALUE1;
    StringProperty PDV_NOTE_MESSAGE = Metadata.VALUE2;
    LongProperty PDV_NOTE_CREATED = new LongProperty(Metadata.TABLE, Metadata.VALUE3.name);

    StringProperty RTM_NOTE_ID = Metadata.VALUE1;
    StringProperty RTM_NOTE_TITLE = Metadata.VALUE2;
    StringProperty RTM_NOTE_TEXT = Metadata.VALUE3;
    LongProperty RTM_NOTE_CREATED = new LongProperty(Metadata.TABLE, Metadata.VALUE4.name);

    Metadata metadata = new Metadata();
    for (m.moveToFirst(); !m.isAfterLast(); m.moveToNext()) {
      metadata.readFromCursor(m);

      String id, body, title, provider;
      long created;
      if ("rmilk-note".equals(metadata.getValue(Metadata.KEY))) {
        id = metadata.getValue(RTM_NOTE_ID);
        body = metadata.getValue(RTM_NOTE_TEXT);
        title = metadata.getValue(RTM_NOTE_TITLE);
        created = metadata.getValue(RTM_NOTE_CREATED);
        provider = MilkNoteHelper.PROVIDER;
      } else {
        id = metadata.getValue(PDV_NOTE_ID);
        body = metadata.getValue(PDV_NOTE_MESSAGE);
        created = metadata.getValue(PDV_NOTE_CREATED);
        title =
            DateUtilities.getDateStringWithWeekday(ContextManager.getContext(), new Date(created));
        provider = ProducteevDataService.NOTE_PROVIDER;
      }

      metadata.setValue(Metadata.KEY, NoteMetadata.METADATA_KEY);
      metadata.setValue(Metadata.CREATION_DATE, created);
      metadata.setValue(NoteMetadata.BODY, body);
      metadata.setValue(NoteMetadata.TITLE, title);
      metadata.setValue(NoteMetadata.THUMBNAIL, null);
      metadata.setValue(NoteMetadata.EXT_PROVIDER, provider);
      metadata.setValue(NoteMetadata.EXT_ID, id);

      metadata.clearValue(Metadata.ID);
      metadataService.save(metadata);
    }
    m.close();
  }
Пример #6
0
    @SuppressWarnings("nls")
    public RemoteViews buildUpdate(Context context, int widgetId) {
      DependencyInjectionService.getInstance().inject(this);

      RemoteViews views = null;

      views = new RemoteViews(context.getPackageName(), R.layout.widget_initialized);

      int[] textIDs = TEXT_IDS;
      int[] separatorIDs = SEPARATOR_IDS;
      int numberOfTasks = 5;

      for (int i = 0; i < textIDs.length; i++) views.setTextViewText(textIDs[i], "");

      TodorooCursor<Task> cursor = null;
      Filter filter = null;
      try {
        filter = getFilter(widgetId);
        views.setTextViewText(R.id.widget_title, filter.title);

        SharedPreferences publicPrefs = AstridPreferences.getPublicPrefs(this);
        int flags = publicPrefs.getInt(SortHelper.PREF_SORT_FLAGS, 0);
        int sort = publicPrefs.getInt(SortHelper.PREF_SORT_SORT, 0);
        String query =
            SortHelper.adjustQueryForFlagsAndSort(filter.sqlQuery, flags, sort)
                    .replaceAll("LIMIT \\d+", "")
                + " LIMIT "
                + numberOfTasks;

        database.openForReading();
        cursor =
            taskService.fetchFiltered(
                query, null, Task.ID, Task.TITLE, Task.DUE_DATE, Task.COMPLETION_DATE);
        Task task = new Task();
        for (int i = 0; i < cursor.getCount() && i < numberOfTasks; i++) {
          cursor.moveToPosition(i);
          task.readFromCursor(cursor);

          String textContent = "";
          int textColor = Color.WHITE;

          textContent = task.getValue(Task.TITLE);

          if (task.isCompleted())
            textColor = context.getResources().getColor(R.color.task_list_done);
          else if (task.hasDueDate() && task.getValue(Task.DUE_DATE) < DateUtilities.now())
            textColor = context.getResources().getColor(R.color.task_list_overdue);

          if (i > 0) views.setViewVisibility(separatorIDs[i - 1], View.VISIBLE);
          views.setTextViewText(textIDs[i], textContent);
          views.setTextColor(textIDs[i], textColor);
        }

        for (int i = cursor.getCount() - 1; i < separatorIDs.length; i++) {
          if (i >= 0) views.setViewVisibility(separatorIDs[i], View.INVISIBLE);
        }
      } catch (Exception e) {
        // can happen if database is not ready
        Log.e("WIDGET-UPDATE", "Error updating widget", e);
      } finally {
        if (cursor != null) cursor.close();
      }

      updateForScreenSize(views);

      Intent listIntent = new Intent(context, TaskListActivity.class);
      String customIntent =
          Preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_INTENT + widgetId);
      if (customIntent != null) {
        listIntent.setComponent(ComponentName.unflattenFromString(customIntent));
        String serializedExtras =
            Preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_EXTRAS + widgetId);
        Bundle extras = AndroidUtilities.bundleFromSerializedString(serializedExtras);
        listIntent.putExtras(extras);
      }
      listIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_WIDGET);
      listIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
      if (filter != null) {
        listIntent.putExtra(TaskListActivity.TOKEN_FILTER, filter);
        listIntent.setAction("L" + widgetId + filter.sqlQuery);
      }
      PendingIntent pendingIntent =
          PendingIntent.getActivity(
              context, widgetId, listIntent, PendingIntent.FLAG_CANCEL_CURRENT);
      views.setOnClickPendingIntent(R.id.taskbody, pendingIntent);

      Intent editIntent = new Intent(context, TaskEditActivity.class);
      editIntent.setFlags(
          Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
      if (filter != null && filter.valuesForNewTasks != null) {
        String values = AndroidUtilities.contentValuesToSerializedString(filter.valuesForNewTasks);
        editIntent.putExtra(TaskEditActivity.TOKEN_VALUES, values);
        editIntent.setType(values);
      }
      pendingIntent = PendingIntent.getActivity(context, 0, editIntent, 0);
      views.setOnClickPendingIntent(R.id.widget_button, pendingIntent);

      return views;
    }