diff options
Diffstat (limited to 'src/github')
-rw-r--r-- | src/github/daneren2005/dsub/util/CacheCleaner.java | 49 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/util/SilentBackgroundTask.java | 5 |
2 files changed, 36 insertions, 18 deletions
diff --git a/src/github/daneren2005/dsub/util/CacheCleaner.java b/src/github/daneren2005/dsub/util/CacheCleaner.java index 102c1dc9..273ed05f 100644 --- a/src/github/daneren2005/dsub/util/CacheCleaner.java +++ b/src/github/daneren2005/dsub/util/CacheCleaner.java @@ -9,7 +9,6 @@ import java.util.List; import java.util.Set; import android.content.Context; -import android.os.AsyncTask; import android.util.Log; import android.os.StatFs; import github.daneren2005.dsub.domain.Playlist; @@ -35,13 +34,13 @@ public class CacheCleaner { } public void clean() { - new BackgroundCleanup().execute(); + new BackgroundCleanup(context).execute(); } public void cleanSpace() { - new BackgroundSpaceCleanup().execute(); + new BackgroundSpaceCleanup(context).execute(); } public void cleanPlaylists(List<Playlist> playlists) { - new BackgroundPlaylistsCleanup().execute(playlists); + new BackgroundPlaylistsCleanup(context, playlists).execute(); } private void deleteEmptyDirs(List<File> dirs, Set<File> undeletable) { @@ -166,9 +165,13 @@ public class CacheCleaner { return undeletable; } - private class BackgroundCleanup extends AsyncTask<Void, Void, Void> { + private class BackgroundCleanup extends SilentBackgroundTask<Void> { + public BackgroundCleanup(Context context) { + super(context); + } + @Override - protected Void doInBackground(Void... params) { + protected Void doInBackground() { if (downloadService == null) { Log.e(TAG, "DownloadService not set. Aborting cache cleaning."); return null; @@ -189,14 +192,18 @@ public class CacheCleaner { } catch (RuntimeException x) { Log.e(TAG, "Error in cache cleaning.", x); } - + return null; } } - - private class BackgroundSpaceCleanup extends AsyncTask<Void, Void, Void> { + + private class BackgroundSpaceCleanup extends SilentBackgroundTask<Void> { + public BackgroundSpaceCleanup(Context context) { + super(context); + } + @Override - protected Void doInBackground(Void... params) { + protected Void doInBackground() { if (downloadService == null) { Log.e(TAG, "DownloadService not set. Aborting cache cleaning."); return null; @@ -207,7 +214,7 @@ public class CacheCleaner { List<File> pinned = new ArrayList<File>(); List<File> dirs = new ArrayList<File>(); findCandidatesForDeletion(FileUtil.getMusicDirectory(context), files, pinned, dirs); - + long bytesToDelete = getMinimumDelete(files, pinned); if(bytesToDelete > 0L) { sortByAscendingModificationTime(files); @@ -217,29 +224,35 @@ public class CacheCleaner { } catch (RuntimeException x) { Log.e(TAG, "Error in cache cleaning.", x); } - + return null; } } - - private class BackgroundPlaylistsCleanup extends AsyncTask<List<Playlist>, Void, Void> { + + private class BackgroundPlaylistsCleanup extends SilentBackgroundTask<Void> { + private final List<Playlist> playlists; + + public BackgroundPlaylistCleanup(Context context, List<Playlist> playlists) { + super(context); + this.playlists = playlists; + } + @Override - protected Void doInBackground(List<Playlist>... params) { + protected Void doInBackground() { try { 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(server, playlist.getName())); } - + for(File playlist : playlistFiles) { playlist.delete(); } } catch (RuntimeException x) { Log.e(TAG, "Error in playlist cache cleaning.", x); } - + return null; } } diff --git a/src/github/daneren2005/dsub/util/SilentBackgroundTask.java b/src/github/daneren2005/dsub/util/SilentBackgroundTask.java index a0db7ca4..b99b7e0e 100644 --- a/src/github/daneren2005/dsub/util/SilentBackgroundTask.java +++ b/src/github/daneren2005/dsub/util/SilentBackgroundTask.java @@ -33,6 +33,11 @@ public abstract class SilentBackgroundTask<T> extends BackgroundTask<T> { queue.offer(task = new Task()); } + @Override + protected void done(T result) { + // Don't do anything unless overriden + } + @Override public void updateProgress(int messageId) { } |