Example #1
0
 /**
  * Build inbox filter
  *
  * @return
  */
 public static Filter buildInboxFilter(Resources r) {
   Filter inbox =
       new Filter(
           r.getString(R.string.BFE_Active),
           r.getString(R.string.BFE_Active),
           new QueryTemplate()
               .where(
                   Criterion.and(
                       TaskCriteria.activeVisibleMine(),
                       Criterion.not(
                           Task.ID.in(
                               Query.select(Metadata.TASK)
                                   .from(Metadata.TABLE)
                                   .where(
                                       Criterion.and(
                                           MetadataCriteria.withKey(TaskToTagMetadata.KEY),
                                           TaskToTagMetadata.TAG_NAME.like(
                                               "x_%", "x"))))))), // $NON-NLS-1$ //$NON-NLS-2$
           null);
   int themeFlags = ThemeService.getFilterThemeFlags();
   inbox.listingIcon =
       ((BitmapDrawable)
               r.getDrawable(ThemeService.getDrawable(R.drawable.filter_inbox, themeFlags)))
           .getBitmap();
   return inbox;
 }
 public static Filter getAssignedByMeFilter(Resources r) {
   int themeFlags = ThemeService.getFilterThemeFlags();
   Filter f =
       new Filter(
           r.getString(R.string.BFE_Assigned),
           r.getString(R.string.BFE_Assigned),
           new QueryTemplate()
               .join(
                   Join.left(
                       Metadata.TABLE,
                       Criterion.and(
                           Metadata.KEY.eq(TaskRabbitMetadata.METADATA_KEY),
                           Task.ID.eq(Metadata.TASK))))
               .where(
                   Criterion.and(
                       TaskCriteria.isActive(),
                       Criterion.or(
                           Task.CREATOR_ID.eq(0),
                           Task.CREATOR_ID.eq(ActFmPreferenceService.userId())),
                       Criterion.or(Task.USER_ID.neq(0), TaskRabbitMetadata.ID.gt(0)))),
           null);
   f.listingIcon =
       ((BitmapDrawable)
               r.getDrawable(ThemeService.getDrawable(R.drawable.filter_assigned, themeFlags)))
           .getBitmap();
   return f;
 }
 public static Filter getTodayFilter(Resources r) {
   int themeFlags = ThemeService.getFilterThemeFlags();
   String todayTitle = AndroidUtilities.capitalize(r.getString(R.string.today));
   ContentValues todayValues = new ContentValues();
   todayValues.put(Task.DUE_DATE.name, PermaSql.VALUE_NOON);
   Filter todayFilter =
       new Filter(
           todayTitle,
           todayTitle,
           new QueryTemplate()
               .where(
                   Criterion.and(
                       TaskCriteria.activeVisibleMine(),
                       Task.DUE_DATE.gt(0),
                       Task.DUE_DATE.lte(PermaSql.VALUE_EOD))),
           todayValues);
   todayFilter.listingIcon =
       ((BitmapDrawable)
               r.getDrawable(ThemeService.getDrawable(R.drawable.filter_calendar, themeFlags)))
           .getBitmap();
   return todayFilter;
 }
  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();
    }
  }