[Android] Playlist screen: keep track of deleted items to revert on cancel

Nicolas Pomepuy git at videolan.org
Mon Sep 5 10:58:56 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Sep  5 11:53:49 2022 +0200| [03a9dd8338c5f494a6e116b4178807b822c4d177] | committer: Nicolas Pomepuy

Playlist screen: keep track of deleted items to revert on cancel

Fixes #2677

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

 .../src/org/videolan/vlc/gui/HeaderMediaListActivity.kt        | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
index d421ba0b8..91e90e301 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
@@ -82,6 +82,7 @@ import kotlin.math.min
 
 open class HeaderMediaListActivity : AudioPlayerContainerActivity(), IEventsHandler<MediaLibraryItem>, IListEventsHandler, ActionMode.Callback, View.OnClickListener, CtxActionReceiver, Filterable, SearchView.OnQueryTextListener, MenuItem.OnActionExpandListener {
 
+    private var lastDismissedPosition: Int = -1
     private lateinit var searchView: SearchView
     private lateinit var itemTouchHelperCallback: SwipeDragItemTouchHelperCallback
     private lateinit var audioBrowserAdapter: AudioBrowserAdapter
@@ -295,6 +296,7 @@ open class HeaderMediaListActivity : AudioPlayerContainerActivity(), IEventsHand
     override fun onItemFocused(v: View, item: MediaLibraryItem) {}
 
     override fun onRemove(position: Int, item: MediaLibraryItem) {
+        lastDismissedPosition = position
         val tracks = ArrayList(listOf(*item.tracks))
         removeFromPlaylist(tracks, ArrayList(listOf(position)))
     }
@@ -482,9 +484,15 @@ open class HeaderMediaListActivity : AudioPlayerContainerActivity(), IEventsHand
                 }
             }
             var removedMessage = if (indexes.size>1) getString(R.string.removed_from_playlist_anonymous) else getString(R.string.remove_playlist_item,list.first().title)
-            UiTools.snackerWithCancel(this at HeaderMediaListActivity, removedMessage, action = {}) {
+            UiTools.snackerWithCancel(this at HeaderMediaListActivity, removedMessage, action = {
+                lastDismissedPosition = -1
+            }) {
                 for ((key, value) in itemsRemoved) {
                     playlist.add(value, key)
+                    if (lastDismissedPosition != -1) {
+                        audioBrowserAdapter.notifyItemChanged(lastDismissedPosition)
+                        lastDismissedPosition = -1
+                    }
                 }
             }
         }



More information about the Android mailing list