diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-06-11 23:18:52 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-06-11 23:18:52 -0700 |
commit | d911009367f5b72ad8705c0e982a65a5edb70fd5 (patch) | |
tree | 62d8722470666c1dbbcac47170a1a61132520e24 /subsonic-android/src/github | |
parent | 5140598a4047406aa4df0faeaabb2439f48166fe (diff) | |
download | dsub-d911009367f5b72ad8705c0e982a65a5edb70fd5.tar.gz dsub-d911009367f5b72ad8705c0e982a65a5edb70fd5.tar.bz2 dsub-d911009367f5b72ad8705c0e982a65a5edb70fd5.zip |
Close #137 Break down playlists into separate server categories
Diffstat (limited to 'subsonic-android/src/github')
6 files changed, 37 insertions, 20 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java index af8f7cf7..83d13bc3 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -346,18 +346,22 @@ 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(); - for (File file : FileUtil.listFiles(root)) { - if(FileUtil.isPlaylistFile(file)) { - String id = file.getName(); - String filename = FileUtil.getBaseName(id); - Playlist playlist = new Playlist(id, filename); - playlists.add(playlist); + for (File folder : FileUtil.listFiles(root)) { + if(folder.isDirectory()) { + 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); + playlists.add(playlist); + } + } } else { // Delete legacy playlist files try { - file.delete(); + folder.delete(); } catch(Exception e) { - Log.w(TAG, "Failed to delete old playlist file: " + file.getName()); + Log.w(TAG, "Failed to delete old playlist file: " + folder.getName()); } } } @@ -374,7 +378,11 @@ public class OfflineMusicService extends RESTMusicService { Reader reader = null; BufferedReader buffer = null; try { - File playlistFile = FileUtil.getPlaylistFile(name); + int firstIndex = name.indexOf(": "); + String server = name.substring(0, firstIndex); + name = name.substring(firstIndex + 2); + + File playlistFile = FileUtil.getPlaylistFile(server, name); reader = new FileReader(playlistFile); buffer = new BufferedReader(reader); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java index 1f283a3b..e12c4024 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -330,7 +330,7 @@ public class RESTMusicService implements MusicService { try { MusicDirectory playlist = new PlaylistParser(context).parse(reader, progressListener); - File playlistFile = FileUtil.getPlaylistFile(name); + File playlistFile = FileUtil.getPlaylistFile(Util.getServerName(context), name); FileWriter fw = new FileWriter(playlistFile); BufferedWriter bw = new BufferedWriter(fw); try { diff --git a/subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java b/subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java index 44de369f..62204c76 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java @@ -219,10 +219,11 @@ public class CacheCleaner { @Override protected Void doInBackground(List<Playlist>... params) { try { - SortedSet<File> playlistFiles = FileUtil.listFiles(FileUtil.getPlaylistDirectory()); + String server = Util.getServerName(context); + SortedSet<File> playlistFiles = FileUtil.listFiles(FileUtil.getPlaylistDirectory(server)); List<Playlist> playlists = params[0]; for (Playlist playlist : playlists) { - playlistFiles.remove(FileUtil.getPlaylistFile(playlist.getName())); + playlistFiles.remove(FileUtil.getPlaylistFile(server, playlist.getName())); } for(File playlist : playlistFiles) { diff --git a/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java b/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java index 7ead874c..e63b3d76 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java @@ -93,19 +93,20 @@ public class FileUtil { return new File(dir, fileName.toString()); } - public static File getPlaylistFile(String name) { - File playlistDir = getPlaylistDirectory(); + public static File getPlaylistFile(String server, String name) { + File playlistDir = getPlaylistDirectory(server); return new File(playlistDir, fileSystemSafe(name) + ".m3u"); } - public static File getOldPlaylistFile(String name) { - File playlistDir = getPlaylistDirectory(); - return new File(playlistDir, name); - } public static File getPlaylistDirectory() { File playlistDir = new File(getSubsonicDirectory(), "playlists"); ensureDirectoryExistsAndIsReadWritable(playlistDir); return playlistDir; } + public static File getPlaylistDirectory(String server) { + File playlistDir = new File(getPlaylistDirectory(), server); + ensureDirectoryExistsAndIsReadWritable(playlistDir); + return playlistDir; + } public static File getAlbumArtFile(Context context, MusicDirectory.Entry entry) { File albumDir = getAlbumDirectory(context, entry); diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java index 650d071d..8ff80bb7 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java @@ -218,6 +218,11 @@ public final class Util { } } + public static String getServerName(Context context) { + SharedPreferences prefs = getPreferences(context); + int instance = prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); + return prefs.getString(Constants.PREFERENCES_KEY_SERVER_NAME + instance, null); + } public static String getServerName(Context context, int instance) { SharedPreferences prefs = getPreferences(context); return prefs.getString(Constants.PREFERENCES_KEY_SERVER_NAME + instance, null); diff --git a/subsonic-android/src/github/daneren2005/dsub/view/PlaylistView.java b/subsonic-android/src/github/daneren2005/dsub/view/PlaylistView.java index effd5a98..876e0691 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/PlaylistView.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/PlaylistView.java @@ -37,6 +37,7 @@ import java.io.File; public class PlaylistView extends UpdateView {
private static final String TAG = PlaylistView.class.getSimpleName();
+ private Context context;
private Playlist playlist;
private TextView titleView;
@@ -44,6 +45,7 @@ public class PlaylistView extends UpdateView { public PlaylistView(Context context) {
super(context);
+ this.context = context;
LayoutInflater.from(context).inflate(R.layout.playlist_list_item, this, true);
titleView = (TextView) findViewById(R.id.playlist_name);
@@ -64,8 +66,8 @@ public class PlaylistView extends UpdateView { @Override
protected void update() {
- File file = FileUtil.getPlaylistFile(playlist.getName());
- if(file.exists()) {
+ File file = FileUtil.getPlaylistFile(Util.getServerName(context), playlist.getName());
+ if(file.exists() || Util.isOffline(context)) {
moreButton.setImageResource(R.drawable.list_item_more_shaded);
} else {
moreButton.setImageResource(R.drawable.list_item_more);
|