diff options
author | Scott Jackson <daneren2005@gmail.com> | 2012-10-28 18:30:13 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2012-10-28 18:30:13 -0700 |
commit | b7ed3a4fc6405e2cf77e8fd7b2e53af6fbaa96d9 (patch) | |
tree | c08f4d4d94195946b4829fd61e5683abb21aaaa5 /subsonic-android/src/github/daneren2005 | |
parent | 444e784b4f50290d303c30c8dd45b0a95d5e2b0d (diff) | |
download | dsub-b7ed3a4fc6405e2cf77e8fd7b2e53af6fbaa96d9.tar.gz dsub-b7ed3a4fc6405e2cf77e8fd7b2e53af6fbaa96d9.tar.bz2 dsub-b7ed3a4fc6405e2cf77e8fd7b2e53af6fbaa96d9.zip |
Async a task which was commonly causing freezes on startup
Diffstat (limited to 'subsonic-android/src/github/daneren2005')
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java b/subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java index 63e5d1be..f87ddf52 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/CacheCleaner.java @@ -9,6 +9,7 @@ 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.service.DownloadFile; @@ -32,31 +33,7 @@ public class CacheCleaner { } public void clean() { - - Log.i(TAG, "Starting cache cleaning."); - - if (downloadService == null) { - Log.e(TAG, "DownloadService not set. Aborting cache cleaning."); - return; - } - - try { - - List<File> files = new ArrayList<File>(); - List<File> dirs = new ArrayList<File>(); - - findCandidatesForDeletion(FileUtil.getMusicDirectory(context), files, dirs); - sortByAscendingModificationTime(files); - - Set<File> undeletable = findUndeletableFiles(); - - deleteFiles(files, undeletable); - deleteEmptyDirs(dirs, undeletable); - Log.i(TAG, "Completed cache cleaning."); - - } catch (RuntimeException x) { - Log.e(TAG, "Error in cache cleaning.", x); - } + new BackgroundCleanup().execute(); } private void deleteEmptyDirs(List<File> dirs, Set<File> undeletable) { @@ -168,4 +145,31 @@ public class CacheCleaner { undeletable.add(FileUtil.getMusicDirectory(context)); return undeletable; } + + private class BackgroundCleanup extends AsyncTask<Void, Void, Void> { + @Override + protected Void doInBackground(Void... params) { + if (downloadService == null) { + Log.e(TAG, "DownloadService not set. Aborting cache cleaning."); + return null; + } + + try { + List<File> files = new ArrayList<File>(); + List<File> dirs = new ArrayList<File>(); + + findCandidatesForDeletion(FileUtil.getMusicDirectory(context), files, dirs); + sortByAscendingModificationTime(files); + + Set<File> undeletable = findUndeletableFiles(); + + deleteFiles(files, undeletable); + deleteEmptyDirs(dirs, undeletable); + } catch (RuntimeException x) { + Log.e(TAG, "Error in cache cleaning.", x); + } + + return null; + } + } } |