diff --git a/res/values/translatable.xml b/res/values/translatable.xml index 061fcfdb..b5291f0a 100644 --- a/res/values/translatable.xml +++ b/res/values/translatable.xml @@ -60,6 +60,7 @@ THE SOFTWARE. Enqueue + Play Next Play Edit Rename diff --git a/src/ch/blinkenlights/android/vanilla/LibraryActivity.java b/src/ch/blinkenlights/android/vanilla/LibraryActivity.java index 1a7728ac..8e0b4a23 100644 --- a/src/ch/blinkenlights/android/vanilla/LibraryActivity.java +++ b/src/ch/blinkenlights/android/vanilla/LibraryActivity.java @@ -104,12 +104,17 @@ public class LibraryActivity * Action for row click: expand the row. */ public static final int ACTION_EXPAND = 6; + /** + * Action for row click: queue selection as next item + */ + public static final int ACTION_ENQUEUE_AS_NEXT = 7; /** * The SongTimeline add song modes corresponding to each relevant action. */ private static final int[] modeForAction = { SongTimeline.MODE_PLAY, SongTimeline.MODE_ENQUEUE, -1, - SongTimeline.MODE_PLAY_ID_FIRST, SongTimeline.MODE_ENQUEUE_ID_FIRST }; + SongTimeline.MODE_PLAY_ID_FIRST, SongTimeline.MODE_ENQUEUE_ID_FIRST, + -1, -1, SongTimeline.MODE_ENQUEUE_AS_NEXT }; private static final String SEARCH_BOX_VISIBLE = "search_box_visible"; @@ -647,9 +652,10 @@ public class LibraryActivity private static final int MENU_PLAY = 0; private static final int MENU_ENQUEUE = 1; private static final int MENU_EXPAND = 2; - private static final int MENU_ADD_TO_PLAYLIST = 3; - private static final int MENU_NEW_PLAYLIST = 4; - private static final int MENU_DELETE = 5; + private static final int MENU_ENQUEUE_AS_NEXT = 3; + private static final int MENU_ADD_TO_PLAYLIST = 4; + private static final int MENU_NEW_PLAYLIST = 5; + private static final int MENU_DELETE = 6; private static final int MENU_RENAME_PLAYLIST = 7; private static final int MENU_SELECT_PLAYLIST = 8; private static final int MENU_PLAY_ALL = 9; @@ -675,6 +681,7 @@ public class LibraryActivity menu.setHeaderTitle(rowData.getStringExtra(LibraryAdapter.DATA_TITLE)); menu.add(0, MENU_PLAY, 0, R.string.play).setIntent(rowData); + menu.add(0, MENU_ENQUEUE_AS_NEXT, 0, R.string.enqueue_as_next).setIntent(rowData); menu.add(0, MENU_ENQUEUE, 0, R.string.enqueue).setIntent(rowData); if (type == MediaUtils.TYPE_PLAYLIST) { menu.add(0, MENU_RENAME_PLAYLIST, 0, R.string.rename).setIntent(rowData); @@ -729,6 +736,9 @@ public class LibraryActivity case MENU_ENQUEUE_ALL: pickSongs(intent, ACTION_ENQUEUE_ALL); break; + case MENU_ENQUEUE_AS_NEXT: + pickSongs(intent, ACTION_ENQUEUE_AS_NEXT); + break; case MENU_NEW_PLAYLIST: { PlaylistTask playlistTask = new PlaylistTask(-1, null); playlistTask.query = buildQueryFromIntent(intent, true, false); diff --git a/src/ch/blinkenlights/android/vanilla/PlaybackService.java b/src/ch/blinkenlights/android/vanilla/PlaybackService.java index 662548f8..66c5d211 100644 --- a/src/ch/blinkenlights/android/vanilla/PlaybackService.java +++ b/src/ch/blinkenlights/android/vanilla/PlaybackService.java @@ -1572,6 +1572,7 @@ public final class PlaybackService extends Service case SongTimeline.MODE_ENQUEUE: case SongTimeline.MODE_ENQUEUE_ID_FIRST: case SongTimeline.MODE_ENQUEUE_POS_FIRST: + case SongTimeline.MODE_ENQUEUE_AS_NEXT: text = R.plurals.enqueued; break; default: diff --git a/src/ch/blinkenlights/android/vanilla/SongTimeline.java b/src/ch/blinkenlights/android/vanilla/SongTimeline.java index f097ddeb..30844185 100644 --- a/src/ch/blinkenlights/android/vanilla/SongTimeline.java +++ b/src/ch/blinkenlights/android/vanilla/SongTimeline.java @@ -145,6 +145,14 @@ public final class SongTimeline { * @see SongTimeline#addSongs(Context, QueryTask) */ public static final int MODE_ENQUEUE_POS_FIRST = 6; + /** + * Enqueues the result as next item(s) + * + * Pass the position in QueryTask.data. + * + * @see SongTimeline#addSongs(Context, QueryTask) + */ + public static final int MODE_ENQUEUE_AS_NEXT = 7; /** * Disable shuffle. @@ -657,6 +665,7 @@ public final class SongTimeline { case MODE_ENQUEUE: case MODE_ENQUEUE_POS_FIRST: case MODE_ENQUEUE_ID_FIRST: + case MODE_ENQUEUE_AS_NEXT: if (mFinishAction == FINISH_RANDOM) { int j = timeline.size(); while (--j > mCurrentPos) { @@ -681,11 +690,21 @@ public final class SongTimeline { int start = timeline.size(); Song jumpSong = null; + int addAtPos = mCurrentPos + 1; + + /* Check if addAtPos is out-of-bounds OR if + * the request does not want to work at the current + * playlist position anyway + */ + if (addAtPos > start || mode != MODE_ENQUEUE_AS_NEXT) { + addAtPos = start; + } + for (int j = 0; j != count; ++j) { cursor.moveToPosition(j); Song song = new Song(-1); song.populate(cursor); - timeline.add(song); + timeline.add(addAtPos++, song); if (jumpSong == null) { if ((mode == MODE_PLAY_POS_FIRST || mode == MODE_ENQUEUE_POS_FIRST) && j == data) {