aboutsummaryrefslogtreecommitdiff
path: root/src/github
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-02-09 15:59:42 -0800
committerScott Jackson <daneren2005@gmail.com>2015-02-09 15:59:42 -0800
commit7b393cf7061c3e60601b14961ca99f1de94531ff (patch)
tree9bdbd2e895eb8b748d027d9c430ca87ce7f6adc4 /src/github
parent8f29e6ab5210235a1e821df905097a8ee3e89736 (diff)
downloaddsub-7b393cf7061c3e60601b14961ca99f1de94531ff.tar.gz
dsub-7b393cf7061c3e60601b14961ca99f1de94531ff.tar.bz2
dsub-7b393cf7061c3e60601b14961ca99f1de94531ff.zip
Move recursiveDelete/deleteEmptyDir to FileUtil
Diffstat (limited to 'src/github')
-rw-r--r--src/github/daneren2005/dsub/fragments/SubsonicFragment.java2
-rw-r--r--src/github/daneren2005/dsub/service/CachedMusicService.java3
-rw-r--r--src/github/daneren2005/dsub/util/CacheCleaner.java13
-rw-r--r--src/github/daneren2005/dsub/util/FileUtil.java51
-rw-r--r--src/github/daneren2005/dsub/util/Util.java45
5 files changed, 48 insertions, 66 deletions
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
index 6128e4ee..0cb044e3 100644
--- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -1362,7 +1362,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
@Override
protected Void doInBackground() throws Throwable {
MediaStoreService mediaStore = new MediaStoreService(context);
- Util.recursiveDelete(dir, mediaStore);
+ FileUtil.recursiveDelete(dir, mediaStore);
return null;
}
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java
index 38508e42..124ae615 100644
--- a/src/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/src/github/daneren2005/dsub/service/CachedMusicService.java
@@ -30,7 +30,6 @@ import org.apache.http.HttpResponse;
import android.content.Context;
import android.graphics.Bitmap;
-import android.util.Log;
import github.daneren2005.dsub.domain.Artist;
import github.daneren2005.dsub.domain.ArtistInfo;
@@ -947,7 +946,7 @@ public class CachedMusicService implements MusicService {
MediaStoreService store = new MediaStoreService(context);
for(Entry entry: oldList) {
File file = FileUtil.getEntryFile(context, entry);
- Util.recursiveDelete(file, store);
+ FileUtil.recursiveDelete(file, store);
}
}
}
diff --git a/src/github/daneren2005/dsub/util/CacheCleaner.java b/src/github/daneren2005/dsub/util/CacheCleaner.java
index d07b0f4e..ac8fa72a 100644
--- a/src/github/daneren2005/dsub/util/CacheCleaner.java
+++ b/src/github/daneren2005/dsub/util/CacheCleaner.java
@@ -54,18 +54,7 @@ public class CacheCleaner {
continue;
}
- File[] children = dir.listFiles();
-
- // No songs left in the folder
- if(children.length == 1 && children[0].getPath().equals(FileUtil.getAlbumArtFile(dir).getPath())) {
- Util.delete(children[0]);
- children = dir.listFiles();
- }
-
- // Delete empty directory
- if (children.length == 0) {
- Util.delete(dir);
- }
+ FileUtil.deleteEmptyDir(dir);
}
}
diff --git a/src/github/daneren2005/dsub/util/FileUtil.java b/src/github/daneren2005/dsub/util/FileUtil.java
index 34838f33..fbfa6af0 100644
--- a/src/github/daneren2005/dsub/util/FileUtil.java
+++ b/src/github/daneren2005/dsub/util/FileUtil.java
@@ -24,7 +24,6 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
-import java.io.FilenameFilter;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.Serializable;
@@ -35,7 +34,6 @@ import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Iterator;
import java.util.List;
-import java.util.zip.DeflaterInputStream;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
@@ -44,7 +42,6 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
-import android.os.Environment;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import github.daneren2005.dsub.domain.Artist;
@@ -54,7 +51,6 @@ import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.domain.PodcastChannel;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.MusicFolder;
-import github.daneren2005.dsub.domain.PodcastChannel;
import github.daneren2005.dsub.domain.PodcastEpisode;
import github.daneren2005.dsub.service.MediaStoreService;
@@ -460,7 +456,7 @@ public class FileUtil {
public static boolean deleteMusicDirectory(Context context) {
File musicDirectory = FileUtil.getMusicDirectory(context);
MediaStoreService mediaStore = new MediaStoreService(context);
- return Util.recursiveDelete(musicDirectory, mediaStore);
+ return recursiveDelete(musicDirectory, mediaStore);
}
public static void deleteSerializedCache(Context context) {
for(File file: context.getCacheDir().listFiles()) {
@@ -471,11 +467,52 @@ public class FileUtil {
}
public static boolean deleteArtworkCache(Context context) {
File artDirectory = FileUtil.getAlbumArtDirectory(context);
- return Util.recursiveDelete(artDirectory);
+ return recursiveDelete(artDirectory);
}
public static boolean deleteAvatarCache(Context context) {
File artDirectory = FileUtil.getAvatarDirectory(context);
- return Util.recursiveDelete(artDirectory);
+ return recursiveDelete(artDirectory);
+ }
+
+ public static boolean recursiveDelete(File dir) {
+ return recursiveDelete(dir, null);
+ }
+ public static boolean recursiveDelete(File dir, MediaStoreService mediaStore) {
+ if (dir != null && dir.exists()) {
+ File[] list = dir.listFiles();
+ if(list != null) {
+ for(File file: list) {
+ if(file.isDirectory()) {
+ if(!recursiveDelete(file, mediaStore)) {
+ return false;
+ }
+ } else if(file.exists()) {
+ if(!file.delete()) {
+ return false;
+ } else if(mediaStore != null) {
+ mediaStore.deleteFromMediaStore(file);
+ }
+ }
+ }
+ }
+ return dir.delete();
+ }
+ return false;
+ }
+
+ public static void deleteEmptyDir(File dir) {
+ File[] children = dir.listFiles();
+
+ // No songs left in the folder
+ if(children.length == 1 && children[0].getPath().equals(FileUtil.getAlbumArtFile(dir).getPath())) {
+ Util.delete(children[0]);
+ children = dir.listFiles();
+ }
+
+ // Delete empty directory
+ if (children.length == 0) {
+ Util.delete(dir);
+ }
}
public static void unpinSong(Context context, File saveFile) {
diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java
index 83bedfc8..aa12f941 100644
--- a/src/github/daneren2005/dsub/util/Util.java
+++ b/src/github/daneren2005/dsub/util/Util.java
@@ -53,7 +53,6 @@ import github.daneren2005.dsub.domain.PlayerState;
import github.daneren2005.dsub.domain.RepeatMode;
import github.daneren2005.dsub.receiver.MediaButtonIntentReceiver;
import github.daneren2005.dsub.service.DownloadService;
-import github.daneren2005.dsub.service.MediaStoreService;
import org.apache.http.HttpEntity;
@@ -601,50 +600,8 @@ public final class Util {
}
return true;
}
- public static boolean recursiveDelete(File dir) {
- if (dir != null && dir.exists()) {
- File[] list = dir.listFiles();
- if(list != null) {
- for(File file: list) {
- if(file.isDirectory()) {
- if(!recursiveDelete(file)) {
- return false;
- }
- } else if(file.exists()) {
- if(!file.delete()) {
- return false;
- }
- }
- }
- }
- return dir.delete();
- }
- return false;
- }
- public static boolean recursiveDelete(File dir, MediaStoreService mediaStore) {
- if (dir != null && dir.exists()) {
- File[] list = dir.listFiles();
- if(list != null) {
- for(File file: list) {
- if(file.isDirectory()) {
- if(!recursiveDelete(file, mediaStore)) {
- return false;
- }
- } else if(file.exists()) {
- if(!file.delete()) {
- return false;
- } else {
- mediaStore.deleteFromMediaStore(file);
- }
- }
- }
- }
- return dir.delete();
- }
- return false;
- }
- public static void toast(Context context, int messageId) {
+ public static void toast(Context context, int messageId) {
toast(context, messageId, true);
}