From 7fbd96ad45cf5e1fe9ad023491254c0bc68989d9 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Sun, 7 Apr 2013 11:34:34 +0200 Subject: [PATCH] Position of playing queue item can now be changed --- .../activity/OrganizeQueueActivity.java | 19 ++--------- .../danoeh/antennapod/feed/FeedManager.java | 33 ++++++++++--------- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java b/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java index 65225a584..89001f7f5 100644 --- a/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java +++ b/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java @@ -72,10 +72,7 @@ public class OrganizeQueueActivity extends SherlockListActivity { @Override public void drop(int from, int to) { FeedManager manager = FeedManager.getInstance(); - int offset = (manager.firstQueueItemIsPlaying()) ? 1 : 0; - - manager.moveQueueItem(OrganizeQueueActivity.this, from + offset, to - + offset, false); + manager.moveQueueItem(OrganizeQueueActivity.this, from, to, false); adapter.notifyDataSetChanged(); } }; @@ -85,7 +82,6 @@ public class OrganizeQueueActivity extends SherlockListActivity { @Override public void remove(int which) { FeedManager manager = FeedManager.getInstance(); - manager.removeQueueItem(OrganizeQueueActivity.this, (FeedItem) getListAdapter().getItem(which)); } @@ -174,21 +170,12 @@ public class OrganizeQueueActivity extends SherlockListActivity { @Override public int getCount() { int queueSize = manager.getQueueSize(true); - if (manager.firstQueueItemIsPlaying()) { - return queueSize - 1; - } else { - return queueSize; - } + return queueSize; } @Override public FeedItem getItem(int position) { - if (manager.firstQueueItemIsPlaying() && position < getCount()) { - return manager.getQueueItemAtIndex(position + 1, true); - } else { - return manager.getQueueItemAtIndex(position, true); - } - + return manager.getQueueItemAtIndex(position, true); } @Override diff --git a/src/de/danoeh/antennapod/feed/FeedManager.java b/src/de/danoeh/antennapod/feed/FeedManager.java index d679e4dfa..bdffdc667 100644 --- a/src/de/danoeh/antennapod/feed/FeedManager.java +++ b/src/de/danoeh/antennapod/feed/FeedManager.java @@ -117,8 +117,8 @@ public class FeedManager { /** * Play FeedMedia and start the playback service + launch Mediaplayer - * Activity. The FeedItem belonging to the media is moved to the top of the - * queue. + * Activity. The FeedItem will be added at the top of the queue if it isn't + * in there yet. * * @param context * for starting the playbackservice @@ -156,9 +156,7 @@ public class FeedManager { context.startActivity(PlaybackService.getPlayerActivityIntent( context, media)); } - if (queue.contains(media.getItem())) { - moveQueueItem(context, queue.indexOf(media.getItem()), 0, true); - } else { + if (!queue.contains(media.getItem())) { addQueueItemAt(context, media.getItem(), 0, false); } } catch (MediaFileNotFoundException e) { @@ -1630,10 +1628,10 @@ public class FeedManager { if (AppConfig.DEBUG) Log.d(TAG, "Extracting Queue"); Cursor cursor = adapter.getQueueCursor(); - + // Sort cursor results by ID with TreeMap TreeMap map = new TreeMap(); - + if (cursor.moveToFirst()) { do { int index = cursor.getInt(PodDBAdapter.KEY_ID_INDEX); @@ -1650,7 +1648,7 @@ public class FeedManager { } while (cursor.moveToNext()); } cursor.close(); - + for (Map.Entry entry : map.entrySet()) { FeedItem item = entry.getValue(); queue.add(item); @@ -1797,18 +1795,23 @@ public class FeedManager { } /** - * Returns true if the first item in the queue is currently being played or - * false otherwise. If the queue is empty, this method will also return - * false. + * Returns the index of the episode that is currently being played in the + * queue or -1 if the queue is empty or no episode in the queue is being + * played. * */ - public boolean firstQueueItemIsPlaying() { + public int getQueuePlayingEpisodeIndex() { FeedManager manager = FeedManager.getInstance(); int queueSize = manager.getQueueSize(true); if (queueSize == 0) { - return false; + return -1; } else { - FeedItem item = getQueueItemAtIndex(0, true); - return item.getState() == FeedItem.State.PLAYING; + for (int x = 0; x < queueSize; x++) { + FeedItem item = getQueueItemAtIndex(x, true); + if (item.getState() == FeedItem.State.PLAYING) { + return x; + } + } + return -1; } }