From c7ebdf8b24ee101f813479582f6aa4b31d748eef Mon Sep 17 00:00:00 2001 From: snoopy Date: Sun, 23 Sep 2012 11:31:36 +0200 Subject: [PATCH] Add "auto queue album" option: When playing a song (or queuing one when playlist is empty), if the song belong to an album, play the whole album, starting with the selected song. --- res/xml/preferences.xml | 6 ++ .../android/remote/business/MusicManager.java | 6 +- .../controller/SongListController.java | 96 ++++++++++--------- 3 files changed, 62 insertions(+), 46 deletions(-) diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 11ccac36..cba3c47c 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -103,6 +103,12 @@ android:entries="@array/SelectionPreferenceEntries" android:entryValues="@array/SelectionPreferenceValues" android:defaultValue="0" /> + response, final Song song, final Context context) { mHandler.post(new Command(response, this) { - public void doRun() throws Exception{ + public void doRun() throws Exception{ + final IMusicClient mc = music(context); + final IControlClient cc = control(context); + final int numAlreadyQueued = mc.getPlaylistSize(MusicManager.this); response.value = music(context).addToPlaylist(MusicManager.this, song); + checkForPlayAfterQueue(mc, cc, numAlreadyQueued); } }); } diff --git a/src/org/xbmc/android/remote/presentation/controller/SongListController.java b/src/org/xbmc/android/remote/presentation/controller/SongListController.java index 5de3788e..9fc116d1 100644 --- a/src/org/xbmc/android/remote/presentation/controller/SongListController.java +++ b/src/org/xbmc/android/remote/presentation/controller/SongListController.java @@ -79,6 +79,8 @@ public class SongListController extends ListController implements IController { private static final String PREF_DEFAULT_SELECTION_ACTION = "setting_default_selection_action"; private static final String DEFAULT_ACTION_PLAY = "0"; + private static final String PREF_AUTO_QUEUE_ALBUM = "setting_auto_queue_album"; + private static final int INT_DEFAULT_ACTION_PLAY = 0; private static final int INT_DEFAULT_ACTION_QUEUE = 1; @@ -124,31 +126,10 @@ public void onItemClick(AdapterView parent, View view, int position, long id) final int SelectionType = Integer.parseInt(prefs.getString(PREF_DEFAULT_SELECTION_ACTION, DEFAULT_ACTION_PLAY)); switch (SelectionType) { case INT_DEFAULT_ACTION_PLAY: - if (mAlbum == null) { - mMusicManager.play(new QueryResponse( - mActivity, - "Playing \"" + song.title + "\" by " + song.artist + "...", - "Error playing song!", - true - ), song, mActivity.getApplicationContext()); - } else { - mMusicManager.play(new QueryResponse( - mActivity, - "Playing album \"" + song.album + "\" starting with song \"" + song.title + "\" by " + song.artist + "...", - "Error playing song!", - true - ), mAlbum, song, mActivity.getApplicationContext()); - } + playSongAlbum(song); break; - case INT_DEFAULT_ACTION_QUEUE: - if (mAlbum == null) - { - mMusicManager.addToPlaylist(new QueryResponse(mActivity, "Song added to playlist.", "Error adding song!"), song, mActivity.getApplicationContext()); - } - else - { - mMusicManager.addToPlaylist(new QueryResponse(mActivity, "Playlist empty, added whole album.", "Song added to playlist."), mAlbum, song, mActivity.getApplicationContext()); - } + case INT_DEFAULT_ACTION_QUEUE: + queueSongAlbum(song); break; default: return; @@ -160,7 +141,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) fetch(); } } - + private void fetch() { final String title = mAlbum != null ? mAlbum.name + " - " : mArtist != null ? mArtist.name + " - " : mGenre != null ? mGenre.name + " - " : "" + "Songs"; DataResponse> response = new DataResponse>() { @@ -200,28 +181,10 @@ public void onContextItemSelected(MenuItem item) { final Song song = (Song)mList.getAdapter().getItem(((ThreeLabelsItemView)((AdapterContextMenuInfo)item.getMenuInfo()).targetView).position); switch (item.getItemId()) { case ITEM_CONTEXT_QUEUE: - if (mAlbum == null) { - mMusicManager.addToPlaylist(new QueryResponse(mActivity, "Song added to playlist.", "Error adding song!"), song, mActivity.getApplicationContext()); - } else { - mMusicManager.addToPlaylist(new QueryResponse(mActivity, "Playlist empty, added whole album.", "Song added to playlist."), mAlbum, song, mActivity.getApplicationContext()); - } + queueSongAlbum(song); break; case ITEM_CONTEXT_PLAY: - if (mAlbum == null) { - mMusicManager.play(new QueryResponse( - mActivity, - "Playing \"" + song.title + "\" by " + song.artist + "...", - "Error playing song!", - true - ), song, mActivity.getApplicationContext()); - } else { - mMusicManager.play(new QueryResponse( - mActivity, - "Playing album \"" + song.album + "\" starting with song \"" + song.title + "\" by " + song.artist + "...", - "Error playing song!", - true - ), mAlbum, song, mActivity.getApplicationContext()); - } + playSongAlbum(song); break; default: return; @@ -384,5 +347,48 @@ public void onActivityResume(Activity activity) { } } + /** + * Plays a song or its album + * if song belong to an album and "auto queue album" set, play the full album (starting with selected song). + * Else play only the given song. + * @param song Song to play + */ + private void playSongAlbum(Song song) { + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mActivity.getApplicationContext()); + boolean queueAlbum = prefs.getBoolean(PREF_AUTO_QUEUE_ALBUM, true); + if (mAlbum == null || queueAlbum == false) { + mMusicManager.play(new QueryResponse( + mActivity, + "Playing \"" + song.title + "\" by " + song.artist + "...", + "Error playing song!", + true + ), song, mActivity.getApplicationContext()); + } else { + mMusicManager.play(new QueryResponse( + mActivity, + "Playing album \"" + song.album + "\" starting with song \"" + song.title + "\" by " + song.artist + "...", + "Error playing song!", + true + ), mAlbum, song, mActivity.getApplicationContext()); + } + } + + /** + * Queue a song or play its album + * If playlist is not empty, queue the song. + * Else if song belong to an album and "auto queue album" set, play the full album (starting with selected song). + * Else play only the given song. + * @param song Song to play + */ + private void queueSongAlbum(Song song) { + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mActivity.getApplicationContext()); + boolean queueAlbum = prefs.getBoolean(PREF_AUTO_QUEUE_ALBUM, true); + if (mAlbum == null || queueAlbum == false) { + mMusicManager.addToPlaylist(new QueryResponse(mActivity, "Song added to playlist.", "Error adding song!"), song, mActivity.getApplicationContext()); + } else { + mMusicManager.addToPlaylist(new QueryResponse(mActivity, "Playlist empty, added whole album.", "Song added to playlist."), mAlbum, song, mActivity.getApplicationContext()); + } + } + private static final long serialVersionUID = 755529227668553163L; }