Exemplo 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));
  }
Exemplo n.º 2
0
  @Override
  protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    synchronized (this) {
      if (dataLoaded) return;
      dataLoaded = true;
    }

    String tag = getIntent().getStringExtra(EXTRA_TAG_NAME);
    long remoteId = getIntent().getLongExtra(EXTRA_TAG_REMOTE_ID, 0);

    if (tag == null && remoteId == 0) return;

    TodorooCursor<TagData> cursor =
        tagDataService.query(
            Query.select(TagData.PROPERTIES)
                .where(
                    Criterion.or(
                        TagData.NAME.eq(tag),
                        Criterion.and(TagData.REMOTE_ID.gt(0), TagData.REMOTE_ID.eq(remoteId)))));
    try {
      tagData = new TagData();
      if (cursor.getCount() == 0) {
        tagData.setValue(TagData.NAME, tag);
        tagData.setValue(TagData.REMOTE_ID, remoteId);
        tagDataService.save(tagData);
      } else {
        cursor.moveToFirst();
        tagData.readFromCursor(cursor);
      }
    } finally {
      cursor.close();
    }

    String fetchKey = LAST_FETCH_KEY + tagData.getId();
    long lastFetchDate = Preferences.getLong(fetchKey, 0);
    if (DateUtilities.now() > lastFetchDate + 300000L) {
      refreshData(false, false);
      Preferences.setLong(fetchKey, DateUtilities.now());
    }

    setUpUpdateList();
    setUpMemberPage();
  }