From 6830fe76ed069a1cc141f887a49c165669074f6b Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 11 Jun 2013 23:36:05 -0700 Subject: Make offline playlist more robust + only show server name if there exists a playlist for more then one server --- .../dsub/service/OfflineMusicService.java | 29 +++++++++++++++++----- 1 file 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 getPlaylists(boolean refresh, Context context, ProgressListener progressListener) throws Exception { List playlists = new ArrayList(); 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); -- cgit v1.2.3