Implemented episode filter

This commit is contained in:
daniel oeh 2012-08-10 14:59:42 +02:00
parent d3d2debfb6
commit 18e4625e9a
4 changed files with 72 additions and 8 deletions

View File

@ -82,7 +82,7 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
.getTime(), System.currentTimeMillis(),
DateFormat.SHORT, DateFormat.SHORT));
}
holder.numberOfEpisodes.setText(feed.getItems().size()
holder.numberOfEpisodes.setText(feed.getNumOfItems()
+ convertView.getResources()
.getString(R.string.episodes_suffix));
int newItems = feed.getNumOfNewItems();

View File

@ -3,6 +3,10 @@ package de.danoeh.antennapod.feed;
import java.util.ArrayList;
import java.util.Date;
import de.danoeh.antennapod.PodcastApp;
import android.preference.PreferenceManager;
/**
* Data Object for a whole feed
*
@ -40,11 +44,39 @@ public class Feed extends FeedFile {
this.download_url = url;
}
/** Returns the number of FeedItems where 'read' is false. */
/**
* Returns the number of FeedItems where 'read' is false. If the 'display
* only episodes' - preference is set to true, this method will only count
* items with episodes.
* */
public int getNumOfNewItems() {
int count = 0;
boolean displayOnlyEpisodes = PreferenceManager
.getDefaultSharedPreferences(PodcastApp.getInstance())
.getBoolean(PodcastApp.PREF_DISPLAY_ONLY_EPISODES, false);
for (FeedItem item : items) {
if (!item.isRead()) {
if (!displayOnlyEpisodes || item.getMedia() != null) {
count++;
}
}
}
return count;
}
/**
* Returns the number of FeedItems. If the 'display only episodes' -
* preference is set to true, this method will only count items with
* episodes.
* */
public int getNumOfItems() {
int count = 0;
boolean displayOnlyEpisodes = PreferenceManager
.getDefaultSharedPreferences(PodcastApp.getInstance())
.getBoolean(PodcastApp.PREF_DISPLAY_ONLY_EPISODES, false);
for (FeedItem item : items) {
if (!displayOnlyEpisodes || item.getMedia() != null) {
count++;
}
}
@ -139,6 +171,4 @@ public class Feed extends FeedFile {
this.type = type;
}
}

View File

@ -8,6 +8,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@ -28,8 +29,10 @@ import de.danoeh.antennapod.feed.FeedItem;
import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.service.DownloadService;
import de.danoeh.antennapod.storage.DownloadRequester;
import de.danoeh.antennapod.util.EpisodeFilter;
import de.danoeh.antennapod.util.menuhandler.FeedItemMenuHandler;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.R;
/** Displays a list of FeedItems. */
@ -99,6 +102,14 @@ public class ItemlistFragment extends SherlockListFragment implements
feed = FeedManager.getInstance().getFeed(feedId);
items = feed.getItems();
}
boolean displayOnlyEpisodes = PreferenceManager
.getDefaultSharedPreferences(PodcastApp.getInstance())
.getBoolean(PodcastApp.PREF_DISPLAY_ONLY_EPISODES, false);
if (displayOnlyEpisodes) {
items = EpisodeFilter.getEpisodeList(items);
}
fila = new FeedItemlistAdapter(getActivity(), 0, items,
onButActionClicked, showFeedtitle);
setListAdapter(fila);

View File

@ -0,0 +1,23 @@
package de.danoeh.antennapod.util;
import java.util.ArrayList;
import java.util.List;
import de.danoeh.antennapod.feed.FeedItem;
public class EpisodeFilter {
private EpisodeFilter() {
}
/** Return a copy of the itemlist without items which have no media. */
public static ArrayList<FeedItem> getEpisodeList(List<FeedItem> items) {
ArrayList<FeedItem> episodes = new ArrayList<FeedItem>(items);
for (FeedItem item : items) {
if (item.getMedia() == null) {
episodes.remove(item);
}
}
return episodes;
}
}