Position of playing queue item can now be changed

This commit is contained in:
daniel oeh 2013-04-07 11:34:34 +02:00
parent 05a525876d
commit 7fbd96ad45
2 changed files with 21 additions and 31 deletions

View File

@ -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

View File

@ -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) {
@ -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;
}
}