diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-07-09 22:25:20 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-07-09 22:25:20 -0700 |
commit | 232f308d7161e4f68ce8f2beecaf25e709988d4d (patch) | |
tree | d5229a2c2b288a0dbbf51fb9464593662aefcd77 /subsonic-android/src/github/daneren2005 | |
parent | 5b15bbbd63e77d2a5e82cb20dcc9ff46fea1bf49 (diff) | |
download | dsub-232f308d7161e4f68ce8f2beecaf25e709988d4d.tar.gz dsub-232f308d7161e4f68ce8f2beecaf25e709988d4d.tar.bz2 dsub-232f308d7161e4f68ce8f2beecaf25e709988d4d.zip |
Add offline support for podcasts
Diffstat (limited to 'subsonic-android/src/github/daneren2005')
4 files changed, 49 insertions, 5 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 547eb0f3..9d34011e 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -221,10 +221,10 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position);
onCreateContextMenu(menu, view, menuInfo, entry);
- if(!entry.isVideo() && !Util.isOffline(context) && playlistId == null && podcastId != null) {
+ if(!entry.isVideo() && !Util.isOffline(context) && playlistId == null && (podcastId != null || Util.isOffline(context) && podcastId == null)) {
menu.removeItem(R.id.song_menu_remove_playlist);
}
- if(podcastId != null) {
+ if(podcastId != null && !Util.isOffline(context)) {
String status = ((PodcastEpisode)entry).getStatus();
if("completed".equals(status)) {
menu.removeItem(R.id.song_menu_server_download);
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java index 3bb30bc1..0a3b0f55 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -602,12 +602,31 @@ public class OfflineMusicService extends RESTMusicService { @Override public List<PodcastChannel> getPodcastChannels(boolean refresh, Context context, ProgressListener progressListener) throws Exception { - throw new OfflineException("Getting Podcasts not available in offline mode"); + List<PodcastChannel> channels = new ArrayList<PodcastChannel>(); + + File dir = FileUtil.getPodcastDirectory(context); + String line; + for(File file: dir.listFiles()) { + BufferedReader br = new BufferedReader(new FileReader(file)); + while ((line = br.readLine()) != null && !"".equals(line)) { + PodcastChannel channel = new PodcastChannel(); + channel.setId(line); + channel.setName(line); + channel.setStatus("completed"); + + if(FileUtil.getPodcastDirectory(context, channel).exists()) { + channels.add(channel); + } + } + br.close(); + } + + return channels; } @Override public MusicDirectory getPodcastEpisodes(String id, Context context, ProgressListener progressListener) throws Exception { - throw new OfflineException("Getting Podcasts not available in offline mode"); + return getMusicDirectory(FileUtil.getPodcastDirectory(context, id).getPath(), null, false, context, progressListener); } @Override diff --git a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java index a002dcb6..fddff16a 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -892,7 +892,19 @@ public class RESTMusicService implements MusicService { Reader reader = getReader(context, progressListener, "getPodcasts", null, Arrays.asList("includeEpisodes"), Arrays.<Object>asList("false")); try { - return new PodcastChannelParser(context).parse(reader, progressListener); + List<PodcastChannel> channels = new PodcastChannelParser(context).parse(reader, progressListener); + + String content = ""; + for(PodcastChannel channel: channels) { + content += channel.getName() + "\n"; + } + + File file = FileUtil.getPodcastFile(context, Util.getServerName(context)); + BufferedWriter bw = new BufferedWriter(new FileWriter(file)); + bw.write(content); + bw.close(); + + return channels; } finally { Util.close(reader); } diff --git a/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java b/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java index 267db36c..44be1921 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java @@ -152,10 +152,23 @@ public class FileUtil { return dir; } + public static File getPodcastFile(Context context, String server) { + File dir = getPodcastDirectory(context); + return new File(dir.getPath() + "/" + fileSystemSafe(server)); + } + public static File getPodcastDirectory(Context context) { + File dir = new File(getSubsonicDirectory(), "podcasts"); + ensureDirectoryExistsAndIsReadWritable(dir); + return dir; + } public static File getPodcastDirectory(Context context, PodcastChannel channel) { File dir = new File(getMusicDirectory(context).getPath() + "/" + fileSystemSafe(channel.getName())); return dir; } + public static File getPodcastDirectory(Context context, String channel) { + File dir = new File(getMusicDirectory(context).getPath() + "/" + fileSystemSafe(channel)); + return dir; + } public static void createDirectoryForParent(File file) { File dir = file.getParentFile(); |