Example #1
0
  private Filter[] buildSavedFilters(Context context, Resources r) {
    int themeFlags = ThemeService.getFilterThemeFlags();

    StoreObjectDao dao = PluginServices.getStoreObjectDao();
    TodorooCursor<StoreObject> cursor =
        dao.query(
            Query.select(StoreObject.PROPERTIES)
                .where(StoreObject.TYPE.eq(SavedFilter.TYPE))
                .orderBy(Order.asc(SavedFilter.NAME)));
    try {
      ArrayList<Filter> list = new ArrayList<>();

      // stock filters
      if (Preferences.getBoolean(R.string.p_show_recently_modified_filter, true)) {
        Filter recent =
            new Filter(
                r.getString(R.string.BFE_Recent),
                r.getString(R.string.BFE_Recent),
                new QueryTemplate()
                    .where(TaskCriteria.ownedByMe())
                    .orderBy(Order.desc(Task.MODIFICATION_DATE))
                    .limit(15),
                null);
        recent.listingIcon =
            ((BitmapDrawable)
                    r.getDrawable(ThemeService.getDrawable(R.drawable.filter_pencil, themeFlags)))
                .getBitmap();

        list.add(recent);
      }

      if (cursor != null) {
        StoreObject savedFilter = new StoreObject();
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
          savedFilter.readFromCursor(cursor);
          Filter f = SavedFilter.load(savedFilter);

          Intent deleteIntent = new Intent(context, DeleteActivity.class);
          deleteIntent.putExtra(TOKEN_FILTER_ID, savedFilter.getId());
          deleteIntent.putExtra(TOKEN_FILTER_NAME, f.title);
          f.contextMenuLabels = new String[] {context.getString(R.string.BFE_Saved_delete)};
          f.contextMenuIntents = new Intent[] {deleteIntent};
          f.listingIcon =
              ((BitmapDrawable)
                      r.getDrawable(
                          ThemeService.getDrawable(R.drawable.filter_sliders, themeFlags)))
                  .getBitmap();
          list.add(f);
        }
      }

      return list.toArray(new Filter[list.size()]);
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }
  }
Example #2
0
 /**
  * Gets a listing of all tasks that are active &
  *
  * @param properties
  * @return todoroo cursor. PLEASE CLOSE THIS CURSOR!
  */
 private TodorooCursor<Task> getTasksWithReminders(Property<?>... properties) {
   return taskDao.query(
       Query.select(properties)
           .where(
               Criterion.and(
                   TaskCriteria.isActive(),
                   TaskCriteria.ownedByMe(),
                   Criterion.or(Task.REMINDER_FLAGS.gt(0), Task.REMINDER_PERIOD.gt(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));
  }