[Android] Fixed playlist duplicate by name bug

Shivansh Saini git at videolan.org
Thu Aug 8 13:53:55 CEST 2019


vlc-android | branch: 3.2.x | Shivansh Saini <shivanshs9 at gmail.com> | Wed Aug  7 10:13:52 2019 +0530| [03df0b7e71a914fe8dba1c15da4557bd60138d3b] | committer: Geoffrey Métais

Fixed playlist duplicate by name bug

Signed-off-by: Shivansh Saini <shivanshs9 at gmail.com>
(cherry picked from commit d810855173b4b00e857f31e32df34cd78903e0cf)

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

 .../src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt    | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt
index ae3bb4436..a22d32a7e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt
@@ -60,7 +60,7 @@ class SavePlaylistDialog : VLCBottomSheetDialogFragment(), View.OnClickListener,
     private lateinit var tracks: Array<AbstractMediaWrapper>
     private lateinit var newTrack: Array<AbstractMediaWrapper>
     private lateinit var medialibrary: AbstractMedialibrary
-    private var playlistId: Long = 0
+    private var playlist: AbstractPlaylist? = null
 
     override fun initialFocusedView(): View = listView
 
@@ -124,10 +124,11 @@ class SavePlaylistDialog : VLCBottomSheetDialogFragment(), View.OnClickListener,
         runIO(Runnable {
             val name = editText!!.text.toString().trim { it <= ' ' }
             val addTracks = !Tools.isArrayEmpty(newTrack)
-            var playlist: AbstractPlaylist? = medialibrary.getPlaylist(playlistId)
+            var playlist: AbstractPlaylist? = if (playlist != null && playlist!!.title == name) medialibrary.getPlaylist(playlist!!.id) else null
             val exists = playlist != null
             val playlistTracks: Array<AbstractMediaWrapper>?
-            if (!exists) playlist = medialibrary.createPlaylist(name)
+            if (!exists) playlist = medialibrary.getPlaylistByName(name)
+            if (playlist == null) playlist = medialibrary.createPlaylist(name)
             if (playlist == null) return at Runnable
             playlistTracks = if (addTracks) {
                 newTrack
@@ -166,7 +167,7 @@ class SavePlaylistDialog : VLCBottomSheetDialogFragment(), View.OnClickListener,
 
 
     override fun onClick(item: MediaLibraryItem) {
-        playlistId = item.id
+        playlist = item as AbstractPlaylist
         editText!!.setText(item.title)
     }
 
@@ -178,3 +179,5 @@ class SavePlaylistDialog : VLCBottomSheetDialogFragment(), View.OnClickListener,
         const val KEY_NEW_TRACKS = "PLAYLIST_NEW_TRACKS"
     }
 }
+
+fun AbstractMedialibrary.getPlaylistByName(name: String): AbstractPlaylist? = playlists.filter { it.title == name }.getOrNull(0)



More information about the Android mailing list