[Android] Directory View : back pressed action shows a parent

Alexandre Perraud git at videolan.org
Thu Oct 4 14:46:04 CEST 2012


vlc-ports/android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Thu Oct  4 12:25:25 2012 +0200| [67155168b86c0305c1a97a4f6b6b24ca3c0a8930] | committer: Ludovic Fauvet

Directory View : back pressed action shows a parent

Signed-off-by: Ludovic Fauvet <etix at videolan.org>

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

 .../src/org/videolan/vlc/gui/DirectoryAdapter.java  |   19 ++++++++++++++++---
 .../org/videolan/vlc/gui/DirectoryViewFragment.java |   11 +++++++++++
 .../src/org/videolan/vlc/gui/MainActivity.java      |   12 ++++++++++--
 3 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
index 593947d..ad22241 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
@@ -285,14 +285,19 @@ public class DirectoryAdapter extends BaseAdapter {
         return v;
     }
 
-    public Boolean browse(int position) {
+    public boolean browse(int position) {
         DirectoryAdapter.Node selectedNode = mCurrentNode.children.get(position);
         if(selectedNode.isFile()) return false;
+        return browse(selectedNode.name);
+    }
+
+    public boolean browse(String directoryName) {
         try {
-            this.mCurrentDir = new URI(LibVLC.getExistingInstance().nativeToURI(this.mCurrentDir + "/" + selectedNode.name)).normalize().getPath();
+            this.mCurrentDir = new URI(LibVLC.getExistingInstance().nativeToURI(this.mCurrentDir + "/" + directoryName)).normalize().getPath();
             this.mCurrentDir = Util.stripTrailingSlash(this.mCurrentDir);
         } catch (URISyntaxException e) {
-            /* blah blah blah blah blah */
+            e.printStackTrace();
+            return false;
         }
 
         Log.d(TAG, "Browsing to " + this.mCurrentDir);
@@ -318,6 +323,14 @@ public class DirectoryAdapter extends BaseAdapter {
         );
     }
 
+    public String getmRootDir() {
+        return mRootDir;
+    }
+
+    public String getmCurrentDir() {
+        return mCurrentDir;
+    }
+
     public ArrayList<String> getAllMediaLocations() {
         ArrayList<String> a = new ArrayList<String>();
         // i = 1 to exclude ".." folder
diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java b/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
index 55a15ae..68ddce1 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
@@ -144,6 +144,17 @@ public class DirectoryViewFragment extends SherlockListFragment implements ISort
         }
     }
 
+    public boolean isRootDirectory () {
+        if (mDirectoryAdapter.getmCurrentDir().equals(mDirectoryAdapter.getmRootDir())) {
+            return true;
+        }
+        return false;
+    };
+
+    public void showParentDirectory() {
+            mDirectoryAdapter.browse("..");
+    };
+
     private void openMediaFile(int p) {
         AudioServiceController audioController = AudioServiceController.getInstance();
         String mediaFile = mDirectoryAdapter.getMediaLocation(p);
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 1c880da..c539d93 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -358,9 +358,17 @@ public class MainActivity extends SherlockFragmentActivity {
         if(mMenu.isBehindShowing()) {
             /* Close the menu first */
             mMenu.showAbove();
-        } else {
-            super.onBackPressed();
+            return;
+        }
+        // If it's the directory view, a "backpressed" action shows a parent.
+        if (mCurrentFragment.equals("directories")) {
+            DirectoryViewFragment directoryView = (DirectoryViewFragment) getFragment(mCurrentFragment);
+            if (!directoryView.isRootDirectory()) {
+                directoryView.showParentDirectory();
+                return;
+            }
         }
+        super.onBackPressed();
     }
 
     private Fragment getFragment(String id)



More information about the Android mailing list