diff options
-rw-r--r-- | res/menu/similar_artists.xml | 12 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/domain/MusicDirectory.java | 4 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/fragments/SimilarArtistFragment.java | 49 |
3 files changed, 60 insertions, 5 deletions
diff --git a/res/menu/similar_artists.xml b/res/menu/similar_artists.xml index bffa1837..771555b6 100644 --- a/res/menu/similar_artists.xml +++ b/res/menu/similar_artists.xml @@ -3,6 +3,18 @@ xmlns:compat="http://schemas.android.com/apk/res-auto"> <item + android:id="@+id/menu_play_now" + android:icon="?media_button_start" + android:title="@string/menu.play" + compat:showAsAction="always|withText"/> + + <item + android:id="@+id/menu_shuffle" + android:icon="?attr/shuffle" + android:title="@string/menu.shuffle" + compat:showAsAction="ifRoom|withText"/> + + <item android:id="@+id/menu_show_missing" android:title="@string/menu.show_missing"/> </menu>
\ No newline at end of file diff --git a/src/github/daneren2005/dsub/domain/MusicDirectory.java b/src/github/daneren2005/dsub/domain/MusicDirectory.java index d0bc173b..ad819763 100644 --- a/src/github/daneren2005/dsub/domain/MusicDirectory.java +++ b/src/github/daneren2005/dsub/domain/MusicDirectory.java @@ -107,6 +107,10 @@ public class MusicDirectory implements Serializable { public int getChildrenSize() { return children.size(); } + + public void shuffleChildren() { + Collections.shuffle(this.children); + } public void sortChildren(Context context, int instance) { if(ServerInfo.checkServerVersion(context, "1.8", instance)) { diff --git a/src/github/daneren2005/dsub/fragments/SimilarArtistFragment.java b/src/github/daneren2005/dsub/fragments/SimilarArtistFragment.java index c029581b..06427a5d 100644 --- a/src/github/daneren2005/dsub/fragments/SimilarArtistFragment.java +++ b/src/github/daneren2005/dsub/fragments/SimilarArtistFragment.java @@ -30,13 +30,17 @@ import android.widget.TextView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.Artist; import github.daneren2005.dsub.domain.ArtistInfo; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.MusicService; +import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.ArtistAdapter; import java.net.URLEncoder; +import java.util.LinkedList; import java.util.List; public class SimilarArtistFragment extends SelectListFragment<Artist> { @@ -54,17 +58,19 @@ public class SimilarArtistFragment extends SelectListFragment<Artist> { @Override public boolean onOptionsItemSelected(MenuItem item) { - if(super.onOptionsItemSelected(item)) { - return true; - } - switch (item.getItemId()) { + case R.id.menu_play_now: + playAll(false); + return true; + case R.id.menu_shuffle: + playAll(true); + return true; case R.id.menu_show_missing: showMissingArtists(); break; } - return false; + return super.onOptionsItemSelected(item); } @Override @@ -132,4 +138,37 @@ public class SimilarArtistFragment extends SelectListFragment<Artist> { Util.showHTMLDialog(context, R.string.menu_similar_artists, b.toString()); } + + private void playAll(final boolean shuffle) { + new RecursiveLoader(context) { + @Override + protected Boolean doInBackground() throws Throwable { + musicService = MusicServiceFactory.getMusicService(context); + + MusicDirectory root = new MusicDirectory(); + for(Artist artist: objects) { + if(Util.isTagBrowsing(context) && !Util.isOffline(context)) { + root.addChildren(musicService.getArtist(artist.getId(), artist.getName(), false, context, this).getChildren()); + } else { + root.addChildren(musicService.getMusicDirectory(artist.getId(), artist.getName(), false, context, this).getChildren()); + } + } + + if(shuffle) { + root.shuffleChildren(); + } + + songs = new LinkedList<MusicDirectory.Entry>(); + getSongsRecursively(root, songs); + + DownloadService downloadService = getDownloadService(); + if (!songs.isEmpty() && downloadService != null) { + downloadService.clear(); + downloadService.download(songs, false, true, false, false); + } + + return true; + } + }.execute(); + } } |