[Android] Add delete song to detail playlist view action mode

Alexandre Perraud git at videolan.org
Mon Jul 24 15:19:32 CEST 2017


vlc-android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Thu Jul 20 16:08:41 2017 +0200| [47ec409c724767f6c9dd30a30260e133b32545db] | committer: Alexandre Perraud

Add delete song to detail playlist view action mode

> https://code.videolan.org/videolan/vlc-android/commit/47ec409c724767f6c9dd30a30260e133b32545db
---

 .../src/org/videolan/vlc/gui/PlaylistActivity.java | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
index 71b7773d9..29f78789c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
@@ -246,6 +246,7 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
         menu.findItem(R.id.action_mode_audio_set_song).setVisible(isSong && AndroidDevices.isPhone());
         menu.findItem(R.id.action_mode_audio_info).setVisible(isSong);
         menu.findItem(R.id.action_mode_audio_append).setVisible(mService.hasMedia());
+        menu.findItem(R.id.action_mode_audio_delete).setVisible(mIsPlaylist);
         return true;
     }
 
@@ -272,6 +273,9 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
             case R.id.action_mode_audio_set_song:
                 AudioUtil.setRingtone((MediaWrapper) list.get(0), this);
                 break;
+            case R.id.action_mode_audio_delete:
+                removeFromPlaylist(tracks);
+                break;
             default:
                 return false;
         }
@@ -404,4 +408,24 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
         if (mService != null)
             mService.load(mPlaylist.getTracks(), 0);
     }
+
+    private void removeFromPlaylist(final List<MediaWrapper> list){
+        final ArrayList<MediaLibraryItem> oldAdapter = new ArrayList<>(mAdapter.getAll());
+        for (MediaLibraryItem mediaItem : list)
+            mAdapter.remove(mediaItem);
+        UiTools.snackerWithCancel(mBinding.getRoot(), getString(R.string.file_deleted), new Runnable() {
+            @Override
+            public void run() {
+                for (MediaLibraryItem mediaItem : list)
+                    ((Playlist) mPlaylist).remove(mediaItem.getId());
+                if (mPlaylist.getTracks().length == 0)
+                    ((Playlist) mPlaylist).delete();
+            }
+        }, new Runnable() {
+            @Override
+            public void run() {
+                mAdapter.update(oldAdapter);
+            }
+        });
+    }
 }



More information about the Android mailing list