[Android] Delete playlist & quit view once empty

Geoffrey Métais git at videolan.org
Thu Sep 13 16:15:17 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Sep 13 16:14:30 2018 +0200| [aac553684cf7a76a374bd6c1d39d7663aa25e451] | committer: Geoffrey Métais

Delete playlist & quit view once empty

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

 .../src/org/videolan/vlc/gui/PlaylistActivity.java       | 16 ++++++++--------
 .../org/videolan/vlc/viewmodels/paged/MLPagedModel.kt    |  2 --
 .../videolan/vlc/viewmodels/paged/PagedTracksModel.kt    |  1 +
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
index 178ac744f..7fc92b412 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
@@ -69,6 +69,7 @@ import org.videolan.vlc.media.PlaylistManager;
 import org.videolan.vlc.util.AndroidDevices;
 import org.videolan.vlc.util.Constants;
 import org.videolan.vlc.util.FileUtils;
+import org.videolan.vlc.util.Util;
 import org.videolan.vlc.util.WorkersKt;
 import org.videolan.vlc.viewmodels.paged.MLPagedModel;
 import org.videolan.vlc.viewmodels.paged.PagedTracksModel;
@@ -115,7 +116,10 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
         ((MLPagedModel)tracksModel).getPagedList().observe(this, new Observer<PagedList<MediaLibraryItem>>() {
             @Override
             public void onChanged(@Nullable PagedList<MediaLibraryItem> tracks) {
-                if (tracks != null) mAdapter.submitList(tracks);
+                if (tracks != null) {
+                    if (tracks.isEmpty() && !tracksModel.isFiltering()) finish();
+                    else mAdapter.submitList(tracks);
+                }
             }
         });
         final int fabVisibility =  savedInstanceState != null ? savedInstanceState.getInt(TAG_FAB_VISIBILITY) : -1;
@@ -237,7 +241,7 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
 
     @Override
     public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
-        int count = mAdapter.getMultiSelectHelper().getSelectionCount();
+        final int count = mAdapter.getMultiSelectHelper().getSelectionCount();
         if (count == 0) {
             stopActionMode();
             return false;
@@ -254,8 +258,8 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
 
     @Override
     public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
-        List<MediaLibraryItem> list = mAdapter.getMultiSelectHelper().getSelection();
-        List<MediaWrapper> tracks = new ArrayList<>();
+        final List<MediaLibraryItem> list = mAdapter.getMultiSelectHelper().getSelection();
+        final List<MediaWrapper> tracks = new ArrayList<>();
         for (MediaLibraryItem mediaItem : list)
             tracks.addAll(Arrays.asList(mediaItem.getTracks()));
 
@@ -371,10 +375,6 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
             @Override
             public void run() {
                 for (MediaLibraryItem mediaItem : list) ((Playlist) mPlaylist).remove(mediaItem.getId());
-                if (mPlaylist.getTracks().length == 0) {
-                    ((Playlist) mPlaylist).delete();
-                    finish();
-                }
             }
         });
     }
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
index c42cd4477..ff97f7673 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/MLPagedModel.kt
@@ -72,8 +72,6 @@ abstract class MLPagedModel<T : MediaLibraryItem>(context: Context) : SortableMo
         return true
     }
 
-    fun remove(item: MediaLibraryItem) {} //TODO
-
     inner class MLDataSource : PositionalDataSource<T>() {
         override fun loadRange(params: LoadRangeParams, callback: LoadRangeCallback<T>) {
             callback.onResult(getPage(params.loadSize, params.startPosition).toList())
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedTracksModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedTracksModel.kt
index 37e5851f8..23ae1927a 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedTracksModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/paged/PagedTracksModel.kt
@@ -120,5 +120,6 @@ class PagedTracksModel(context: Context, val parent: MediaLibraryItem? = null):
 
     override fun onPlaylistsModified() {
         refresh()
+        if ((parent as Playlist).realTracksCount == 0) parent.delete()
     }
 }



More information about the Android mailing list