aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src/github
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2012-11-10 18:26:03 -0800
committerScott Jackson <daneren2005@gmail.com>2012-11-10 18:26:03 -0800
commitc6bf2a4c690bdfe416f7f3be919eec63a461ff28 (patch)
tree1a01a728b074cc9fcac4426827d54459d7d27dd0 /subsonic-android/src/github
parent662f6cd23c23aa798e9023d6a7b43208e1c77529 (diff)
downloaddsub-c6bf2a4c690bdfe416f7f3be919eec63a461ff28.tar.gz
dsub-c6bf2a4c690bdfe416f7f3be919eec63a461ff28.tar.bz2
dsub-c6bf2a4c690bdfe416f7f3be919eec63a461ff28.zip
Cleanup old playlists which are no longer valid #51
Diffstat (limited to 'subsonic-android/src/github')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java6
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java26
2 files changed, 31 insertions, 1 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java
index d667d3ff..84a10d08 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java
@@ -97,12 +97,16 @@ public class SelectPlaylistActivity extends SubsonicTabActivity implements Adapt
}
private void load() {
+ final SelectPlaylistActivity me = this;
BackgroundTask<List<Playlist>> task = new TabActivityBackgroundTask<List<Playlist>>(this) {
@Override
protected List<Playlist> doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this);
boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
- return musicService.getPlaylists(refresh, SelectPlaylistActivity.this, this);
+ List<Playlist> playlists = musicService.getPlaylists(refresh, SelectPlaylistActivity.this, this);
+ if(!Util.isOffline(me))
+ new CacheCleaner(me, getDownloadService()).cleanPlaylists(playlists);
+ return playlists;
}
@Override
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java b/subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java
index f87ddf52..7b96197c 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java
@@ -12,8 +12,10 @@ import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.os.StatFs;
+import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.service.DownloadFile;
import github.daneren2005.dsub.service.DownloadService;
+import java.util.*;
/**
* @author Sindre Mehus
@@ -35,6 +37,9 @@ public class CacheCleaner {
public void clean() {
new BackgroundCleanup().execute();
}
+ public void cleanPlaylists(List<Playlist> playlists) {
+ new BackgroundPlaylistsCleanup().execute(playlists);
+ }
private void deleteEmptyDirs(List<File> dirs, Set<File> undeletable) {
for (File dir : dirs) {
@@ -172,4 +177,25 @@ public class CacheCleaner {
return null;
}
}
+
+ private class BackgroundPlaylistsCleanup extends AsyncTask<List<Playlist>, Void, Void> {
+ @Override
+ protected Void doInBackground(List<Playlist>... params) {
+ try {
+ SortedSet<File> playlistFiles = FileUtil.listFiles(FileUtil.getPlaylistDirectory());
+ List<Playlist> playlists = params[0];
+ for (Playlist playlist : playlists) {
+ playlistFiles.remove(FileUtil.getPlaylistFile(playlist.getName()));
+ }
+
+ for(File playlist : playlistFiles) {
+ playlist.delete();
+ }
+ } catch (RuntimeException x) {
+ Log.e(TAG, "Error in playlist cache cleaning.", x);
+ }
+
+ return null;
+ }
+ }
}