예제 #1
0
  @SuppressWarnings("nls")
  private TodorooCursor<Task> constructCursor() {
    String tagName = null;
    if (getActiveTagData() != null) tagName = getActiveTagData().getValue(TagData.NAME);

    String[] emergentTags = TagService.getInstance().getEmergentTags();
    StringProperty tagProperty =
        new StringProperty(null, TAGS_METADATA_JOIN + "." + TagService.TAG.name);

    Criterion tagsJoinCriterion =
        Criterion.and(
            Field.field(TAGS_METADATA_JOIN + "." + Metadata.KEY.name)
                .eq(TagService.KEY), // $NON-NLS-1$
            Task.ID.eq(Field.field(TAGS_METADATA_JOIN + "." + Metadata.TASK.name)),
            Criterion.not(tagProperty.in(emergentTags)));
    if (tagName != null)
      tagsJoinCriterion =
          Criterion.and(
              tagsJoinCriterion,
              Field.field(TAGS_METADATA_JOIN + "." + TagService.TAG.name).neq(tagName));

    // TODO: For now, we'll modify the query to join and include the task rabbit and tag data here.
    // Eventually, we might consider restructuring things so that this query is constructed
    // elsewhere.
    String joinedQuery =
        Join.left(
                    Metadata.TABLE.as(TR_METADATA_JOIN),
                    Criterion.and(
                        Field.field(TR_METADATA_JOIN + "." + Metadata.KEY.name)
                            .eq(TaskRabbitMetadata.METADATA_KEY), // $NON-NLS-1$
                        Task.ID.eq(Field.field(TR_METADATA_JOIN + "." + Metadata.TASK.name))))
                .toString() //$NON-NLS-1$
            + Join.left(Metadata.TABLE.as(TAGS_METADATA_JOIN), tagsJoinCriterion)
                .toString() //$NON-NLS-1$
            + filter.getSqlQuery();

    sqlQueryTemplate.set(SortHelper.adjustQueryForFlagsAndSort(joinedQuery, sortFlags, sortSort));

    String groupedQuery;
    if (sqlQueryTemplate.get().contains("GROUP BY")) groupedQuery = sqlQueryTemplate.get();
    else if (sqlQueryTemplate.get().contains("ORDER BY")) // $NON-NLS-1$
    groupedQuery =
          sqlQueryTemplate
              .get()
              .replace("ORDER BY", "GROUP BY " + Task.ID + " ORDER BY"); // $NON-NLS-1$
    else groupedQuery = sqlQueryTemplate.get() + " GROUP BY " + Task.ID;
    sqlQueryTemplate.set(groupedQuery);

    // Peform query
    try {
      return taskService.fetchFiltered(sqlQueryTemplate.get(), null, taskProperties());
    } catch (SQLiteException e) {
      // We don't show this error anymore--seems like this can get triggered
      // by a strange bug, but there seems to not be any negative side effect.
      // For now, we'll suppress the error
      // See http://astrid.com/home#tags-7tsoi/task-1119pk
      return null;
    }
  }
예제 #2
0
  private TodorooCursor<Task> constructCursor() {
    String tagName = null;
    if (getActiveTagData() != null) {
      tagName = getActiveTagData().getName();
    }

    Criterion tagsJoinCriterion =
        Criterion.and(
            Field.field(TAGS_METADATA_JOIN + "." + Metadata.KEY.name)
                .eq(TaskToTagMetadata.KEY), // $NON-NLS-1$
            Field.field(TAGS_METADATA_JOIN + "." + Metadata.DELETION_DATE.name).eq(0),
            Task.ID.eq(Field.field(TAGS_METADATA_JOIN + "." + Metadata.TASK.name)));
    if (tagName != null) {
      tagsJoinCriterion =
          Criterion.and(
              tagsJoinCriterion,
              Field.field(TAGS_METADATA_JOIN + "." + TaskToTagMetadata.TAG_NAME.name).neq(tagName));
    }

    // TODO: For now, we'll modify the query to join and include the things like tag data here.
    // Eventually, we might consider restructuring things so that this query is constructed
    // elsewhere.
    String joinedQuery =
        Join.left(Metadata.TABLE.as(TAGS_METADATA_JOIN), tagsJoinCriterion)
                .toString() //$NON-NLS-1$
            + Join.left(
                TaskAttachment.TABLE.as(FILE_METADATA_JOIN),
                Task.UUID.eq(Field.field(FILE_METADATA_JOIN + "." + TaskAttachment.TASK_UUID.name)))
            + filter.getSqlQuery();

    sqlQueryTemplate.set(SortHelper.adjustQueryForFlagsAndSort(joinedQuery, sortFlags, sortSort));

    String groupedQuery;
    if (sqlQueryTemplate.get().contains("GROUP BY")) {
      groupedQuery = sqlQueryTemplate.get();
    } else if (sqlQueryTemplate.get().contains("ORDER BY")) // $NON-NLS-1$
    {
      groupedQuery =
          sqlQueryTemplate
              .get()
              .replace("ORDER BY", "GROUP BY " + Task.ID + " ORDER BY"); // $NON-NLS-1$
    } else {
      groupedQuery = sqlQueryTemplate.get() + " GROUP BY " + Task.ID;
    }
    sqlQueryTemplate.set(groupedQuery);

    // Peform query
    try {
      return taskService.fetchFiltered(sqlQueryTemplate.get(), null, taskProperties());
    } catch (SQLiteException e) {
      // We don't show this error anymore--seems like this can get triggered
      // by a strange bug, but there seems to not be any negative side effect.
      // For now, we'll suppress the error
      // See http://astrid.com/home#tags-7tsoi/task-1119pk
      log.error(e.getMessage(), e);
      return null;
    }
  }
예제 #3
0
 private TodorooCursor<Task> getCursor() {
   String query = getQuery(context);
   return taskService.fetchFiltered(
       query,
       null,
       Task.ID,
       Task.TITLE,
       Task.DUE_DATE,
       Task.COMPLETION_DATE,
       Task.IMPORTANCE,
       Task.RECURRENCE);
 }
예제 #4
0
  /**
   * Select a custom task id in the list. If it doesn't exist, create a new custom filter
   *
   * @param withCustomId
   */
  @SuppressWarnings("nls")
  public void selectCustomId(long withCustomId) {
    // if already in the list, select it
    TodorooCursor<Task> currentCursor = (TodorooCursor<Task>) taskAdapter.getCursor();
    for (int i = 0; i < currentCursor.getCount(); i++) {
      currentCursor.moveToPosition(i);
      if (currentCursor.get(Task.ID) == withCustomId) {
        getListView().setSelection(i);
        return;
      }
    }

    // create a custom cursor
    if (!sqlQueryTemplate.get().contains("WHERE"))
      sqlQueryTemplate.set(sqlQueryTemplate.get() + " WHERE " + TaskCriteria.byId(withCustomId));
    else
      sqlQueryTemplate.set(
          sqlQueryTemplate
              .get()
              .replace("WHERE ", "WHERE " + TaskCriteria.byId(withCustomId) + " OR "));

    currentCursor = taskService.fetchFiltered(sqlQueryTemplate.get(), null, taskProperties());
    getListView().setFilterText("");

    taskAdapter.changeCursor(currentCursor);

    // update title
    if (getActivity() instanceof TaskListActivity)
      ((TaskListActivity) getActivity()).setListsTitle(getString(R.string.TLA_custom));

    // try selecting again
    for (int i = 0; i < currentCursor.getCount(); i++) {
      currentCursor.moveToPosition(i);
      if (currentCursor.get(Task.ID) == withCustomId) {
        getListView().setSelection(i);
        break;
      }
    }
  }
예제 #5
0
  /**
   * Fill in the Task List with current items
   *
   * @param withCustomId force task with given custom id to be part of list
   */
  protected void setUpTaskList() {
    if (filter == null) return;

    // TODO: For now, we'll modify the query to join and include the task rabbit data here.
    // Eventually, we might consider restructuring things so that this query is constructed
    // elsewhere.
    String joinedTaskRabbitQuery =
        Join.left(
                Metadata.TABLE.as(TR_METADATA_JOIN),
                Criterion.and(
                    Field.field(TR_METADATA_JOIN + "." + Metadata.KEY.name)
                        .eq(TaskRabbitMetadata.METADATA_KEY), // $NON-NLS-1$
                    Task.ID.eq(
                        Field.field(TR_METADATA_JOIN) + "." + Metadata.TASK.name))) // $NON-NLS-1$
            + filter.getSqlQuery();

    sqlQueryTemplate.set(
        SortHelper.adjustQueryForFlagsAndSort(joinedTaskRabbitQuery, sortFlags, sortSort));

    // perform query
    TodorooCursor<Task> currentCursor;
    try {
      currentCursor = taskService.fetchFiltered(sqlQueryTemplate.get(), null, taskProperties());
    } catch (SQLiteException e) {
      StartupService.handleSQLiteColumnMissing(getActivity(), e);
      return;
    }

    // set up list adapters
    taskAdapter = createTaskAdapter(currentCursor);

    setListAdapter(taskAdapter);
    getListView().setOnScrollListener(this);
    registerForContextMenu(getListView());

    loadTaskListContent(true);
  }
예제 #6
0
  private void verifyTreeModel(LIST list, Filter filter) {
    boolean changedThings = false;
    Set<String> keySet = idToNode.keySet();
    Set<String> currentIds = new HashSet<>();
    for (String id : keySet) {
      currentIds.add(id);
    }
    Set<String> idsInQuery = new HashSet<>();
    String sql = filter.getSqlQuery().replaceAll("ORDER BY .*", ""); // $NON-NLS-1$//$NON-NLS-2$
    sql = sql + String.format(" ORDER BY %s", Task.CREATION_DATE); // $NON-NLS-1$
    TodorooCursor<Task> tasks = taskService.fetchFiltered(sql, null, Task.UUID);
    try {
      for (tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) {
        String id = tasks.getString(0);
        idsInQuery.add(id);
        if (idToNode.containsKey(id)) {
          continue;
        }

        changedThings = true;
        Node newNode = new Node(id, treeRoot, 0);
        treeRoot.children.add(0, newNode);
        idToNode.put(id, newNode);
      }

      currentIds.removeAll(idsInQuery);
      if (currentIds.size() > 0) {
        removeNodes(currentIds);
        changedThings = true;
      }
    } finally {
      tasks.close();
    }
    if (changedThings) {
      writeSerialization(list, serializeTree(), false);
    }
  }
예제 #7
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;
    }