diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-06-11 23:36:05 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-06-11 23:36:05 -0700 |
commit | 6830fe76ed069a1cc141f887a49c165669074f6b (patch) | |
tree | d5ce36795bef2a3bfeb5dabe853de99e3237003f | |
parent | d911009367f5b72ad8705c0e982a65a5edb70fd5 (diff) | |
download | dsub-6830fe76ed069a1cc141f887a49c165669074f6b.tar.gz dsub-6830fe76ed069a1cc141f887a49c165669074f6b.tar.bz2 dsub-6830fe76ed069a1cc141f887a49c165669074f6b.zip |
Make offline playlist more robust + only show server name if there exists a playlist for more then one server
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java index 83d13bc3..adc3a9e0 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -346,16 +346,26 @@ public class OfflineMusicService extends RESTMusicService { public List<Playlist> getPlaylists(boolean refresh, Context context, ProgressListener progressListener) throws Exception { List<Playlist> playlists = new ArrayList<Playlist>(); File root = FileUtil.getPlaylistDirectory(); + String lastServer = null; + boolean removeServer = true; for (File folder : FileUtil.listFiles(root)) { if(folder.isDirectory()) { + String server = folder.getName(); for(File file: FileUtil.listFiles(folder)) { if(FileUtil.isPlaylistFile(file)) { String id = file.getName(); - String filename = folder.getName() + ": " + FileUtil.getBaseName(id); - Playlist playlist = new Playlist(id, filename); + String filename = server + ": " + FileUtil.getBaseName(id); + Playlist playlist = new Playlist(server, filename); playlists.add(playlist); } } + + if(!server.equals(lastServer)) { + if(lastServer != null) { + removeServer = false; + } + lastServer = server; + } } else { // Delete legacy playlist files try { @@ -365,6 +375,12 @@ public class OfflineMusicService extends RESTMusicService { } } } + + if(removeServer) { + for(Playlist playlist: playlists) { + playlist.setName(playlist.getName().substring(playlist.getId().length() + 2)); + } + } return playlists; } @@ -378,11 +394,12 @@ public class OfflineMusicService extends RESTMusicService { Reader reader = null; BufferedReader buffer = null; try { - int firstIndex = name.indexOf(": "); - String server = name.substring(0, firstIndex); - name = name.substring(firstIndex + 2); + int firstIndex = name.indexOf(id); + if(firstIndex != -1) { + name = name.substring(id.length() + 2); + } - File playlistFile = FileUtil.getPlaylistFile(server, name); + File playlistFile = FileUtil.getPlaylistFile(id, name); reader = new FileReader(playlistFile); buffer = new BufferedReader(reader); |