[Android] Handle inner folders

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


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue May 12 13:29:26 2015 +0200| [794bc6107a42486321cb258e7860b06faab26c85] | committer: Geoffrey Métais

Handle inner folders

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

 .../vlc/gui/browser/BaseBrowserAdapter.java        |    2 +-
 .../vlc/gui/browser/StorageBrowserAdapter.java     |   38 ++++++++++++++------
 .../vlc/gui/browser/StorageBrowserFragment.java    |   37 +++++++++++++++++++
 3 files changed, 65 insertions(+), 12 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 69d205b..0299503 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -28,7 +28,6 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.CheckBox;
-import android.widget.CompoundButton;
 import android.widget.ImageView;
 import android.widget.TextView;
 
@@ -263,6 +262,7 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
             mMediaDirsLocation.add(dir.getPath());
         }
         mCustomDirsLocation = Arrays.asList(CustomDirectories.getCustomDirectories());
+        mMediaDirsLocation.addAll(mCustomDirsLocation);
     }
 
     public void addAll(ArrayList<MediaWrapper> mediaList){
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.java
index 0823249..6f23af2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.java
@@ -28,12 +28,11 @@ import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.CompoundButton;
+import android.widget.CheckBox;
 
 import org.videolan.libvlc.Media;
 import org.videolan.vlc.MediaWrapper;
 import org.videolan.vlc.R;
-import org.videolan.vlc.util.AndroidDevices;
 import org.videolan.vlc.util.Strings;
 
 public class StorageBrowserAdapter extends BaseBrowserAdapter {
@@ -67,25 +66,23 @@ public class StorageBrowserAdapter extends BaseBrowserAdapter {
         vh.itemView.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                MediaWrapper mw = new MediaWrapper(((Storage)getItem(vh.getAdapterPosition())).getPath());
+                MediaWrapper mw = new MediaWrapper(((Storage) getItem(vh.getAdapterPosition())).getPath());
                 mw.setType(MediaWrapper.TYPE_DIR);
-                fragment.browse(mw, holder.getAdapterPosition());
+                ((StorageBrowserFragment) fragment).browse(mw, holder.getAdapterPosition(), vh.checkBox.isChecked());
             }
         });
         vh.checkBox.setChecked(mMediaDirsLocation == null || mMediaDirsLocation.isEmpty() ||
                 mMediaDirsLocation.contains(storage.getPath()));
-        vh.checkBox.setEnabled(true);
-        vh.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+        vh.checkBox.setEnabled(!((StorageBrowserFragment) fragment).mScannedDirectory);
+        vh.checkBox.setOnClickListener(new View.OnClickListener() {
             @Override
-            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
+            public void onClick(View v) {
+                boolean isChecked = ((CheckBox)v).isChecked();
                 String path = ((Storage)getItem(vh.getAdapterPosition())).getPath();
-                updateMediaDirs();
                 if (isChecked)
                     addDir(path);
                 else
-                    mDbManager.removeDir(path);
-                updateMediaDirs();
-                fragment.updateLib();
+                    removeDir(path);
             }
         });
         if (hasContextMenu) {
@@ -113,6 +110,12 @@ public class StorageBrowserAdapter extends BaseBrowserAdapter {
         addItem(storage, notify, top);
     }
 
+    private void removeDir(String path) {
+        mDbManager.removeDir(path);
+        updateMediaDirs();
+        fragment.updateLib();
+    }
+
     private void addDir(final String path) {
         new Thread(new Runnable() {
             @Override
@@ -123,7 +126,20 @@ public class StorageBrowserAdapter extends BaseBrowserAdapter {
                     mDbManager.removeDir(parentPath);
                     parentPath = Strings.getParent(parentPath);
                 }
+                refreshFragment();
+                updateMediaDirs();
+                fragment.updateLib();
             }
         }).start();
     }
+
+    void refreshFragment(){
+        fragment.getActivity().runOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                if (mMediaDirsLocation == null || mMediaDirsLocation.isEmpty())
+                    fragment.refresh();
+            }
+        });
+    }
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
index 4246018..9ae5126 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
@@ -23,15 +23,24 @@
 
 package org.videolan.vlc.gui.browser;
 
+import android.os.Bundle;
 import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentTransaction;
 import android.text.TextUtils;
 
 import org.videolan.libvlc.Media;
+import org.videolan.vlc.MediaWrapper;
 import org.videolan.vlc.R;
 import org.videolan.vlc.util.AndroidDevices;
 
+import java.util.ArrayList;
+
 public class StorageBrowserFragment extends FileBrowserFragment {
 
+    public static final String KEY_IN_MEDIALIB = "key_in_medialib";
+
+    boolean mScannedDirectory = false;
+
     public StorageBrowserFragment(){
         mHandler = new BrowserFragmentHandler(this);
         mAdapter = new StorageBrowserAdapter(this);
@@ -44,6 +53,22 @@ public class StorageBrowserFragment extends FileBrowserFragment {
     }
 
     @Override
+    public void onCreate(Bundle bundle) {
+        super.onCreate(bundle);
+        if (bundle == null)
+            bundle = getArguments();
+        if (bundle != null){
+            mScannedDirectory = bundle.getBoolean(KEY_IN_MEDIALIB);
+        }
+    }
+
+    @Override
+    public void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        outState.putBoolean(KEY_IN_MEDIALIB, mScannedDirectory);
+    }
+
+    @Override
     protected void browseRoot() {
         String storages[] = AndroidDevices.getMediaDirectories();
         BaseBrowserAdapter.Storage storage;
@@ -82,4 +107,16 @@ public class StorageBrowserFragment extends FileBrowserFragment {
         }
         mAdapter.notifyDataSetChanged();
     }
+
+    public void browse (MediaWrapper media, int position, boolean scanned){
+        FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
+        Fragment next = createFragment();
+        Bundle args = new Bundle();
+        args.putParcelable(KEY_MEDIA, media);
+        args.putBoolean(KEY_IN_MEDIALIB, mScannedDirectory || scanned);
+        next.setArguments(args);
+        ft.replace(R.id.fragment_placeholder, next, media.getLocation());
+        ft.addToBackStack(mMrl);
+        ft.commit();
+    }
 }



More information about the Android mailing list