[Android] Use Uri for storage class too

Geoffrey Métais git at videolan.org
Fri Jun 12 11:18:13 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jun 12 11:17:48 2015 +0200| [37d420eb12c1d127ebeee7bf8fbf190474cef8f8] | committer: Geoffrey Métais

Use Uri for storage class too

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

 .../org/videolan/vlc/gui/browser/BaseBrowserAdapter.java |   12 ++++++------
 .../videolan/vlc/gui/browser/BaseBrowserFragment.java    |    4 ++--
 .../videolan/vlc/gui/browser/FileBrowserFragment.java    |    4 ++--
 .../videolan/vlc/gui/browser/StorageBrowserAdapter.java  |   14 ++++++--------
 .../videolan/vlc/gui/browser/StorageBrowserFragment.java |    8 +++++---
 5 files changed, 21 insertions(+), 21 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 3493126..d0ebc7d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -188,13 +188,13 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
     }
 
     public static class Storage {
-        String path;
+        Uri uri;
         String name;
         String description;
 
-        public Storage(String location){
-            path = location;
-            name = Strings.getName(path);
+        public Storage(Uri uri){
+            this.uri = uri;
+            name = uri.getLastPathSegment();
         }
 
         public String getName() {
@@ -213,8 +213,8 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
             return description;
         }
 
-        public String getPath() {
-            return path;
+        public Uri getUri() {
+            return uri;
         }
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 862ea2b..e4a34e4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -482,7 +482,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
         while (mCurrentParsedPosition <mAdapter.getItemCount()){
             item = mAdapter.getItem(mCurrentParsedPosition);
             if (item instanceof BaseBrowserAdapter.Storage) {
-                mw = new MediaWrapper(AndroidUtil.LocationToUri(((BaseBrowserAdapter.Storage) item).getPath()));
+                mw = new MediaWrapper(((BaseBrowserAdapter.Storage) item).getUri());
                 mw.setType(MediaWrapper.TYPE_DIR);
             } else  if (item instanceof MediaWrapper){
                 mw = (MediaWrapper) item;
@@ -534,7 +534,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
                     if (mw.getType() == MediaWrapper.TYPE_DIR || mw.getType() == MediaWrapper.TYPE_PLAYLIST)
                         break;
                 } else if (mAdapter.getItem(mCurrentParsedPosition) instanceof BaseBrowserAdapter.Storage) {
-                    mw = new MediaWrapper(AndroidUtil.LocationToUri(((BaseBrowserAdapter.Storage) mAdapter.getItem(mCurrentParsedPosition)).getPath()));
+                    mw = new MediaWrapper(((BaseBrowserAdapter.Storage) mAdapter.getItem(mCurrentParsedPosition)).getUri());
                     break;
                 } else
                     mw = null;
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 f646c89..8a7434f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
@@ -189,8 +189,8 @@ public class FileBrowserFragment extends BaseBrowserFragment {
         if (mRoot) {
             if (item.getItemId() == R.id.directory_remove_custom_path){
                 BaseBrowserAdapter.Storage storage = (BaseBrowserAdapter.Storage) mAdapter.getItem(position);
-                MediaDatabase.getInstance().recursiveRemoveDir(storage.getPath());
-                CustomDirectories.removeCustomDirectory(storage.getPath());
+                MediaDatabase.getInstance().recursiveRemoveDir(storage.getUri().getPath());
+                CustomDirectories.removeCustomDirectory(storage.getUri().getPath());
                 mAdapter.updateMediaDirs();
                 mAdapter.removeItem(position, true);
                 updateLib();
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 3fbc83f..22611c7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.java
@@ -31,10 +31,8 @@ import android.view.ViewGroup;
 import android.widget.CheckBox;
 
 import org.videolan.libvlc.Media;
-import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.vlc.MediaWrapper;
 import org.videolan.vlc.R;
-import org.videolan.vlc.util.Strings;
 
 public class StorageBrowserAdapter extends BaseBrowserAdapter {
 
@@ -59,7 +57,7 @@ public class StorageBrowserAdapter extends BaseBrowserAdapter {
     public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
         final MediaViewHolder vh = (MediaViewHolder) holder;
         final Storage storage = (Storage) getItem(position);
-        String storagePath = Strings.removeFileProtocole(storage.getPath());
+        String storagePath = storage.getUri().getPath();
         boolean hasContextMenu = mCustomDirsLocation.contains(storagePath);
         vh.title.setText(storage.getName());
         vh.icon.setVisibility(View.GONE);
@@ -70,7 +68,7 @@ public class StorageBrowserAdapter extends BaseBrowserAdapter {
         vh.itemView.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                MediaWrapper mw = new MediaWrapper(AndroidUtil.LocationToUri(((Storage) getItem(vh.getAdapterPosition())).getPath()));
+                MediaWrapper mw = new MediaWrapper(((Storage) getItem(vh.getAdapterPosition())).getUri());
                 mw.setType(MediaWrapper.TYPE_DIR);
                 ((StorageBrowserFragment) fragment).browse(mw, holder.getAdapterPosition(), vh.checkBox.isChecked());
             }
@@ -83,7 +81,7 @@ public class StorageBrowserAdapter extends BaseBrowserAdapter {
             @Override
             public void onClick(View v) {
                 boolean isChecked = ((CheckBox) v).isChecked();
-                String path = Strings.removeFileProtocole(((Storage) getItem(vh.getAdapterPosition())).getPath());
+                String path = ((Storage) getItem(vh.getAdapterPosition())).getUri().getPath();
                 if (isChecked)
                     addDir(path);
                 else
@@ -108,7 +106,7 @@ public class StorageBrowserAdapter extends BaseBrowserAdapter {
     }
 
     public void addItem(Media media, boolean notify, boolean top){
-        Storage storage = new Storage(media.getUri().toString());
+        Storage storage = new Storage(media.getUri());
         addItem(storage, notify, top);
     }
 
@@ -122,8 +120,8 @@ public class StorageBrowserAdapter extends BaseBrowserAdapter {
                     String pathString;
                     for (Object item : mMediaList){
                         storage = (Storage) item;
-                        if (!TextUtils.equals(path, storage.getPath())) {
-                            pathString = Strings.removeFileProtocole(storage.getPath());
+                        if (!TextUtils.equals(path, storage.getUri().getPath())) {
+                            pathString = storage.getUri().getPath();
                             mDbManager.addDir(pathString);
                         }
                     }
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 0aaf530..e87c792 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
@@ -23,6 +23,7 @@
 
 package org.videolan.vlc.gui.browser;
 
+import android.net.Uri;
 import android.os.Bundle;
 import android.support.design.widget.FloatingActionButton;
 import android.support.v4.app.Fragment;
@@ -33,7 +34,6 @@ import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.ImageView;
 
 import org.videolan.libvlc.Media;
 import org.videolan.vlc.MediaWrapper;
@@ -41,6 +41,8 @@ import org.videolan.vlc.R;
 import org.videolan.vlc.util.AndroidDevices;
 import org.videolan.vlc.util.CustomDirectories;
 
+import java.io.File;
+
 public class StorageBrowserFragment extends FileBrowserFragment implements View.OnClickListener {
 
     public static final String KEY_IN_MEDIALIB = "key_in_medialib";
@@ -91,7 +93,7 @@ public class StorageBrowserFragment extends FileBrowserFragment implements View.
         String storages[] = AndroidDevices.getMediaDirectories();
         BaseBrowserAdapter.Storage storage;
         for (String mediaDirLocation : storages) {
-            storage = new BaseBrowserAdapter.Storage(mediaDirLocation);
+            storage = new BaseBrowserAdapter.Storage(Uri.fromFile(new File(mediaDirLocation)));
             if (TextUtils.equals(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, mediaDirLocation))
                 storage.setName(getString(R.string.internal_memory));
             mAdapter.addItem(storage, false, false);
@@ -141,7 +143,7 @@ public class StorageBrowserFragment extends FileBrowserFragment implements View.
     protected void setContextMenu(MenuInflater inflater, Menu menu, int position) {
         if (mRoot) {
             BaseBrowserAdapter.Storage storage = (BaseBrowserAdapter.Storage) mAdapter.getItem(position);
-            boolean isCustom = CustomDirectories.contains(storage.getPath());
+            boolean isCustom = CustomDirectories.contains(storage.getUri().getPath());
             if (isCustom)
                 inflater.inflate(R.menu.directory_custom_dir, menu);
         } else



More information about the Android mailing list