diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-01-12 20:38:05 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-01-12 20:38:05 -0800 |
commit | 4333c8992f7b440d5e4013f017e3b4134a53ae71 (patch) | |
tree | 5d2b8940c7d1c2a362a8d773fa5f949a47c4605f /src | |
parent | d0936909afd512c5c4ef1fe07ddc331ac161aec0 (diff) | |
download | dsub-4333c8992f7b440d5e4013f017e3b4134a53ae71.tar.gz dsub-4333c8992f7b440d5e4013f017e3b4134a53ae71.tar.bz2 dsub-4333c8992f7b440d5e4013f017e3b4134a53ae71.zip |
#46 Finish adding basic browse by tag support
Diffstat (limited to 'src')
14 files changed, 158 insertions, 35 deletions
diff --git a/src/github/daneren2005/dsub/fragments/SearchFragment.java b/src/github/daneren2005/dsub/fragments/SearchFragment.java index b77df12b..86f31041 100644 --- a/src/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/src/github/daneren2005/dsub/fragments/SearchFragment.java @@ -298,6 +298,7 @@ public class SearchFragment extends SubsonicFragment { if(autoplay) {
args.putBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true);
}
+ args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true);
fragment.setArguments(args);
replaceFragment(fragment, R.id.fragment_list_layout);
diff --git a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 5b46b40c..df4e2d95 100644 --- a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -171,6 +171,7 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie if("root".equals(artist.getId())) {
args.putSerializable(Constants.FRAGMENT_LIST, (Serializable) entries);
}
+ args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true);
fragment.setArguments(args);
replaceFragment(fragment, R.id.fragment_list_layout);
@@ -185,7 +186,7 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie private void load(final boolean refresh) {
setTitle(R.string.button_bar_browse);
- if (Util.isOffline(context)) {
+ if (Util.isOffline(context) || Util.isTagBrowsing(context)) {
folderButton.setVisibility(View.GONE);
} else {
folderButton.setVisibility(View.VISIBLE);
@@ -196,7 +197,7 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie @Override
protected Indexes doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(context);
- if (!Util.isOffline(context)) {
+ if (!Util.isOffline(context) && !Util.isTagBrowsing(context)) {
musicFolders = musicService.getMusicFolders(refresh, context, this);
}
String musicFolderId = Util.getSelectedMusicFolderId(context);
diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 93558a03..0b58c618 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -68,6 +68,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter int albumListSize;
boolean refreshListing = false;
boolean showAll = false;
+ boolean artist = false;
public SelectDirectoryFragment() {
@@ -136,6 +137,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter albumListExtra = args.getString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_EXTRA);
albumListSize = args.getInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0);
refreshListing = args.getBoolean(Constants.INTENT_EXTRA_REFRESH_LISTINGS);
+ artist = args.getBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, false);
if(entries == null) {
entries = (List<MusicDirectory.Entry>) args.getSerializable(Constants.FRAGMENT_LIST);
}
@@ -320,6 +322,9 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter if ("newest".equals(albumListType)) {
args.putBoolean(Constants.INTENT_EXTRA_REFRESH_LISTINGS, true);
}
+ if(entry.getArtist() == null && entry.getParent() == null) {
+ args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true);
+ }
fragment.setArguments(args);
replaceFragment(fragment, rootId, true);
@@ -390,7 +395,15 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter new LoadTask() {
@Override
protected MusicDirectory load(MusicService service) throws Exception {
- return service.getMusicDirectory(id, name, refresh, context, this);
+ if(Util.isTagBrowsing(context) && !Util.isOffline(context)) {
+ if(artist) {
+ return service.getArtist(id, name, refresh, context, this);
+ } else {
+ return service.getAlbum(id, name, refresh, context, this);
+ }
+ } else {
+ return service.getMusicDirectory(id, name, refresh, context, this);
+ }
}
@Override
@@ -409,7 +422,15 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter protected MusicDirectory load(MusicService service) throws Exception {
MusicDirectory root;
if(share == null) {
- root = service.getMusicDirectory(id, name, refresh, context, this);
+ if(Util.isTagBrowsing(context) && !Util.isOffline(context)) {
+ if(artist) {
+ root = service.getArtist(id, name, refresh, context, this);
+ } else {
+ root = service.getAlbum(id, name, refresh, context, this);
+ }
+ } else {
+ root = service.getMusicDirectory(id, name, refresh, context, this);
+ }
} else {
root = share.getMusicDirectory();
}
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 4bba4e89..8907a534 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -588,7 +588,11 @@ public class SubsonicFragment extends Fragment { @Override
protected Void doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(context);
- musicService.setStarred(entry.getId(), starred, context, null);
+ if(entry.isDirectory() && Util.isTagBrowsing(context) && !Util.isOffline(context)) {
+ musicService.setStarred(null, null, entry.getId(), starred, context, null);
+ } else {
+ musicService.setStarred(entry.getId(), null, null, starred, context, null);
+ }
// Make sure to clear parent cache
String s = Util.getRestUrl(context, null) + entry.getParent();
@@ -627,7 +631,11 @@ public class SubsonicFragment extends Fragment { @Override
protected Void doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(context);
- musicService.setStarred(entry.getId(), starred, context, null);
+ if(Util.isTagBrowsing(context) && !Util.isOffline(context)) {
+ musicService.setStarred(null, entry.getId(), null, starred, context, null);
+ } else {
+ musicService.setStarred(entry.getId(), null, null, starred, context, null);
+ }
return null;
}
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java index b93a6e1e..f223c5a6 100644 --- a/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -126,21 +126,53 @@ public class CachedMusicService implements MusicService { @Override public MusicDirectory getMusicDirectory(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception { - MusicDirectory dir = null; + MusicDirectory dir = null; - if(!refresh) { - dir = FileUtil.deserialize(context, getCacheName(context, "directory", id), MusicDirectory.class); - } + if(!refresh) { + dir = FileUtil.deserialize(context, getCacheName(context, "directory", id), MusicDirectory.class); + } - if(dir == null) { - dir = musicService.getMusicDirectory(id, name, refresh, context, progressListener); - FileUtil.serialize(context, dir, getCacheName(context, "directory", id)); - } + if(dir == null) { + dir = musicService.getMusicDirectory(id, name, refresh, context, progressListener); + FileUtil.serialize(context, dir, getCacheName(context, "directory", id)); + } - return dir; + return dir; } - @Override + @Override + public MusicDirectory getArtist(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception { + MusicDirectory dir = null; + + if(!refresh) { + dir = FileUtil.deserialize(context, getCacheName(context, "artist", id), MusicDirectory.class); + } + + if(dir == null) { + dir = musicService.getArtist(id, name, refresh, context, progressListener); + FileUtil.serialize(context, dir, getCacheName(context, "artist", id)); + } + + return dir; + } + + @Override + public MusicDirectory getAlbum(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception { + MusicDirectory dir = null; + + if(!refresh) { + dir = FileUtil.deserialize(context, getCacheName(context, "album", id), MusicDirectory.class); + } + + if(dir == null) { + dir = musicService.getAlbum(id, name, refresh, context, progressListener); + FileUtil.serialize(context, dir, getCacheName(context, "album", id)); + } + + return dir; + } + + @Override public SearchResult search(SearchCritera criteria, Context context, ProgressListener progressListener) throws Exception { return musicService.search(criteria, context, progressListener); } @@ -309,8 +341,8 @@ public class CachedMusicService implements MusicService { } @Override - public void setStarred(String id, boolean starred, Context context, ProgressListener progressListener) throws Exception { - musicService.setStarred(id, starred, context, progressListener); + public void setStarred(String id, String artistId, String albumId, boolean starred, Context context, ProgressListener progressListener) throws Exception { + musicService.setStarred(id, artistId, albumId, starred, context, progressListener); } @Override diff --git a/src/github/daneren2005/dsub/service/MusicService.java b/src/github/daneren2005/dsub/service/MusicService.java index 0946c4f7..28fc2036 100644 --- a/src/github/daneren2005/dsub/service/MusicService.java +++ b/src/github/daneren2005/dsub/service/MusicService.java @@ -57,6 +57,10 @@ public interface MusicService { MusicDirectory getMusicDirectory(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception; + MusicDirectory getArtist(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception; + + MusicDirectory getAlbum(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception; + SearchResult search(SearchCritera criteria, Context context, ProgressListener progressListener) throws Exception; MusicDirectory getStarredList(Context context, ProgressListener progressListener) throws Exception; @@ -113,7 +117,7 @@ public interface MusicService { RemoteStatus setJukeboxGain(float gain, Context context, ProgressListener progressListener) throws Exception; - void setStarred(String id, boolean starred, Context context, ProgressListener progressListener) throws Exception; + void setStarred(String id, String artistId, String albumId, boolean starred, Context context, ProgressListener progressListener) throws Exception; List<Share> getShares(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 80ad375a..2196afbb 100644 --- a/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -133,7 +133,17 @@ public class OfflineMusicService extends RESTMusicService { return result; } - private String getName(File file) { + @Override + public MusicDirectory getArtist(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception { + throw new OfflineException("Artist by tags not available in offline mode"); + } + + @Override + public MusicDirectory getAlbum(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception { + throw new OfflineException("Album by tags not available in offline mode"); + } + + private String getName(File file) { String name = file.getName(); if (file.isDirectory()) { return name; @@ -535,7 +545,7 @@ public class OfflineMusicService extends RESTMusicService { } @Override - public void setStarred(String id, boolean starred, Context context, ProgressListener progressListener) throws Exception { + public void setStarred(String id, String artistId, String albumId, boolean starred, Context context, ProgressListener progressListener) throws Exception { SharedPreferences prefs = Util.getPreferences(context); String cacheLocn = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null); diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java index 1927dc93..906d2ad4 100644 --- a/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -274,7 +274,27 @@ public class RESTMusicService implements MusicService { } } - @Override + @Override + public MusicDirectory getArtist(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception { + Reader reader = getReader(context, progressListener, "getArtist", null, "id", id); + try { + return new MusicDirectoryParser(context).parse(name, reader, progressListener); + } finally { + Util.close(reader); + } + } + + @Override + public MusicDirectory getAlbum(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception { + Reader reader = getReader(context, progressListener, "getAlbum", null, "id", id); + try { + return new MusicDirectoryParser(context).parse(name, reader, progressListener); + } finally { + Util.close(reader); + } + } + + @Override public SearchResult search(SearchCritera critera, Context context, ProgressListener progressListener) throws Exception { try { return searchNew(critera, context, progressListener); @@ -802,11 +822,24 @@ public class RESTMusicService implements MusicService { } @Override - public void setStarred(String id, boolean starred, Context context, ProgressListener progressListener) throws Exception { + public void setStarred(String id, String artistId, String albumId, boolean starred, Context context, ProgressListener progressListener) throws Exception { checkServerVersion(context, "1.8", "Starring is not supported."); - id = getOfflineSongId(id, context, progressListener); + + List<String> names = new ArrayList<String>(); + List<Object> values = new ArrayList<Object>(); + + if(id != null) { + names.add("id"); + values.add(getOfflineSongId(id, context, progressListener)); + } else if(artistId != null) { + names.add("artistId"); + values.add(artistId); + } else if(albumId != null) { + names.add("albumId"); + values.add(albumId); + } - Reader reader = getReader(context, progressListener, starred ? "star" : "unstar", null, "id", id); + Reader reader = getReader(context, progressListener, starred ? "star" : "unstar", null, names, values); try { new ErrorParser(context).parse(reader); } finally { @@ -1183,7 +1216,7 @@ public class RESTMusicService implements MusicService { String id = offline.getString(Constants.OFFLINE_STAR_ID + i, null); boolean starred = offline.getBoolean(Constants.OFFLINE_STAR_SETTING + i, false); if(id != null) { - setStarred(id, starred, context, progressListener); + setStarred(id, null, null, starred, context, progressListener); } else { String search = offline.getString(Constants.OFFLINE_STAR_SEARCH + i, ""); try{ @@ -1191,10 +1224,10 @@ public class RESTMusicService implements MusicService { SearchResult result = searchNew(critera, context, progressListener); if(result.getSongs().size() == 1){ Log.i(TAG, "Query '" + search + "' returned song " + result.getSongs().get(0).getTitle() + " by " + result.getSongs().get(0).getArtist() + " with id " + result.getSongs().get(0).getId()); - setStarred(result.getSongs().get(0).getId(), starred, context, progressListener); + setStarred(result.getSongs().get(0).getId(), null, null, starred, context, progressListener); } else if(result.getAlbums().size() == 1){ Log.i(TAG, "Query '" + search + "' returned song " + result.getAlbums().get(0).getTitle() + " by " + result.getAlbums().get(0).getArtist() + " with id " + result.getAlbums().get(0).getId()); - setStarred(result.getAlbums().get(0).getId(), starred, context, progressListener); + setStarred(result.getAlbums().get(0).getId(), null, null, starred, context, progressListener); } else{ throw new Exception("Song not found on server"); diff --git a/src/github/daneren2005/dsub/service/parser/IndexesParser.java b/src/github/daneren2005/dsub/service/parser/IndexesParser.java index bf5bd8b1..30ea190b 100644 --- a/src/github/daneren2005/dsub/service/parser/IndexesParser.java +++ b/src/github/daneren2005/dsub/service/parser/IndexesParser.java @@ -67,7 +67,7 @@ public class IndexesParser extends MusicDirectoryEntryParser { eventType = nextParseEvent(); if (eventType == XmlPullParser.START_TAG) { String name = getElementName(); - if ("indexes".equals(name)) { + if ("indexes".equals(name) || "artists".equals(name)) { changed = true; lastModified = getLong("lastModified"); ignoredArticles = get("ignoredArticles"); diff --git a/src/github/daneren2005/dsub/service/parser/MusicDirectoryEntryParser.java b/src/github/daneren2005/dsub/service/parser/MusicDirectoryEntryParser.java index 3c12dfd4..e58427f5 100644 --- a/src/github/daneren2005/dsub/service/parser/MusicDirectoryEntryParser.java +++ b/src/github/daneren2005/dsub/service/parser/MusicDirectoryEntryParser.java @@ -34,6 +34,9 @@ public class MusicDirectoryEntryParser extends AbstractParser { entry.setId(get("id")); entry.setParent(get("parent")); entry.setTitle(get("title")); + if(entry.getTitle() == null) { + entry.setTitle(get("name")); + } entry.setDirectory(getBoolean("isDir")); entry.setCoverArt(get("coverArt")); entry.setArtist(get("artist")); diff --git a/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java b/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java index 7a49cfa5..75f878be 100644 --- a/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java +++ b/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java @@ -49,19 +49,25 @@ public class MusicDirectoryParser extends MusicDirectoryEntryParser { MusicDirectory dir = new MusicDirectory(); int eventType; + boolean isArtist = false; do { eventType = nextParseEvent(); if (eventType == XmlPullParser.START_TAG) { String name = getElementName(); - if ("child".equals(name)) { + if ("child".equals(name) || "song".equals(name) || "video".equals(name)) { MusicDirectory.Entry entry = parseEntry(artist); entry.setGrandParent(dir.getParent()); dir.addChild(entry); - } else if ("directory".equals(name)) { + } else if ("directory".equals(name) || "artist".equals(name) || ("album".equals(name) && !isArtist)) { dir.setName(get("name")); dir.setId(get("id")); dir.setParent(get("parent")); - } else if ("error".equals(name)) { + isArtist = true; + } else if("album".equals(name)) { + MusicDirectory.Entry entry = parseEntry(artist); + entry.setDirectory(true); + dir.addChild(entry); + } else if ("error".equals(name)) { handleError(); } } diff --git a/src/github/daneren2005/dsub/service/parser/SearchResult2Parser.java b/src/github/daneren2005/dsub/service/parser/SearchResult2Parser.java index a0be07ac..abf96d7f 100644 --- a/src/github/daneren2005/dsub/service/parser/SearchResult2Parser.java +++ b/src/github/daneren2005/dsub/service/parser/SearchResult2Parser.java @@ -57,7 +57,9 @@ public class SearchResult2Parser extends MusicDirectoryEntryParser { artist.setName(get("name")); artists.add(artist); } else if ("album".equals(name)) { - albums.add(parseEntry("")); + MusicDirectory.Entry entry = parseEntry(""); + entry.setDirectory(true); + albums.add(entry); } else if ("song".equals(name)) { songs.add(parseEntry("")); } else if ("error".equals(name)) { diff --git a/src/github/daneren2005/dsub/service/parser/StarredListParser.java b/src/github/daneren2005/dsub/service/parser/StarredListParser.java index 54e419d3..bd2a7888 100644 --- a/src/github/daneren2005/dsub/service/parser/StarredListParser.java +++ b/src/github/daneren2005/dsub/service/parser/StarredListParser.java @@ -48,7 +48,9 @@ public class StarredListParser extends MusicDirectoryEntryParser { String name = getElementName(); if ("album".equals(name) || "song".equals(name)) { MusicDirectory.Entry entry = parseEntry(""); - entry.setDirectory(true); + if("album".equals(name)) { + entry.setDirectory(true); + } dir.addChild(entry); } else if("artist".equals(name)) { MusicDirectory.Entry entry = parseArtist(); diff --git a/src/github/daneren2005/dsub/util/compat/RemoteControlClientKK.java b/src/github/daneren2005/dsub/util/compat/RemoteControlClientKK.java index e88b4122..2c041d71 100644 --- a/src/github/daneren2005/dsub/util/compat/RemoteControlClientKK.java +++ b/src/github/daneren2005/dsub/util/compat/RemoteControlClientKK.java @@ -64,7 +64,7 @@ public class RemoteControlClientKK extends RemoteControlClientJB { protected Void doInBackground(Void... params) { try { MusicService musicService = MusicServiceFactory.getMusicService(downloadService); - musicService.setStarred(entry.getId(), starred, downloadService, null); + musicService.setStarred(entry.getId(), null, null, starred, downloadService, null); // Make sure to clear parent cache String s = Util.getRestUrl(downloadService, null) + entry.getParent(); |