diff options
Diffstat (limited to 'subsonic-android/src/net/sourceforge/subsonic/androidapp/service')
4 files changed, 54 insertions, 8 deletions
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/CachedMusicService.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/CachedMusicService.java index a06f3995..14aed954 100644 --- a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/CachedMusicService.java +++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/CachedMusicService.java @@ -128,8 +128,8 @@ public class CachedMusicService implements MusicService { } @Override - public MusicDirectory getPlaylist(String id, Context context, ProgressListener progressListener) throws Exception { - return musicService.getPlaylist(id, context, progressListener); + public MusicDirectory getPlaylist(String id, String name, Context context, ProgressListener progressListener) throws Exception { + return musicService.getPlaylist(id, name, context, progressListener); } @Override diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MusicService.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MusicService.java index 2acb4c65..cb0c5709 100644 --- a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MusicService.java +++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MusicService.java @@ -53,7 +53,7 @@ public interface MusicService { SearchResult search(SearchCritera criteria, Context context, ProgressListener progressListener) throws Exception; - MusicDirectory getPlaylist(String id, Context context, ProgressListener progressListener) throws Exception; + MusicDirectory getPlaylist(String id, String name, Context context, ProgressListener progressListener) throws Exception; List<Playlist> getPlaylists(boolean refresh, Context context, ProgressListener progressListener) throws Exception; diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/OfflineMusicService.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/OfflineMusicService.java index 6a8ad6d0..79fee6d2 100644 --- a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/OfflineMusicService.java +++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/OfflineMusicService.java @@ -21,6 +21,8 @@ package net.sourceforge.subsonic.androidapp.service; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; +import java.io.Reader; +import java.io.FileReader; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -41,6 +43,7 @@ import net.sourceforge.subsonic.androidapp.domain.MusicFolder; import net.sourceforge.subsonic.androidapp.domain.Playlist; import net.sourceforge.subsonic.androidapp.domain.SearchCritera; import net.sourceforge.subsonic.androidapp.domain.SearchResult; +import net.sourceforge.subsonic.androidapp.service.parser.PlaylistParser; import net.sourceforge.subsonic.androidapp.util.Constants; import net.sourceforge.subsonic.androidapp.util.FileUtil; import net.sourceforge.subsonic.androidapp.util.ProgressListener; @@ -150,12 +153,38 @@ public class OfflineMusicService extends RESTMusicService { @Override public List<Playlist> getPlaylists(boolean refresh, Context context, ProgressListener progressListener) throws Exception { - throw new OfflineException("Playlists not available in offline mode"); + List<Playlist> playlists = new ArrayList<Playlist>(); + File root = FileUtil.getPlaylistDirectory(); + for (File file : FileUtil.listFiles(root)) { + Playlist playlist = new Playlist(file.getName(), file.getName()); + playlists.add(playlist); + } + return playlists; } @Override - public MusicDirectory getPlaylist(String id, Context context, ProgressListener progressListener) throws Exception { - throw new OfflineException("Playlists not available in offline mode"); + public MusicDirectory getPlaylist(String id, String name, Context context, ProgressListener progressListener) throws Exception { + DownloadService downloadService = DownloadServiceImpl.getInstance(); + if (downloadService == null) { + return new MusicDirectory(); + } + + Reader reader = null; + try { + reader = new FileReader(FileUtil.getPlaylistFile(name)); + MusicDirectory fullList = new PlaylistParser(context).parse(reader, progressListener); + MusicDirectory playlist = new MusicDirectory(); + for(MusicDirectory.Entry song: fullList.getChildren()) { + DownloadFile downloadFile = downloadService.forSong(song); + File completeFile = downloadFile.getCompleteFile(); + if(completeFile.exists()) { + playlist.addChild(song); + } + } + return playlist; + } finally { + Util.close(reader); + } } @Override diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/RESTMusicService.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/RESTMusicService.java index 1d99f2d9..a939feef 100644 --- a/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/RESTMusicService.java +++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/service/RESTMusicService.java @@ -22,7 +22,9 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.FileReader; import java.io.OutputStream; +import java.io.OutputStreamWriter; import java.io.Reader; import java.net.URLEncoder; import java.util.ArrayList; @@ -317,13 +319,28 @@ public class RESTMusicService implements MusicService { } @Override - public MusicDirectory getPlaylist(String id, Context context, ProgressListener progressListener) throws Exception { + public MusicDirectory getPlaylist(String id, String name, Context context, ProgressListener progressListener) throws Exception { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setSoTimeout(params, SOCKET_READ_TIMEOUT_GET_PLAYLIST); Reader reader = getReader(context, progressListener, "getPlaylist", params, "id", id); + OutputStreamWriter out = null; + try { + out = new OutputStreamWriter(new FileOutputStream(FileUtil.getPlaylistFile(name))); + + char[] buff = new char[256]; + int n; + while((n = reader.read(buff)) >= 0) { + out.write(buff, 0, n); + } + } finally { + Util.close(out); + Util.close(reader); + } + try { - return new PlaylistParser(context).parse(reader, progressListener); + reader = new FileReader(FileUtil.getPlaylistFile(name)); + return new PlaylistParser(context).parse(reader, progressListener); } finally { Util.close(reader); } |