aboutsummaryrefslogtreecommitdiff
path: root/src/github/daneren2005
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-02-03 11:08:29 -0800
committerScott Jackson <daneren2005@gmail.com>2015-02-03 11:08:29 -0800
commit29b4fa7f77104b86f04c4db576caab6fa8d5f049 (patch)
tree80c38a9d85ce7226b4d8a6dc4762b4d2865dc7e0 /src/github/daneren2005
parent760a4fcfac37d751c19e094076b63aa44a312e3c (diff)
downloaddsub-29b4fa7f77104b86f04c4db576caab6fa8d5f049.tar.gz
dsub-29b4fa7f77104b86f04c4db576caab6fa8d5f049.tar.bz2
dsub-29b4fa7f77104b86f04c4db576caab6fa8d5f049.zip
#450 Add ability to play/shuffle from Similar Artists menu
Diffstat (limited to 'src/github/daneren2005')
-rw-r--r--src/github/daneren2005/dsub/domain/MusicDirectory.java4
-rw-r--r--src/github/daneren2005/dsub/fragments/SimilarArtistFragment.java49
2 files changed, 48 insertions, 5 deletions
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();
+ }
}