Esempio n. 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();
      }
    }
  }
Esempio n. 2
0
  void saveAndView() {
    String title = filterName.getText().toString().trim();

    if (isEmpty(title)) {
      return;
    }

    StringBuilder sql = new StringBuilder(" WHERE ");
    ContentValues values = new ContentValues();
    for (int i = 0; i < adapter.getCount(); i++) {
      CriterionInstance instance = adapter.getItem(i);
      String value = instance.getValueFromCriterion();
      if (value == null && instance.criterion.sql != null && instance.criterion.sql.contains("?")) {
        value = "";
      }

      switch (instance.type) {
        case CriterionInstance.TYPE_ADD:
          sql.append("OR ");
          break;
        case CriterionInstance.TYPE_SUBTRACT:
          sql.append("AND NOT ");
          break;
        case CriterionInstance.TYPE_INTERSECT:
          sql.append("AND ");
          break;
        case CriterionInstance.TYPE_UNIVERSE:
      }

      // special code for all tasks universe
      if (instance.criterion.sql == null) {
        sql.append(TaskCriteria.activeAndVisible()).append(' ');
      } else {
        String subSql = instance.criterion.sql.replace("?", UnaryCriterion.sanitize(value));
        sql.append(Task.ID).append(" IN (").append(subSql).append(") ");
      }

      if (instance.criterion.valuesForNewTasks != null
          && instance.type == CriterionInstance.TYPE_INTERSECT) {
        for (Entry<String, Object> entry : instance.criterion.valuesForNewTasks.valueSet()) {
          values.put(
              entry.getKey().replace("?", value), entry.getValue().toString().replace("?", value));
        }
      }
    }

    StoreObject storeObject =
        SavedFilter.persist(storeObjectDao, adapter, title, sql.toString(), values);
    Filter filter = new CustomFilter(title, sql.toString(), values, storeObject.getId());
    setResult(RESULT_OK, new Intent().putExtra(TagSettingsActivity.TOKEN_NEW_FILTER, filter));
    finish();
  }
  private Filter[] buildSavedFilters(Context context, Resources r) {
    int themeFlags = ThemeService.getFilterThemeFlags();

    boolean useCustomFilters = Preferences.getBoolean(R.string.p_use_filters, true);
    StoreObjectDao dao = PluginServices.getStoreObjectDao();
    TodorooCursor<StoreObject> cursor = null;
    if (useCustomFilters)
      cursor =
          dao.query(
              Query.select(StoreObject.PROPERTIES)
                  .where(StoreObject.TYPE.eq(SavedFilter.TYPE))
                  .orderBy(Order.asc(SavedFilter.NAME)));
    try {
      Filter[] list;
      if (useCustomFilters && cursor != null) list = new Filter[cursor.getCount() + 3];
      else list = new Filter[3];

      // stock filters
      list[0] = getTodayFilter(r);

      list[1] =
          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);
      list[1].listingIcon =
          ((BitmapDrawable)
                  r.getDrawable(ThemeService.getDrawable(R.drawable.filter_pencil, themeFlags)))
              .getBitmap();

      list[2] = getAssignedByMeFilter(r);

      if (useCustomFilters && cursor != null) {
        StoreObject savedFilter = new StoreObject();
        for (int i = 3; i < list.length; i++) {
          cursor.moveToNext();
          savedFilter.readFromCursor(cursor);
          list[i] = SavedFilter.load(savedFilter);

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

      return list;
    } finally {
      if (cursor != null) cursor.close();
    }
  }