[Android] Fix contextual delete option

Geoffrey Métais git at videolan.org
Fri Oct 30 15:45:35 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Oct 30 15:03:19 2015 +0100| [c40f61c6a2c897e167e05f23a6e2e12a6975f954] | committer: Geoffrey Métais

Fix contextual delete option

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

 .../videolan/vlc/gui/audio/AudioAlbumFragment.java |    4 +++
 .../vlc/gui/audio/AudioAlbumsSongsFragment.java    |   33 ++++++++++++--------
 .../vlc/gui/audio/AudioBrowserFragment.java        |   12 +++++++
 .../vlc/gui/browser/BaseBrowserFragment.java       |    2 +-
 .../videolan/vlc/gui/video/VideoGridFragment.java  |    4 +--
 vlc-android/src/org/videolan/vlc/util/Util.java    |    2 +-
 6 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumFragment.java
index 8afa9b6..8b881ff 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumFragment.java
@@ -47,6 +47,7 @@ import org.videolan.vlc.MediaWrapper;
 import org.videolan.vlc.R;
 import org.videolan.vlc.gui.PlaybackServiceFragment;
 import org.videolan.vlc.util.AndroidDevices;
+import org.videolan.vlc.util.Util;
 
 import java.util.ArrayList;
 
@@ -168,6 +169,9 @@ public class AudioAlbumFragment extends PlaybackServiceFragment implements Adapt
         menu.setGroupVisible(R.id.songs_view_only, false);
         menu.findItem(R.id.audio_list_browser_delete).setVisible(false);
         menu.setGroupVisible(R.id.phone_only, AndroidDevices.isPhone());
+        //Hide delete if we cannot
+        String location = mMediaList.get(position).getLocation();
+        menu.findItem(R.id.audio_list_browser_delete).setVisible(Util.canWrite(location));
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
index 1098197..57baa8b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -197,6 +197,12 @@ public class AudioAlbumsSongsFragment extends PlaybackServiceFragment implements
         if (!AndroidDevices.isPhone())
             menu.setGroupVisible(R.id.phone_only, false);
         menu.findItem(R.id.audio_list_browser_play).setVisible(true);
+        //Hide delete if we cannot
+            AudioBrowserListAdapter adapter = mViewPager.getCurrentItem() == MODE_SONG ?
+                    mSongsAdapter : mAlbumsAdapter;
+            String location = adapter.getItem(position).mMediaList.get(0).getLocation();
+        menu.findItem(R.id.audio_list_browser_delete).setVisible(
+                Util.canWrite(location));
     }
 
     @Override
@@ -386,19 +392,20 @@ public class AudioAlbumsSongsFragment extends PlaybackServiceFragment implements
             switch (msg.what){
                 case DELETE_MEDIA:
                     AudioBrowserListAdapter.ListItem listItem = fragment.mSongsAdapter.getItem(msg.arg1);
-                    MediaWrapper media = listItem.mMediaList.get(0);
-                    final String path = media.getUri().getPath();
-                    fragment.mMediaLibrary.getMediaItems().remove(media);
-                    fragment.mSongsAdapter.removeMedia(media);
-                    fragment.mAlbumsAdapter.removeMedia(media);
-                    if (fragment.mService != null)
-                        fragment.mService.removeLocation(media.getLocation());
-                    fragment.mMediaLibrary.getMediaItems().remove(media);
-                    VLCApplication.runBackground(new Runnable() {
-                        public void run() {
-                            Util.recursiveDelete(VLCApplication.getAppContext(), new File(path));
-                        }
-                    });
+                    for (MediaWrapper media : listItem.mMediaList) {
+                        final String path = media.getUri().getPath();
+                        fragment.mMediaLibrary.getMediaItems().remove(media);
+                        fragment.mSongsAdapter.removeMedia(media);
+                        fragment.mAlbumsAdapter.removeMedia(media);
+                        if (fragment.mService != null)
+                            fragment.mService.removeLocation(media.getLocation());
+                        fragment.mMediaLibrary.getMediaItems().remove(media);
+                        VLCApplication.runBackground(new Runnable() {
+                            public void run() {
+                                Util.recursiveDelete(VLCApplication.getAppContext(), new File(path));
+                            }
+                        });
+                    }
                     break;
             }
         }
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index 9047045..36cb298 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -388,6 +388,18 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
             menu.findItem(R.id.audio_list_browser_play).setVisible(true);
         if (pos != MODE_SONG && pos != MODE_PLAYLIST)
             menu.findItem(R.id.audio_list_browser_delete).setVisible(false);
+        else {
+            MenuItem item = menu.findItem(R.id.audio_list_browser_delete);
+            int position = ((AdapterContextMenuInfo) item.getMenuInfo()).position;
+            AudioBrowserListAdapter adapter = pos == MODE_SONG ? mSongsAdapter : mPlaylistAdapter;
+            AudioBrowserListAdapter.ListItem mediaItem = adapter.getItem(position);
+            if (pos == MODE_PLAYLIST && MediaDatabase.getInstance().playlistExists(mediaItem.mTitle))
+                item.setVisible(true);
+            else {
+                String location = mediaItem.mMediaList.get(0).getLocation();
+                item.setVisible(Util.canWrite(location));
+            }
+        }
         if (!AndroidDevices.isPhone())
             menu.setGroupVisible(R.id.phone_only, false);
     }
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 9664afb..3749fc7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -359,7 +359,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
 
     protected void setContextMenu(MenuInflater inflater, Menu menu, int position) {
         MediaWrapper mw = (MediaWrapper) mAdapter.getItem(position);
-        boolean canWrite = Util.canWrite(mw.getLocation());
+        boolean canWrite = this instanceof FileBrowserFragment && Util.canWrite(mw.getLocation());
         boolean isAudio = mw.getType() == MediaWrapper.TYPE_AUDIO;
         boolean isVideo = mw.getType() == MediaWrapper.TYPE_VIDEO;
         if (isAudio || isVideo) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index f7e0c8f..84389e1 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -350,8 +350,8 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
             hasInfo = true;
         media.release();
         menu.findItem(R.id.video_list_info).setVisible(hasInfo);
-        menu.findItem(R.id.video_list_delete).setVisible(!AndroidUtil.isLolliPopOrLater() ||
-                mediaWrapper.getLocation().startsWith("file://" + AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY));
+        menu.findItem(R.id.video_list_delete).setVisible(
+                Util.canWrite(mediaWrapper.getLocation()));
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java
index 2233231..8f9d767 100644
--- a/vlc-android/src/org/videolan/vlc/util/Util.java
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java
@@ -369,7 +369,7 @@ public class Util {
             return false;
         if (path.startsWith(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY))
             return true;
-        if (AndroidUtil.isLolliPopOrLater())
+        if (AndroidUtil.isKitKatOrLater())
             return false;
         File file = new File(path);
         return (file.exists() && file.canWrite());



More information about the Android mailing list