From 18e4625e9a3596f4801122013b3030b037376d4b Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Fri, 10 Aug 2012 14:59:42 +0200 Subject: [PATCH] Implemented episode filter --- .../antennapod/adapter/FeedlistAdapter.java | 2 +- src/de/danoeh/antennapod/feed/Feed.java | 44 ++++++++++++++++--- .../antennapod/fragment/ItemlistFragment.java | 11 +++++ .../danoeh/antennapod/util/EpisodeFilter.java | 23 ++++++++++ 4 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 src/de/danoeh/antennapod/util/EpisodeFilter.java diff --git a/src/de/danoeh/antennapod/adapter/FeedlistAdapter.java b/src/de/danoeh/antennapod/adapter/FeedlistAdapter.java index b333ff125..6f72d9e70 100644 --- a/src/de/danoeh/antennapod/adapter/FeedlistAdapter.java +++ b/src/de/danoeh/antennapod/adapter/FeedlistAdapter.java @@ -82,7 +82,7 @@ public class FeedlistAdapter extends ArrayAdapter { .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(); diff --git a/src/de/danoeh/antennapod/feed/Feed.java b/src/de/danoeh/antennapod/feed/Feed.java index 9c4e7e75c..0a32f3e75 100644 --- a/src/de/danoeh/antennapod/feed/Feed.java +++ b/src/de/danoeh/antennapod/feed/Feed.java @@ -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 * @@ -12,7 +16,7 @@ import java.util.Date; public class Feed extends FeedFile { public static final String TYPE_RSS2 = "rss"; public static final String TYPE_ATOM1 = "atom"; - + private String title; /** Link to the website. */ private String link; @@ -39,14 +43,42 @@ public class Feed extends FeedFile { this(lastUpdate); 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++; - } + } } return count; } @@ -106,7 +138,7 @@ public class Feed extends FeedFile { public void setLastUpdate(Date lastUpdate) { this.lastUpdate = lastUpdate; } - + public String getPaymentLink() { return paymentLink; } @@ -138,7 +170,5 @@ public class Feed extends FeedFile { public void setType(String type) { this.type = type; } - - } diff --git a/src/de/danoeh/antennapod/fragment/ItemlistFragment.java b/src/de/danoeh/antennapod/fragment/ItemlistFragment.java index de1a5cb4f..ba810507d 100644 --- a/src/de/danoeh/antennapod/fragment/ItemlistFragment.java +++ b/src/de/danoeh/antennapod/fragment/ItemlistFragment.java @@ -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); diff --git a/src/de/danoeh/antennapod/util/EpisodeFilter.java b/src/de/danoeh/antennapod/util/EpisodeFilter.java new file mode 100644 index 000000000..debfa926c --- /dev/null +++ b/src/de/danoeh/antennapod/util/EpisodeFilter.java @@ -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 getEpisodeList(List items) { + ArrayList episodes = new ArrayList(items); + for (FeedItem item : items) { + if (item.getMedia() == null) { + episodes.remove(item); + } + } + return episodes; + } +}