[Android] clear cache folder when emptying database

Sébastien Toque git at videolan.org
Mon Nov 11 18:12:38 CET 2013


vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Mon Nov 11 18:12:01 2013 +0100| [b7cc339e25f0450d77143165c0f78ad208325473] | committer: Sébastien Toque

clear cache folder when emptying database

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=b7cc339e25f0450d77143165c0f78ad208325473
---

 .../org/videolan/vlc/gui/PreferencesActivity.java  |    2 ++
 .../src/org/videolan/vlc/gui/audio/AudioUtil.java  |   23 +++++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index 1e0343c..20e6ae0 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -27,6 +27,7 @@ import org.videolan.vlc.BitmapCache;
 import org.videolan.vlc.MediaDatabase;
 import org.videolan.vlc.R;
 import org.videolan.vlc.Util;
+import org.videolan.vlc.gui.audio.AudioUtil;
 
 import android.app.AlertDialog;
 import android.content.Context;
@@ -143,6 +144,7 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
                     public boolean onPreferenceClick(Preference preference) {
                         MediaDatabase.getInstance(getBaseContext()).emptyDatabase();
                         BitmapCache.getInstance().clear();
+                        AudioUtil.clearCacheFolder();
                         Toast.makeText(getBaseContext(), R.string.media_db_cleared, Toast.LENGTH_SHORT).show();
                         return true;
                     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
index cc4116f..c56f532 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
@@ -58,6 +58,7 @@ public class AudioUtil {
     public final static String TAG = "VLC/AudioUtil";
 
     public static String CACHE_DIR = null;
+    public static String ART_DIR = null;
     public static String COVER_DIR = null;
     public static String PLAYLIST_DIR = null;
 
@@ -109,16 +110,36 @@ public class AudioUtil {
             CACHE_DIR = context.getExternalCacheDir().getPath();
         else
             CACHE_DIR = Environment.getExternalStorageDirectory().getPath() + "/Android/data/" + context.getPackageName() + "/cache";
+        ART_DIR = CACHE_DIR + "/art/";
         COVER_DIR = CACHE_DIR + "/covers/";
         PLAYLIST_DIR = CACHE_DIR + "/playlists/";
 
-        for(String path : Arrays.asList(COVER_DIR, PLAYLIST_DIR)) {
+        for(String path : Arrays.asList(ART_DIR, COVER_DIR, PLAYLIST_DIR)) {
             File file = new File(path);
             if (!file.exists())
                 file.mkdirs();
         }
     }
 
+    public static void clearCacheFolder() {
+        for(String path : Arrays.asList(ART_DIR, COVER_DIR, PLAYLIST_DIR)) {
+            File file = new File(path);
+            if (file.exists())
+                deleteContent(file, false);
+        }
+    }
+
+    private static void deleteContent(File dir, boolean deleteDir) {
+        if (dir.isDirectory()) {
+            File[] files = dir.listFiles();
+            for (File file : files) {
+                deleteContent(file, true);
+            }
+        }
+        if (deleteDir)
+            dir.delete();
+    }
+
     private static String getCoverFromMediaStore(Context context, Media media) {
         ContentResolver contentResolver = context.getContentResolver();
         Uri uri = android.provider.MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;



More information about the Android mailing list