Ejemplo n.º 1
0
  private void addTags(ArrayList<FilterListItem> list) {
    HashSet<String> tagNames = new HashSet<String>();

    // active tags
    Tag[] myTags =
        tagService.getGroupedTags(
            TagService.GROUPED_TAGS_BY_SIZE,
            Criterion.and(TaskCriteria.ownedByMe(), TaskCriteria.activeAndVisible()));
    for (Tag tag : myTags) tagNames.add(tag.tag);
    if (myTags.length > 0) list.add(filterFromTags(myTags, R.string.tag_FEx_category_mine));

    // find all tag data not in active tag list
    TodorooCursor<TagData> cursor =
        tagDataService.query(
            Query.select(TagData.NAME, TagData.TASK_COUNT, TagData.REMOTE_ID)
                .where(TagData.DELETION_DATE.eq(0)));
    ArrayList<Tag> notListed = new ArrayList<Tag>();
    try {
      ArrayList<Tag> sharedTags = new ArrayList<Tag>();
      for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
        String tagName = cursor.get(TagData.NAME);
        if (tagNames.contains(tagName)) continue;
        Tag tag = new Tag(tagName, cursor.get(TagData.TASK_COUNT), cursor.get(TagData.REMOTE_ID));
        if (tag.count > 0) sharedTags.add(tag);
        else notListed.add(tag);
        tagNames.add(tagName);
      }
      if (sharedTags.size() > 0)
        list.add(
            filterFromTags(
                sharedTags.toArray(new Tag[sharedTags.size()]), R.string.tag_FEx_category_shared));
    } finally {
      cursor.close();
    }

    // find inactive tags, intersect tag list
    Tag[] inactiveTags =
        tagService.getGroupedTags(
            TagService.GROUPED_TAGS_BY_ALPHA,
            Criterion.and(
                TaskCriteria.notDeleted(), Criterion.not(TaskCriteria.activeAndVisible())));
    for (Tag tag : inactiveTags) {
      if (!tagNames.contains(tag.tag) && !TextUtils.isEmpty(tag.tag)) {
        notListed.add(tag);
        tag.count = 0;
      }
    }
    if (notListed.size() > 0)
      list.add(
          filterFromTags(
              notListed.toArray(new Tag[notListed.size()]), R.string.tag_FEx_category_inactive));
  }
Ejemplo n.º 2
0
  /** Create filter from new tag object */
  @SuppressWarnings("nls")
  public static FilterWithCustomIntent filterFromTag(
      Context context, Tag tag, Criterion criterion) {
    String listTitle = tag.tag + " (" + tag.count + ")";
    String title = context.getString(R.string.tag_FEx_name, tag.tag);
    QueryTemplate tagTemplate = tag.queryTemplate(criterion);
    ContentValues contentValues = new ContentValues();
    contentValues.put(Metadata.KEY.name, TagService.KEY);
    contentValues.put(TagService.TAG.name, tag.tag);

    FilterWithCustomIntent filter =
        new FilterWithCustomIntent(listTitle, title, tagTemplate, contentValues);
    if (tag.count == 0) filter.color = Color.GRAY;

    filter.contextMenuLabels =
        new String[] {
          context.getString(R.string.tag_cm_rename), context.getString(R.string.tag_cm_delete)
        };
    filter.contextMenuIntents =
        new Intent[] {
          newTagIntent(context, RenameTagActivity.class, tag),
          newTagIntent(context, DeleteTagActivity.class, tag)
        };
    filter.customTaskList = new ComponentName(ContextManager.getContext(), TagViewActivity.class);
    Bundle extras = new Bundle();
    extras.putString(TagViewActivity.EXTRA_TAG_NAME, tag.tag);
    extras.putLong(TagViewActivity.EXTRA_TAG_REMOTE_ID, tag.remoteId);
    filter.customExtras = extras;

    return filter;
  }