From 50cbd5040bfecfbad8b46694be17e6b793094c43 Mon Sep 17 00:00:00 2001 From: Kurt Hardin Date: Tue, 25 Sep 2012 11:46:13 -0700 Subject: Added star support features for original UI. --- .../dsub/activity/SelectAlbumActivity.java | 8 ++- .../dsub/service/CachedMusicService.java | 5 ++ .../daneren2005/dsub/service/MusicService.java | 2 + .../daneren2005/dsub/service/RESTMusicService.java | 11 ++++ .../dsub/service/parser/StarredListParser.java | 62 ++++++++++++++++++++++ 5 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 subsonic-android/src/github/daneren2005/dsub/service/parser/StarredListParser.java diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java index 108dcf9c..8a473bc7 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java @@ -336,7 +336,13 @@ public class SelectAlbumActivity extends SubsonicTabActivity { new LoadTask() { @Override protected MusicDirectory load(MusicService service) throws Exception { - return service.getAlbumList(albumListType, size, offset, SelectAlbumActivity.this, this); + MusicDirectory result; + if ("starred".equals(albumListType)) { + result = service.getStarredList(SelectAlbumActivity.this, this); + } else { + result = service.getAlbumList(albumListType, size, offset, SelectAlbumActivity.this, this); + } + return result; } @Override diff --git a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java index dbd421f2..832b2037 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -163,6 +163,11 @@ public class CachedMusicService implements MusicService { return musicService.getAlbumList(type, size, offset, context, progressListener); } + @Override + public MusicDirectory getStarredList(Context context, ProgressListener progressListener) throws Exception { + return musicService.getStarredList(context, progressListener); + } + @Override public MusicDirectory getRandomSongs(int size, Context context, ProgressListener progressListener) throws Exception { return musicService.getRandomSongs(size, context, progressListener); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java index a5045b18..15abbdf8 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java @@ -53,6 +53,8 @@ public interface MusicService { SearchResult search(SearchCritera criteria, Context context, ProgressListener progressListener) throws Exception; + MusicDirectory getStarredList(Context context, ProgressListener progressListener) throws Exception; + MusicDirectory getPlaylist(String id, String name, Context context, ProgressListener progressListener) throws Exception; List getPlaylists(boolean refresh, Context context, ProgressListener progressListener) throws Exception; diff --git a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java index c24b2c06..1ef65bb8 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -93,6 +93,7 @@ import github.daneren2005.dsub.service.parser.PlaylistsParser; import github.daneren2005.dsub.service.parser.RandomSongsParser; import github.daneren2005.dsub.service.parser.SearchResult2Parser; import github.daneren2005.dsub.service.parser.SearchResultParser; +import github.daneren2005.dsub.service.parser.StarredListParser; import github.daneren2005.dsub.service.parser.VersionParser; import github.daneren2005.dsub.service.ssl.SSLSocketFactory; import github.daneren2005.dsub.service.ssl.TrustSelfSignedStrategy; @@ -414,6 +415,16 @@ public class RESTMusicService implements MusicService { } } + @Override + public MusicDirectory getStarredList(Context context, ProgressListener progressListener) throws Exception { + Reader reader = getReader(context, progressListener, "getStarred", null); + try { + return new StarredListParser(context).parse(reader, progressListener); + } finally { + Util.close(reader); + } + } + @Override public MusicDirectory getRandomSongs(int size, Context context, ProgressListener progressListener) throws Exception { HttpParams params = new BasicHttpParams(); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/parser/StarredListParser.java b/subsonic-android/src/github/daneren2005/dsub/service/parser/StarredListParser.java new file mode 100644 index 00000000..c3c16949 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/service/parser/StarredListParser.java @@ -0,0 +1,62 @@ +/* + This file is part of Subsonic. + + Subsonic is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Subsonic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Subsonic. If not, see . + + Copyright 2009 (C) Sindre Mehus + */ +package github.daneren2005.dsub.service.parser; + +import android.content.Context; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.util.ProgressListener; +import org.xmlpull.v1.XmlPullParser; + +import java.io.Reader; + +/** + * @author Kurt Hardin + */ +public class StarredListParser extends MusicDirectoryEntryParser { + + public StarredListParser(Context context) { + super(context); + } + + public MusicDirectory parse(Reader reader, ProgressListener progressListener) throws Exception { + + updateProgress(progressListener, R.string.parser_reading); + init(reader); + + MusicDirectory dir = new MusicDirectory(); + int eventType; + do { + eventType = nextParseEvent(); + if (eventType == XmlPullParser.START_TAG) { + String name = getElementName(); + if ("album".equals(name) || "song".equals(name)) { + dir.addChild(parseEntry()); + } else if ("error".equals(name)) { + handleError(); + } + } + } while (eventType != XmlPullParser.END_DOCUMENT); + + validate(); + updateProgress(progressListener, R.string.parser_reading_done); + + return dir; + } +} \ No newline at end of file -- cgit v1.2.3