diff options
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 @@ -14,6 +14,10 @@ compat:showAsAction="ifRoom|withText"/> <item + android:id="@+id/menu_top_tracks" + android:title="@string/menu.top_tracks"/> + + <item android:id="@+id/menu_show_all" android:title="@string/menu.show_all"/> </menu> 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 @@ <string name="menu.add_user">Add User</string>
<string name="menu.rescan">Rescan Server</string>
<string name="menu.rate">Set Rating</string>
+ <string name="menu.top_tracks">Last.FM Top Tracks</string>
<string name="playlist.label">Playlists</string>
<string name="playlist.update_info">Update Information</string>
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<Entry> 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<PodcastChannel> 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<Genre> 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<PodcastChannel> 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<File> children = new LinkedList<File>(); 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<String> parameterNames = new ArrayList<String>(); + List<Object> parameterValues = new ArrayList<Object>(); + + 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<PodcastChannel> 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"; |