From 8f9344fbe74a6922f949ddffbc1779f539fcef3f Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Wed, 20 Jun 2012 16:02:05 +0200 Subject: Implemented Queue for FeedItems --- src/de/podfetcher/feed/FeedManager.java | 38 ++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/de/podfetcher/feed') diff --git a/src/de/podfetcher/feed/FeedManager.java b/src/de/podfetcher/feed/FeedManager.java index cdcde55c8..506b62efc 100644 --- a/src/de/podfetcher/feed/FeedManager.java +++ b/src/de/podfetcher/feed/FeedManager.java @@ -34,6 +34,9 @@ public class FeedManager { /** Contains completed Download status entries */ private ArrayList downloadLog; + + /** Contains the queue of items to be played. */ + private ArrayList queue; private DownloadRequester requester; @@ -43,6 +46,7 @@ public class FeedManager { unreadItems = new ArrayList(); requester = DownloadRequester.getInstance(); downloadLog = new ArrayList(); + queue = new ArrayList(); } public static FeedManager getInstance() { @@ -141,6 +145,24 @@ public class FeedManager { } return adapter.setDownloadStatus(status); } + + public void addQueueItem(Context context, FeedItem item) { + PodDBAdapter adapter = new PodDBAdapter(context); + queue.add(item); + adapter.setQueue(queue); + } + + public void removeQueueItem(Context context, FeedItem item) { + boolean removed = queue.remove(item); + if (removed) { + PodDBAdapter adapter = new PodDBAdapter(context); + adapter.setQueue(queue); + } + } + + public boolean isInQueue(FeedItem item) { + return queue.contains(item); + } private void addNewFeed(Context context, Feed feed) { feeds.add(feed); @@ -300,7 +322,6 @@ public class FeedManager { /** Reads the database */ public void loadDBData(Context context) { - PodDBAdapter adapter = new PodDBAdapter(context); updateArrays(context); } @@ -309,6 +330,7 @@ public class FeedManager { categories.clear(); extractFeedlistFromCursor(context); extractDownloadLogFromCursor(context); + extractQueueFromCursor(context); } private void extractFeedlistFromCursor(Context context) { @@ -423,6 +445,20 @@ public class FeedManager { } while (logCursor.moveToNext()); } } + + private void extractQueueFromCursor(Context context) { + PodDBAdapter adapter = new PodDBAdapter(context); + adapter.open(); + Cursor cursor = adapter.getQueueCursor(); + if (cursor.moveToFirst()) { + do { + int index = cursor.getInt(cursor.getColumnIndex(PodDBAdapter.KEY_ID)); + Feed feed = getFeed(cursor.getColumnIndex(PodDBAdapter.KEY_FEED)); + FeedItem item = getFeedItem(cursor.getColumnIndex(PodDBAdapter.KEY_FEEDITEM), feed); + queue.add(index, item); + } while (cursor.moveToNext()); + } + } public ArrayList getFeeds() { return feeds; -- cgit v1.2.3