aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-01-08 17:49:20 -0800
committerScott Jackson <daneren2005@gmail.com>2016-01-08 17:49:20 -0800
commit8396286e51f30da6ad04883d5097fd81198f7266 (patch)
tree31a8a1ef1ed7b44f7bfa4d50825c5e3f253a3c20
parent3828901677e2ccb2ba783a51c333bbab7b018675 (diff)
downloaddsub-8396286e51f30da6ad04883d5097fd81198f7266.tar.gz
dsub-8396286e51f30da6ad04883d5097fd81198f7266.tar.bz2
dsub-8396286e51f30da6ad04883d5097fd81198f7266.zip
fixes #595 Add Album Lists to Auto
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java70
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java57
2 files changed, 100 insertions, 27 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java b/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java
index d579ef54..e07b58b0 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java
@@ -33,6 +33,8 @@ import java.util.ArrayList;
import java.util.List;
import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.domain.MusicDirectory.Entry;
import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.util.Constants;
@@ -50,6 +52,7 @@ public class AutoMediaBrowserService extends MediaBrowserService {
private static final String BROWSER_PLAYLISTS = "playlists";
private static final String PLAYLIST_PREFIX = "pl-";
private static final String ALBUM_TYPE_PREFIX = "ty-";
+ private static final String MUSIC_DIRECTORY_PREFIX = "md-";
private DownloadService downloadService;
private Handler handler = new Handler();
@@ -76,12 +79,16 @@ public class AutoMediaBrowserService extends MediaBrowserService {
} else if(parentId.startsWith(ALBUM_TYPE_PREFIX)) {
int id = Integer.valueOf(parentId.substring(ALBUM_TYPE_PREFIX.length()));
getAlbumList(result, id);
+ } else if(parentId.startsWith(MUSIC_DIRECTORY_PREFIX)) {
+ String id = parentId.substring(MUSIC_DIRECTORY_PREFIX.length());
+ getPlayOptions(result, id, Constants.INTENT_EXTRA_NAME_ID);
} else if(BROWSER_LIBRARY.equals(parentId)) {
getLibrary(result);
} else if(BROWSER_PLAYLISTS.equals(parentId)) {
getPlaylists(result);
} else if(parentId.startsWith(PLAYLIST_PREFIX)) {
- getPlayOptions(result, parentId.substring(PLAYLIST_PREFIX.length()), Constants.INTENT_EXTRA_NAME_PLAYLIST_ID);
+ String id = parentId.substring(PLAYLIST_PREFIX.length());
+ getPlayOptions(result, id, Constants.INTENT_EXTRA_NAME_PLAYLIST_ID);
} else {
// No idea what it is, send empty result
result.sendResult(new ArrayList<MediaBrowser.MediaItem>());
@@ -91,12 +98,12 @@ public class AutoMediaBrowserService extends MediaBrowserService {
private void getRootFolders(Result<List<MediaBrowser.MediaItem>> result) {
List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>();
- /*MediaDescription.Builder albumLists = new MediaDescription.Builder();
+ MediaDescription.Builder albumLists = new MediaDescription.Builder();
albumLists.setTitle(downloadService.getString(R.string.main_albums_title))
.setMediaId(BROWSER_ALBUM_LISTS);
mediaItems.add(new MediaBrowser.MediaItem(albumLists.build(), MediaBrowser.MediaItem.FLAG_BROWSABLE));
- MediaDescription.Builder library = new MediaDescription.Builder();
+ /*MediaDescription.Builder library = new MediaDescription.Builder();
library.setTitle(downloadService.getString(R.string.button_bar_browse))
.setMediaId(BROWSER_LIBRARY);
mediaItems.add(new MediaBrowser.MediaItem(library.build(), MediaBrowser.MediaItem.FLAG_BROWSABLE));*/
@@ -113,15 +120,10 @@ public class AutoMediaBrowserService extends MediaBrowserService {
List<Integer> albums = new ArrayList<>();
albums.add(R.string.main_albums_newest);
albums.add(R.string.main_albums_random);
- if(ServerInfo.checkServerVersion(downloadService, "1.8")) {
- albums.add(R.string.main_albums_alphabetical);
- }
if(!Util.isTagBrowsing(downloadService)) {
albums.add(R.string.main_albums_highest);
}
- // albums.add(R.string.main_albums_starred);
- // albums.add(R.string.main_albums_genres);
- // albums.add(R.string.main_albums_year);
+ albums.add(R.string.main_albums_starred);
albums.add(R.string.main_albums_recent);
albums.add(R.string.main_albums_frequent);
@@ -138,8 +140,56 @@ public class AutoMediaBrowserService extends MediaBrowserService {
result.sendResult(mediaItems);
}
- private void getAlbumList(Result<List<MediaBrowser.MediaItem>> result, int id) {
+ private void getAlbumList(final Result<List<MediaBrowser.MediaItem>> result, final int id) {
+ new SilentServiceTask<MusicDirectory>(downloadService) {
+ @Override
+ protected MusicDirectory doInBackground(MusicService musicService) throws Throwable {
+ String albumListType;
+ switch(id) {
+ case R.string.main_albums_newest:
+ albumListType = "newest";
+ break;
+ case R.string.main_albums_random:
+ albumListType = "random";
+ break;
+ case R.string.main_albums_highest:
+ albumListType = "highest";
+ break;
+ case R.string.main_albums_starred:
+ albumListType = "starred";
+ break;
+ case R.string.main_albums_recent:
+ albumListType = "recent";
+ break;
+ case R.string.main_albums_frequent:
+ albumListType = "frequent";
+ break;
+ default:
+ albumListType = "newest";
+ }
+
+ return musicService.getAlbumList(albumListType, 40, 0, true, downloadService, null);
+ }
+ @Override
+ protected void done(MusicDirectory albumSet) {
+ List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>();
+
+ for(Entry album: albumSet.getChildren(true, false)) {
+ MediaDescription description = new MediaDescription.Builder()
+ .setTitle(album.getAlbumDisplay())
+ .setSubtitle(album.getArtist())
+ .setMediaId(MUSIC_DIRECTORY_PREFIX + album.getId())
+ .build();
+
+ mediaItems.add(new MediaBrowser.MediaItem(description, MediaBrowser.MediaItem.FLAG_BROWSABLE));
+ }
+
+ result.sendResult(mediaItems);
+ }
+ }.execute();
+
+ result.detach();
}
private void getLibrary(Result<List<MediaBrowser.MediaItem>> result) {
diff --git a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java
index 456446f3..fb489705 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java
@@ -43,6 +43,7 @@ import github.daneren2005.dsub.R;
import github.daneren2005.dsub.activity.SubsonicActivity;
import github.daneren2005.dsub.activity.SubsonicFragmentActivity;
import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.domain.MusicDirectory.Entry;
import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.domain.SearchCritera;
import github.daneren2005.dsub.domain.SearchResult;
@@ -145,7 +146,7 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
DownloadFile downloadFile = downloadService.getCurrentPlaying();
if(downloadFile != null) {
- MusicDirectory.Entry entry = downloadFile.getSong();
+ Entry entry = downloadFile.getSong();
addCustomActions(entry, builder);
builder.setActiveQueueItemId(entry.getId().hashCode());
}
@@ -156,7 +157,7 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
}
@Override
- public void updateMetadata(Context context, MusicDirectory.Entry currentSong) {
+ public void updateMetadata(Context context, Entry currentSong) {
setMetadata(currentSong, null);
if(currentSong != null && imageLoader != null) {
@@ -165,11 +166,11 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
}
@Override
- public void metadataChanged(MusicDirectory.Entry currentSong) {
+ public void metadataChanged(Entry currentSong) {
setPlaybackState(previousState);
}
- public void setMetadata(MusicDirectory.Entry currentSong, Bitmap bitmap) {
+ public void setMetadata(Entry currentSong, Bitmap bitmap) {
MediaMetadata.Builder builder = new MediaMetadata.Builder();
builder.putString(MediaMetadata.METADATA_KEY_ARTIST, (currentSong == null) ? null : currentSong.getArtist())
.putString(MediaMetadata.METADATA_KEY_ALBUM, (currentSong == null) ? null : currentSong.getAlbum())
@@ -189,7 +190,7 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
}
@Override
- public void updateAlbumArt(MusicDirectory.Entry currentSong, Bitmap bitmap) {
+ public void updateAlbumArt(Entry currentSong, Bitmap bitmap) {
setMetadata(currentSong, bitmap);
}
@@ -208,7 +209,7 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
List<MediaSession.QueueItem> queue = new ArrayList<>();
for(DownloadFile file: playlist) {
- MusicDirectory.Entry entry = file.getSong();
+ Entry entry = file.getSong();
MediaDescription description = new MediaDescription.Builder()
.setMediaId(entry.getId())
@@ -244,7 +245,7 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
return actions;
}
- protected void addCustomActions(MusicDirectory.Entry currentSong, PlaybackState.Builder builder) {
+ protected void addCustomActions(Entry currentSong, PlaybackState.Builder builder) {
Bundle showOnWearExtras = new Bundle();
showOnWearExtras.putBoolean(SHOW_ON_WEAR, true);
@@ -296,7 +297,7 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
SearchResult results = musicService.search(searchCritera, downloadService, null);
if(results.hasArtists()) {
- playFromParent(new MusicDirectory.Entry(results.getArtists().get(0)));
+ playFromParent(new Entry(results.getArtists().get(0)));
} else if(results.hasAlbums()) {
playFromParent(results.getAlbums().get(0));
} else if(results.hasSongs()) {
@@ -308,12 +309,12 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
return null;
}
- private void playFromParent(MusicDirectory.Entry parent) throws Exception {
- List<MusicDirectory.Entry> songs = new ArrayList<>();
+ private void playFromParent(Entry parent) throws Exception {
+ List<Entry> songs = new ArrayList<>();
getSongsRecursively(parent, songs);
playSongs(songs);
}
- private void getSongsRecursively(MusicDirectory.Entry parent, List<MusicDirectory.Entry> songs) throws Exception {
+ private void getSongsRecursively(Entry parent, List<Entry> songs) throws Exception {
MusicDirectory musicDirectory;
if(Util.isTagBrowsing(downloadService) && !Util.isOffline(downloadService)) {
musicDirectory = musicService.getAlbum(parent.getId(), parent.getTitle(), false, downloadService, this);
@@ -321,7 +322,7 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
musicDirectory = musicService.getMusicDirectory(parent.getId(), parent.getTitle(), false, downloadService, this);
}
- for (MusicDirectory.Entry dir : musicDirectory.getChildren(true, false)) {
+ for (Entry dir : musicDirectory.getChildren(true, false)) {
if (dir.getRating() == 1) {
continue;
}
@@ -329,7 +330,7 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
getSongsRecursively(dir, songs);
}
- for (MusicDirectory.Entry song : musicDirectory.getChildren(false, true)) {
+ for (Entry song : musicDirectory.getChildren(false, true)) {
if (!song.isVideo() && song.getRating() != 1) {
songs.add(song);
}
@@ -349,16 +350,32 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
}
}.execute();
}
+ private void playMusicDirectory(final Entry dir, final boolean shuffle, final boolean append) {
+ new SilentServiceTask<Void>(downloadService) {
+ @Override
+ protected Void doInBackground(MusicService musicService) throws Throwable {
+ MusicDirectory musicDirectory;
+ if(Util.isTagBrowsing(downloadService) && !Util.isOffline(downloadService)) {
+ musicDirectory = musicService.getAlbum(dir.getId(), "dir", false, downloadService, null);
+ } else {
+ musicDirectory = musicService.getMusicDirectory(dir.getId(), "dir", false, downloadService, null);
+ }
+ playSongs(musicDirectory.getChildren(false, true), shuffle, append);
- private void playSong(MusicDirectory.Entry entry) {
- List<MusicDirectory.Entry> entries = new ArrayList<>();
+ return null;
+ }
+ }.execute();
+ }
+
+ private void playSong(Entry entry) {
+ List<Entry> entries = new ArrayList<>();
entries.add(entry);
playSongs(entries);
}
- private void playSongs(List<MusicDirectory.Entry> entries) {
+ private void playSongs(List<Entry> entries) {
playSongs(entries, false, false);
}
- private void playSongs(List<MusicDirectory.Entry> entries, boolean shuffle, boolean append) {
+ private void playSongs(List<Entry> entries, boolean shuffle, boolean append) {
if(!append) {
downloadService.clear();
}
@@ -467,6 +484,7 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
}
}
+ @Override
public void onPlayFromMediaId (String mediaId, Bundle extras) {
if(extras == null) {
return;
@@ -479,6 +497,11 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
Playlist playlist = new Playlist(playlistId, null);
playPlaylist(playlist, shuffle, playLast);
}
+ String musicDirectoryId = extras.getString(Constants.INTENT_EXTRA_NAME_ID);
+ if(musicDirectoryId != null) {
+ Entry dir = new Entry(musicDirectoryId);
+ playMusicDirectory(dir, shuffle, playLast);
+ }
}
@Override