[Android] Recursive check when adding a directory

Geoffrey Métais git at videolan.org
Tue May 12 14:40:50 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon May 11 14:52:48 2015 +0200| [12e4064860eb9d9ccd5efa386cb2bb67b2d56f24] | committer: Geoffrey Métais

Recursive check when adding a directory

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

 .../vlc/gui/browser/BaseBrowserAdapter.java        |   20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
index 8df2bd7..fda65e5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -188,9 +188,9 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
                 public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                     String path = ((Storage)getItem(vh.getAdapterPosition())).getPath();
                     updateMediaDirs();
-                    if (isChecked)
-                        mDbManager.addDir(path);
-                    else {
+                    if (isChecked) {
+                        addDir(path);
+                    } else {
                         if (mMediaDirsLocation == null || mMediaDirsLocation.isEmpty()){
                             String storagePath;
                             for (Object storage : mMediaList){
@@ -222,6 +222,20 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
             vh.checkBox.setEnabled(false);
     }
 
+    private void addDir(final String path) {
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+                mDbManager.addDir(path);
+                File tmpFile = new File(path).getParentFile();
+                while (tmpFile != null && !tmpFile.getPath().equals("/")) {
+                    mDbManager.removeDir(tmpFile.getPath());
+                    tmpFile = tmpFile.getParentFile();
+                }
+            }
+        }).start();
+    }
+
     @Override
     public int getItemCount() {
         return mMediaList.size();



More information about the Android mailing list