[Android] Check custom directories existence

Geoffrey Métais git at videolan.org
Tue May 19 14:53:33 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue May 19 14:52:14 2015 +0200| [af6514488d1aed3902e8da006d3698a9fbdf75c5] | committer: Geoffrey Métais

Check custom directories existence

Fixes #10497

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

 .../vlc/gui/browser/FileBrowserFragment.java       |   44 +++++++++++++-------
 1 file changed, 29 insertions(+), 15 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
index 7d018e8..eba8d6c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
@@ -23,6 +23,7 @@
 
 package org.videolan.vlc.gui.browser;
 
+import android.app.Activity;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.DialogInterface;
@@ -90,22 +91,35 @@ public class FileBrowserFragment extends BaseBrowserFragment {
 
     @Override
     protected void browseRoot() {
+        final Activity context = getActivity();
         mAdapter.updateMediaDirs();
-        String storages[] = AndroidDevices.getMediaDirectories();
-        MediaWrapper directory;
-        for (String mediaDirLocation : storages) {
-            directory = new MediaWrapper(mediaDirLocation);
-            directory.setType(MediaWrapper.TYPE_DIR);
-            if (TextUtils.equals(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, mediaDirLocation))
-                directory.setTitle(getString(R.string.internal_memory));
-            mAdapter.addItem(directory, false, false);
-        }
-        mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_HIDE_LOADING);
-        if (mReadyToDisplay) {
-            updateEmptyView();
-            mAdapter.notifyDataSetChanged();
-            parseSubDirectories();
-        }
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+                String storages[] = AndroidDevices.getMediaDirectories();
+                MediaWrapper directory;
+                for (String mediaDirLocation : storages) {
+                    if (!(new File(mediaDirLocation).exists()))
+                        continue;
+                    directory = new MediaWrapper(mediaDirLocation);
+                    directory.setType(MediaWrapper.TYPE_DIR);
+                    if (TextUtils.equals(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, mediaDirLocation))
+                        directory.setTitle(getString(R.string.internal_memory));
+                    mAdapter.addItem(directory, false, false);
+                }
+                mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_HIDE_LOADING);
+                if (mReadyToDisplay) {
+                    context.runOnUiThread(new Runnable() {
+                        @Override
+                        public void run() {
+                            updateEmptyView();
+                            mAdapter.notifyDataSetChanged();
+                            parseSubDirectories();
+                        }
+                    });
+                }
+            }
+        }).start();
     }
 
     public void onStart(){



More information about the Android mailing list