From 9fbf7578b216cdac338ccd6537e9efa2908d9c7d Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 4 Oct 2014 18:06:17 -0700 Subject: #392 Add top track view for Madsonic servers --- res/menu/select_album.xml | 4 +++ res/values/strings.xml | 1 + .../dsub/fragments/SelectDirectoryFragment.java | 34 ++++++++++++++++++++++ .../dsub/service/CachedMusicService.java | 7 ++++- .../daneren2005/dsub/service/MusicService.java | 2 ++ .../dsub/service/OfflineMusicService.java | 7 ++++- .../daneren2005/dsub/service/RESTMusicService.java | 20 ++++++++++++- src/github/daneren2005/dsub/util/Constants.java | 1 + 8 files changed, 73 insertions(+), 3 deletions(-) diff --git a/res/menu/select_album.xml b/res/menu/select_album.xml index 4b79d251..1a575d31 100644 --- a/res/menu/select_album.xml +++ b/res/menu/select_album.xml @@ -13,6 +13,10 @@ android:title="@string/menu.shuffle" compat:showAsAction="ifRoom|withText"/> + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 857ebe71..6ac264b8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -103,6 +103,7 @@ Add User Rescan Server Set Rating + Last.FM Top Tracks Playlists Update Information diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 6cbb7e9b..440bbd8a 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -87,6 +87,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter boolean restoredInstance = false; boolean lookupParent = false; boolean largeAlbums = false; + boolean topTracks = false; String lookupEntry; public SelectDirectoryFragment() { @@ -131,6 +132,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter refreshListing = args.getBoolean(Constants.INTENT_EXTRA_REFRESH_LISTINGS); artist = args.getBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, false); lookupEntry = args.getString(Constants.INTENT_EXTRA_SEARCH_SONG); + topTracks = args.getBoolean(Constants.INTENT_EXTRA_TOP_TRACKS); String childId = args.getString(Constants.INTENT_EXTRA_NAME_CHILD_ID); if(childId != null) { @@ -203,6 +205,10 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter menuInflater.inflate(R.menu.empty, menu); } else { menuInflater.inflate(R.menu.select_album, menu); + + if(!ServerInfo.isMadsonic(context)) { + menu.removeItem(R.id.menu_top_tracks); + } } } else { if(podcastId == null) { @@ -289,6 +295,9 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter case R.id.menu_unstar: unstarSelected(); return true; + case R.id.menu_top_tracks: + showTopTracks(); + return true; } return super.onOptionsItemSelected(item); @@ -452,6 +461,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } else { if(showAll) { getRecursiveMusicDirectory(id, name, refresh); + } else if(topTracks) { + getTopTracks(id, name, refresh); } else { getMusicDirectory(id, name, refresh); } @@ -557,6 +568,17 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter }.execute(); } + private void getTopTracks(final String id, final String name, final boolean refresh) { + setTitle(name); + + new LoadTask() { + @Override + protected MusicDirectory load(MusicService service) throws Exception { + return service.getTopTrackSongs(name, 20, context, this); + } + }.execute(); + } + private void getAlbumList(final String albumListType, final int size) { showHeader = false; @@ -1147,6 +1169,15 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter builder.create().show(); } + private void showTopTracks() { + SubsonicFragment fragment = new SelectDirectoryFragment(); + Bundle args = new Bundle(getArguments()); + args.putBoolean(Constants.INTENT_EXTRA_TOP_TRACKS, true); + fragment.setArguments(args); + + replaceFragment(fragment, true); + } + private View createHeader(List entries) { View header = entryList.findViewById(R.id.select_album_header); boolean add = false; @@ -1240,6 +1271,9 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } } }); + } else if(topTracks) { + artistView.setText(R.string.menu_top_tracks); + artistView.setVisibility(View.VISIBLE); } else if (artists.size() == 1) { String artistText = artists.iterator().next(); if(years.size() == 1) { diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java index 59ed550c..17c9e722 100644 --- a/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -626,7 +626,12 @@ public class CachedMusicService implements MusicService { public MusicDirectory getSongsByGenre(String genre, int count, int offset, Context context, ProgressListener progressListener) throws Exception { return musicService.getSongsByGenre(genre, count, offset, context, progressListener); } - + + @Override + public MusicDirectory getTopTrackSongs(String artist, int size, Context context, ProgressListener progressListener) throws Exception { + return musicService.getTopTrackSongs(artist, size, context, progressListener); + } + @Override public List getPodcastChannels(boolean refresh, Context context, ProgressListener progressListener) throws Exception { checkSettingsChanged(context); diff --git a/src/github/daneren2005/dsub/service/MusicService.java b/src/github/daneren2005/dsub/service/MusicService.java index 3f07e9f5..765f498a 100644 --- a/src/github/daneren2005/dsub/service/MusicService.java +++ b/src/github/daneren2005/dsub/service/MusicService.java @@ -137,6 +137,8 @@ public interface MusicService { List getGenres(boolean refresh, Context context, ProgressListener progressListener) throws Exception; MusicDirectory getSongsByGenre(String genre, int count, int offset, Context context, ProgressListener progressListener) throws Exception; + + MusicDirectory getTopTrackSongs(String artist, int size, Context context, ProgressListener progressListener) throws Exception; List getPodcastChannels(boolean refresh, Context context, ProgressListener progressListener) throws Exception; diff --git a/src/github/daneren2005/dsub/service/OfflineMusicService.java b/src/github/daneren2005/dsub/service/OfflineMusicService.java index 7dd2631f..22b12cde 100644 --- a/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -628,7 +628,12 @@ public class OfflineMusicService implements MusicService { throw new OfflineException(ERRORMSG); } - @Override + @Override + public MusicDirectory getTopTrackSongs(String artist, int size, Context context, ProgressListener progressListener) throws Exception { + throw new OfflineException(ERRORMSG); + } + + @Override public MusicDirectory getRandomSongs(int size, String folder, String genre, String startYear, String endYear, Context context, ProgressListener progressListener) throws Exception { File root = FileUtil.getMusicDirectory(context); List children = new LinkedList(); diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java index 1733009d..ca937bcc 100644 --- a/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -1040,7 +1040,25 @@ public class RESTMusicService implements MusicService { Util.close(reader); } } - + + @Override + public MusicDirectory getTopTrackSongs(String artist, int size, Context context, ProgressListener progressListener) throws Exception { + List parameterNames = new ArrayList(); + List parameterValues = new ArrayList(); + + parameterNames.add("artist"); + parameterValues.add(artist); + parameterNames.add("size"); + parameterValues.add(size); + + Reader reader = getReader(context, progressListener, "getTopTrackSongs", null, parameterNames, parameterValues); + try { + return new RandomSongsParser(context, getInstance(context)).parse(reader, progressListener); + } finally { + Util.close(reader); + } + } + @Override public List getPodcastChannels(boolean refresh, Context context, ProgressListener progressListener) throws Exception { checkServerVersion(context, "1.6", "Podcasts not supported."); diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java index 30dc33b4..c01df5c1 100644 --- a/src/github/daneren2005/dsub/util/Constants.java +++ b/src/github/daneren2005/dsub/util/Constants.java @@ -63,6 +63,7 @@ public final class Constants { public static final String INTENT_EXTRA_FRAGMENT_TYPE = "fragmentType"; public static final String INTENT_EXTRA_REFRESH_LISTINGS = "refreshListings"; public static final String INTENT_EXTRA_SEARCH_SONG = "searchSong"; + public static final String INTENT_EXTRA_TOP_TRACKS = "topTracks"; // Preferences keys. public static final String PREFERENCES_KEY_SERVER_KEY = "server"; -- cgit v1.2.3