summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/feed
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2013-02-24 10:46:10 +0100
committerdaniel oeh <daniel.oeh@gmail.com>2013-02-24 10:46:10 +0100
commit56f199dc8c69d7e24d0e05613f9911c323cb46a6 (patch)
tree6ef20851c871d7ef4f47d5c75df0a8fb7262eb8b /src/de/danoeh/antennapod/feed
parentcca91b12b9df7c23121b4c01172863ff64d35cfe (diff)
downloadAntennaPod-56f199dc8c69d7e24d0e05613f9911c323cb46a6.zip
Added UserPreferences class, limit access to unreadItems and queue
Diffstat (limited to 'src/de/danoeh/antennapod/feed')
-rw-r--r--src/de/danoeh/antennapod/feed/Feed.java17
-rw-r--r--src/de/danoeh/antennapod/feed/FeedManager.java81
2 files changed, 72 insertions, 26 deletions
diff --git a/src/de/danoeh/antennapod/feed/Feed.java b/src/de/danoeh/antennapod/feed/Feed.java
index 4df9fc43f..ed5d49dbd 100644
--- a/src/de/danoeh/antennapod/feed/Feed.java
+++ b/src/de/danoeh/antennapod/feed/Feed.java
@@ -7,6 +7,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
import android.preference.PreferenceManager;
import de.danoeh.antennapod.PodcastApp;
+import de.danoeh.antennapod.preferences.UserPreferences;
/**
* Data Object for a whole feed
@@ -68,13 +69,9 @@ public class Feed extends FeedFile {
* */
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.getState() == FeedItem.State.NEW) {
- if (!displayOnlyEpisodes || item.getMedia() != null) {
+ if (!UserPreferences.isDisplayOnlyEpisodes() || item.getMedia() != null) {
count++;
}
}
@@ -105,12 +102,9 @@ public class Feed extends FeedFile {
* only count items with episodes.
*/
public boolean hasNewItems() {
- boolean displayOnlyEpisodes = PreferenceManager
- .getDefaultSharedPreferences(PodcastApp.getInstance())
- .getBoolean(PodcastApp.PREF_DISPLAY_ONLY_EPISODES, false);
for (FeedItem item : items) {
if (item.getState() == FeedItem.State.NEW) {
- if (!displayOnlyEpisodes || item.getMedia() != null) {
+ if (!UserPreferences.isDisplayOnlyEpisodes() || item.getMedia() != null) {
return true;
}
}
@@ -125,11 +119,8 @@ public class Feed extends FeedFile {
* */
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) {
+ if (!UserPreferences.isDisplayOnlyEpisodes() || item.getMedia() != null) {
count++;
}
}
diff --git a/src/de/danoeh/antennapod/feed/FeedManager.java b/src/de/danoeh/antennapod/feed/FeedManager.java
index 6c3471e5c..6a8ed9b6e 100644
--- a/src/de/danoeh/antennapod/feed/FeedManager.java
+++ b/src/de/danoeh/antennapod/feed/FeedManager.java
@@ -21,11 +21,13 @@ import android.util.Log;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.asynctask.DownloadStatus;
+import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.service.PlaybackService;
import de.danoeh.antennapod.storage.DownloadRequestException;
import de.danoeh.antennapod.storage.DownloadRequester;
import de.danoeh.antennapod.storage.PodDBAdapter;
import de.danoeh.antennapod.util.DownloadError;
+import de.danoeh.antennapod.util.EpisodeFilter;
import de.danoeh.antennapod.util.FeedtitleComparator;
import de.danoeh.antennapod.util.comparator.DownloadStatusComparator;
import de.danoeh.antennapod.util.comparator.FeedItemPubdateComparator;
@@ -591,9 +593,6 @@ public class FeedManager {
public void downloadFeedItem(final Context context, FeedItem... items)
throws DownloadRequestException {
- boolean autoQueue = PreferenceManager.getDefaultSharedPreferences(
- context.getApplicationContext()).getBoolean(
- PodcastApp.PREF_AUTO_QUEUE, true);
List<FeedItem> addToQueue = new ArrayList<FeedItem>();
for (FeedItem item : items) {
@@ -618,7 +617,7 @@ public class FeedManager {
addToQueue.add(item);
}
}
- if (autoQueue) {
+ if (UserPreferences.isAutoQueue()) {
addQueueItem(context,
addToQueue.toArray(new FeedItem[addToQueue.size()]));
}
@@ -732,9 +731,7 @@ public class FeedManager {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context
.getApplicationContext());
- boolean autoDelete = prefs.getBoolean(PodcastApp.PREF_AUTO_DELETE,
- false);
- if (autoDelete) {
+ if (UserPreferences.isAutoDelete()) {
long lastPlayedId = prefs.getLong(
PlaybackService.PREF_LAST_PLAYED_ID, -1);
long autoDeleteId = prefs.getLong(
@@ -1479,16 +1476,74 @@ public class FeedManager {
return feeds;
}
- public List<FeedItem> getUnreadItems() {
- return unreadItems;
+ /**
+ * Returns the number of items that are currently in the queue.
+ *
+ * @param enableEpisodeFilter
+ * true if items without episodes should be ignored by this
+ * method if the episode filter was enabled by the user.
+ * */
+ public int getQueueSize(boolean enableEpisodeFilter) {
+ if (UserPreferences.isDisplayOnlyEpisodes() && enableEpisodeFilter) {
+ return EpisodeFilter.countItemsWithEpisodes(queue);
+ } else {
+ return queue.size();
+ }
}
- public ArrayList<DownloadStatus> getDownloadLog() {
- return downloadLog;
+ /**
+ * Returns the FeedItem at the specified index of the queue.
+ *
+ * @param enableEpisodeFilter
+ * true if items without episodes should be ignored by this
+ * method if the episode filter was enabled by the user.
+ *
+ * @throws IndexOutOfBoundsException
+ * if index is out of range
+ * */
+ public FeedItem getQueueItemAtIndex(int index, boolean enableEpisodeFilter) {
+ if (UserPreferences.isDisplayOnlyEpisodes() && enableEpisodeFilter) {
+ return EpisodeFilter.accessEpisodeByIndex(queue, index);
+ } else {
+ return queue.get(index);
+ }
+ }
+
+ /**
+ * Returns the number of unread items.
+ *
+ * @param enableEpisodeFilter
+ * true if items without episodes should be ignored by this
+ * method if the episode filter was enabled by the user.
+ * */
+ public int getUnreadItemsSize(boolean enableEpisodeFilter) {
+ if (UserPreferences.isDisplayOnlyEpisodes() && enableEpisodeFilter) {
+ return EpisodeFilter.countItemsWithEpisodes(unreadItems);
+ } else {
+ return unreadItems.size();
+ }
}
- public List<FeedItem> getQueue() {
- return queue;
+ /**
+ * Returns the FeedItem at the specified index of the unread items list.
+ *
+ * @param enableEpisodeFilter
+ * true if items without episodes should be ignored by this
+ * method if the episode filter was enabled by the user.
+ *
+ * @throws IndexOutOfBoundsException
+ * if index is out of range
+ * */
+ public FeedItem getUnreadItemAtIndex(int index, boolean enableEpisodeFilter) {
+ if (UserPreferences.isDisplayOnlyEpisodes() && enableEpisodeFilter) {
+ return EpisodeFilter.accessEpisodeByIndex(unreadItems, index);
+ } else {
+ return unreadItems.get(index);
+ }
+ }
+
+ public ArrayList<DownloadStatus> getDownloadLog() {
+ return downloadLog;
}
public List<FeedItem> getPlaybackHistory() {