aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2012-07-06 20:36:08 -0700
committerScott Jackson <daneren2005@gmail.com>2012-07-06 20:36:08 -0700
commit28af3222ac09cf1b4118fa1a9f646d6ad9622e9d (patch)
tree1d5df5b4605e7c73f2020ff64c5323bc4f68d419 /subsonic-android
parentf7c41e5c9799ce3e589db1d4f58c4f83326e9455 (diff)
downloaddsub-28af3222ac09cf1b4118fa1a9f646d6ad9622e9d.tar.gz
dsub-28af3222ac09cf1b4118fa1a9f646d6ad9622e9d.tar.bz2
dsub-28af3222ac09cf1b4118fa1a9f646d6ad9622e9d.zip
Offline playlists
Diffstat (limited to 'subsonic-android')
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectAlbumActivity.java4
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SubsonicTabActivity.java1
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/CachedMusicService.java4
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/MusicService.java2
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/OfflineMusicService.java35
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/service/RESTMusicService.java21
-rw-r--r--subsonic-android/src/net/sourceforge/subsonic/androidapp/util/FileUtil.java10
7 files changed, 66 insertions, 11 deletions
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectAlbumActivity.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectAlbumActivity.java
index b354599f..070bed0b 100644
--- a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectAlbumActivity.java
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SelectAlbumActivity.java
@@ -279,13 +279,13 @@ public class SelectAlbumActivity extends SubsonicTabActivity {
}.execute();
}
- private void getPlaylist(final String playlistId, String playlistName) {
+ private void getPlaylist(final String playlistId, final String playlistName) {
setTitle(playlistName);
new LoadTask() {
@Override
protected MusicDirectory load(MusicService service) throws Exception {
- return service.getPlaylist(playlistId, SelectAlbumActivity.this, this);
+ return service.getPlaylist(playlistId, playlistName, SelectAlbumActivity.this, this);
}
}.execute();
}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SubsonicTabActivity.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SubsonicTabActivity.java
index 8c9c0687..f75e39fc 100644
--- a/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SubsonicTabActivity.java
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/activity/SubsonicTabActivity.java
@@ -240,7 +240,6 @@ public class SubsonicTabActivity extends Activity {
private void updateButtonVisibility() {
int visibility = Util.isOffline(this) ? View.GONE : View.VISIBLE;
searchButton.setVisibility(visibility);
- playlistButton.setVisibility(visibility);
}
public void setProgressVisible(boolean visible) {
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);
}
diff --git a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/FileUtil.java b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/FileUtil.java
index 6cdd6fb1..88d10d3e 100644
--- a/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/FileUtil.java
+++ b/subsonic-android/src/net/sourceforge/subsonic/androidapp/util/FileUtil.java
@@ -70,6 +70,16 @@ public class FileUtil {
return new File(dir, fileName.toString());
}
+
+ public static File getPlaylistFile(String id) {
+ File playlistDir = getPlaylistDirectory();
+ return new File(playlistDir, id);
+ }
+ public static File getPlaylistDirectory() {
+ File playlistDir = new File(getSubsonicDirectory(), "playlists");
+ ensureDirectoryExistsAndIsReadWritable(playlistDir);
+ return playlistDir;
+ }
public static File getAlbumArtFile(Context context, MusicDirectory.Entry entry) {
File albumDir = getAlbumDirectory(context, entry);