Example #1
1
  @Override
  public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    StringBuilder selection = new StringBuilder();

    // create temporary copies
    final boolean isFilterFavorites = mIsFilterFavorites;
    final boolean isFilterUnwatched = mIsFilterUnwatched;
    final boolean isFilterUpcoming = mIsFilterUpcoming;
    final boolean isFilterHidden = mIsFilterHidden;

    // restrict to favorites?
    if (isFilterFavorites) {
      selection.append(Shows.FAVORITE).append("=1");
    }

    final long timeInAnHour = System.currentTimeMillis() + DateUtils.HOUR_IN_MILLIS;

    // restrict to shows with a next episode?
    if (isFilterUnwatched) {
      if (selection.length() != 0) {
        selection.append(" AND ");
      }
      selection.append(Shows.NEXTAIRDATEMS).append("!=").append(DBUtils.UNKNOWN_NEXT_AIR_DATE);

      // exclude shows with upcoming next episode
      if (!isFilterUpcoming) {
        selection.append(" AND ").append(Shows.NEXTAIRDATEMS).append("<=").append(timeInAnHour);
      }
    }
    // restrict to shows with an upcoming (yet to air) next episode?
    if (isFilterUpcoming) {
      if (selection.length() != 0) {
        selection.append(" AND ");
      }
      // Display shows upcoming within <limit> days + 1 hour
      int upcomingLimitInDays = AdvancedSettings.getUpcomingLimitInDays(getActivity());
      long latestAirtime = timeInAnHour + upcomingLimitInDays * DateUtils.DAY_IN_MILLIS;

      selection.append(Shows.NEXTAIRDATEMS).append("<=").append(latestAirtime);

      // exclude shows with no upcoming next episode if not filtered for unwatched, too
      if (!isFilterUnwatched) {
        selection.append(" AND ").append(Shows.NEXTAIRDATEMS).append(">=").append(timeInAnHour);
      }
    }

    // special: if hidden filter is disabled, exclude hidden shows
    if (selection.length() != 0) {
      selection.append(" AND ");
    }
    selection.append(Shows.HIDDEN).append(isFilterHidden ? "=1" : "=0");

    return new CursorLoader(
        getActivity(),
        Shows.CONTENT_URI,
        ShowsQuery.PROJECTION,
        selection.toString(),
        null,
        ShowsDistillationSettings.getSortQuery(mSortOrderId, mIsSortFavoritesFirst));
  }
Example #2
0
  private void getSortAndFilterSettings() {
    mIsFilterFavorites = ShowsDistillationSettings.isFilteringFavorites(getActivity());
    mIsFilterUnwatched = ShowsDistillationSettings.isFilteringUnwatched(getActivity());
    mIsFilterUpcoming = ShowsDistillationSettings.isFilteringUpcoming(getActivity());
    mIsFilterHidden = ShowsDistillationSettings.isFilteringHidden(getActivity());

    mSortOrderId = ShowsDistillationSettings.getSortOrderId(getActivity());
    mIsSortFavoritesFirst = ShowsDistillationSettings.isSortFavoritesFirst(getActivity());
  }