[Android] [PATCH] Bug #9727 patched

Vojtěch Létal letal.vojtech at gmail.com
Sun Mar 2 12:27:08 CET 2014


 From 93a9885a416bceb732c143de172fb27fe70f2133 Mon Sep 17 00:00:00 2001
From: Vojtech Letal <letal.vojtech at gmail.com>
Date: Sun, 2 Mar 2014 12:14:26 +0100
Subject: [PATCH] Bug #9727 patched

Bug description: "VLC for Android does not save current position in
folder mode." https://trac.videolan.org/vlc/ticket/9727

Method browse in the DirectoryAdapter now returns a number representing
position of the current directory in the directory which is being
opened, 0 if the opened directory does not contain the current one or -1
if the opening was not successful.

This is used in DirectoryViewFragment. After calling the browse method
if the call was successful selection is set to appropriate item or
handled as before.
---
  .../src/org/videolan/vlc/gui/DirectoryAdapter.java | 44 
+++++++++++++++++-----
  .../videolan/vlc/gui/DirectoryViewFragment.java    | 13 +++++--
  2 files changed, 44 insertions(+), 13 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java 
b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
index 0b1cee0..4645123 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
@@ -25,6 +25,7 @@ import java.net.URI;
  import java.net.URISyntaxException;
  import java.util.ArrayList;
  import java.util.Collections;
+import java.util.ListIterator;
  import java.util.regex.Pattern;

  import org.videolan.libvlc.LibVLC;
@@ -108,6 +109,19 @@ public class DirectoryAdapter extends BaseAdapter {
              return false;
          }

+        public int getChildPosition(DirectoryAdapter.Node child){
+            if(child == null)
+                return -1;
+
+            ListIterator<DirectoryAdapter.Node> it = 
children.listIterator();
+            while(it.hasNext()){
+                DirectoryAdapter.Node node = it.next();
+                if(child.equals(node)) return it.previousIndex();
+            }
+
+            return -1;
+        }
+
          public DirectoryAdapter.Node ensureExists(String _n) {
              for(DirectoryAdapter.Node n : this.children) {
                  if(Util.nullEquals(n.name, _n)) return n;
@@ -331,13 +345,23 @@ public class DirectoryAdapter extends BaseAdapter {
          return v;
      }

-    public boolean browse(int position) {
+    /**
+     * @return position of the current directory in a newly formed 
listview
+     * or -1 if opening not successful
+     * */
+
+    public int browse(int position) {
          DirectoryAdapter.Node selectedNode = 
mCurrentNode.children.get(position);
-        if(selectedNode.isFile()) return false;
+        if(selectedNode.isFile()) return -1;
          return browse(selectedNode.name);
      }

-    public boolean browse(String directoryName) {
+    /**
+     * @return position of the current directory in a newly formed 
listview
+     * or -1 if opening not successful
+     * */
+
+    public int browse(String directoryName) {
          if (this.mCurrentDir == null) {
              // We're on the storage list
              String storages[] = Util.getMediaDirectories();
@@ -363,18 +387,20 @@ public class DirectoryAdapter extends BaseAdapter {
                  }
              } catch(URISyntaxException e) {
                  Log.e(TAG, "URISyntaxException in browse()", e);
-                return false;
+                return -1;
              } catch(NullPointerException e) {
                  Log.e(TAG, "NullPointerException in browse()", e);
-                return false;
+                return -1;
              }
          }

          Log.d(TAG, "Browsing to " + this.mCurrentDir);

-        if(directoryName.equals(".."))
-            this.mCurrentNode = this.mCurrentNode.parent;
-        else {
+        int currentDirPosition = 0;
+        if(directoryName.equals("..")){
+            currentDirPosition = 
mCurrentNode.parent.getChildPosition(mCurrentNode);
+            this.mCurrentNode = this.mCurrentNode.parent;
+        } else {
              this.mCurrentNode = 
this.mCurrentNode.getChildNode(directoryName);
              if(mCurrentNode.subfolderCount() < 1) {
                  // Clear the ".." entry
@@ -384,7 +410,7 @@ public class DirectoryAdapter extends BaseAdapter {
          }

          this.notifyDataSetChanged();
-        return true;
+        return (currentDirPosition == -1) ? 0 : currentDirPosition;
      }

      public boolean isChildFile(int position) {
diff --git 
a/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java 
b/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
index d656f5a..6794169 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
@@ -152,10 +152,12 @@ public class DirectoryViewFragment extends 
SherlockListFragment implements ISort

      @Override
      public void onListItemClick(ListView l, View v, int p, long id) {
-        Boolean success = mDirectoryAdapter.browse(p);
-        if(!success) { /* Clicked on a media file */
+        int success = mDirectoryAdapter.browse(p);
+
+        if(success < 0) /* Clicked on a media file */
              openMediaFile(p);
-        }
+        else
+            setSelection(success);
      }

      public boolean isRootDirectory () {
@@ -163,7 +165,10 @@ public class DirectoryViewFragment extends 
SherlockListFragment implements ISort
      }

      public void showParentDirectory() {
-        mDirectoryAdapter.browse("..");
+        int success = mDirectoryAdapter.browse("..");
+
+        if(success >= 0)
+            setSelection(success);
      };

      private void openMediaFile(int p) {
-- 
1.8.3.2



More information about the Android mailing list