From 20ca93ed7ec0fb9dea4b6a858a09a7d18c1915f7 Mon Sep 17 00:00:00 2001 From: Steven Vandevelde Date: Sun, 4 Sep 2022 18:02:03 +0200 Subject: [PATCH] Playlist improvements --- CHANGELOG.md | 5 +- src/Applications/UI/Playlists/ContextMenu.elm | 162 ++++++++++++------ src/Applications/UI/Playlists/View.elm | 13 +- src/Library/Tracks.elm | 19 +- .../Tracks/Collection/Internal/Harvest.elm | 6 +- 5 files changed, 134 insertions(+), 71 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 515d159e..d68ed130 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,10 @@ ## 3.2.0 - **Native builds with [Tauri](https://tauri.app/)**. -- Fixes playback issue with Google Drive on Safari/iOS. -- Improves Google Drive support, access tokens are now refreshed when needed (before it only refreshed on source processing) - Add support for non-standard `audio/x-flac` mimetype +- Fixes a playback issue with Google Drive on Safari/iOS. +- Improves Google Drive support, access tokens are now refreshed when needed (before it only refreshed on source processing) +- Several playlist improvements: add to queue, add options to autogenerated playlists, etc. ## 3.1.1 diff --git a/src/Applications/UI/Playlists/ContextMenu.elm b/src/Applications/UI/Playlists/ContextMenu.elm index c8d0a50c..761fd1d2 100644 --- a/src/Applications/UI/Playlists/ContextMenu.elm +++ b/src/Applications/UI/Playlists/ContextMenu.elm @@ -9,6 +9,7 @@ import Playlists.Matching import Tracks exposing (IdentifiedTrack) import UI.Page import UI.Playlists.Page +import UI.Queue.Types as Queue import UI.Tracks.Types as Tracks import UI.Types exposing (Msg(..)) import Url @@ -21,17 +22,22 @@ import Url listMenu : Playlist -> List IdentifiedTrack -> Maybe String -> Coordinates -> ContextMenu Msg listMenu playlist allTracks confirmation coordinates = let - ( identifiedTracksFromPlaylist, _ ) = - Playlists.Matching.match playlist allTracks + identifiedTracksFromPlaylist = + if playlist.autoGenerated then + List.filter + (Tuple.second >> Tracks.matchesAutoGeneratedPlaylist playlist) + allTracks + + else + allTracks + |> Playlists.Matching.match playlist + |> Tuple.first tracksFromPlaylist = identifiedTracksFromPlaylist |> List.sortBy (Tuple.first >> .indexInPlaylist >> Maybe.withDefault 0) |> List.map Tuple.second - playlistId = - "Playlist - " ++ playlist.name - menuMsg = ShowPlaylistListMenu playlist @@ -42,63 +48,105 @@ listMenu playlist allTracks confirmation coordinates = , pagePos = ( 0, 0 ) , screenPos = ( 0, 0 ) } + in + if playlist.autoGenerated then + ContextMenu + [ addToQueue identifiedTracksFromPlaylist + , downloadAsZip tracksFromPlaylist playlist + , storeInCache tracksFromPlaylist + ] + coordinates + + else + ContextMenu + [ addToQueue identifiedTracksFromPlaylist + , downloadAsZip tracksFromPlaylist playlist + , removePlaylist menuMsg confirmation playlist + , renamePlaylist playlist + , storeInCache tracksFromPlaylist + ] + coordinates + + + +-- ITEMS + + +addToQueue identifiedTracks = + Item + { icon = Icons.update + , label = "Add to queue" + , msg = + { inFront = False, tracks = identifiedTracks } + |> Queue.AddTracks + |> QueueMsg + + -- + , active = False + } + + +downloadAsZip tracksFromPlaylist playlist = + Item + { icon = Icons.archive + , label = "Download as zip file" + , msg = + tracksFromPlaylist + |> Tracks.Download playlist.name + |> TracksMsg + + -- + , active = False + } + + +removePlaylist menuMsg confirmation playlist = + let + playlistId = + "Playlist - " ++ playlist.name askForConfirmation = confirmation == Just playlistId in - ContextMenu - [ Item - { icon = Icons.archive - , label = "Download as zip file" - , msg = - tracksFromPlaylist - |> Tracks.Download playlist.name - |> TracksMsg - - -- - , active = False - } + Item + { icon = Icons.delete + , label = + if askForConfirmation then + "Are you sure?" + + else + "Remove playlist" + , msg = + if askForConfirmation then + DeletePlaylist { playlistName = playlist.name } + + else + ContextMenuConfirmation playlistId menuMsg + , active = + askForConfirmation + } + + +renamePlaylist playlist = + Item + { icon = Icons.font_download + , label = "Rename playlist" + , msg = + playlist.name + |> Url.percentEncode + |> UI.Playlists.Page.Edit + |> UI.Page.Playlists + |> ChangeUrlUsingPage -- - , Item - { icon = Icons.font_download - , label = "Rename playlist" - , msg = - playlist.name - |> Url.percentEncode - |> UI.Playlists.Page.Edit - |> UI.Page.Playlists - |> ChangeUrlUsingPage - - -- - , active = False - } + , active = False + } - -- - , Item - { icon = Icons.delete - , label = - if askForConfirmation then - "Are you sure?" - - else - "Remove playlist" - , msg = - if askForConfirmation then - DeletePlaylist { playlistName = playlist.name } - - else - ContextMenuConfirmation playlistId menuMsg - , active = - askForConfirmation - } - -- - , Item - { icon = Icons.offline_bolt - , label = "Store in cache" - , msg = TracksMsg (Tracks.StoreInCache tracksFromPlaylist) - , active = False - } - ] - coordinates +storeInCache tracksFromPlaylist = + Item + { icon = Icons.offline_bolt + , label = "Store in cache" + , msg = TracksMsg (Tracks.StoreInCache tracksFromPlaylist) + , active = False + } diff --git a/src/Applications/UI/Playlists/View.elm b/src/Applications/UI/Playlists/View.elm index 6171fd21..98cbe2b2 100644 --- a/src/Applications/UI/Playlists/View.elm +++ b/src/Applications/UI/Playlists/View.elm @@ -112,7 +112,12 @@ index playlists selectedPlaylist bgColor authMethodSupportsPublicData = else { label = text playlist.name - , actions = [] + , actions = + [ { icon = Icons.more_vert + , msg = Just (ShowPlaylistListMenu playlist) + , title = "Menu" + } + ] , msg = Just (ActivatePlaylist playlist) , isSelected = False } @@ -257,9 +262,13 @@ selectedPlaylistListItem playlist bgColor = [ text playlist.name ] , actions = [ { icon = \size _ -> Icons.check size (Color selectionColor) - , msg = Nothing + , msg = Just (always DeactivatePlaylist) , title = "Selected playlist" } + , { icon = Icons.more_vert + , msg = Just (ShowPlaylistListMenu playlist) + , title = "Menu" + } ] , msg = Just DeactivatePlaylist , isSelected = False diff --git a/src/Library/Tracks.elm b/src/Library/Tracks.elm index fa81d652..0a5e47c2 100644 --- a/src/Library/Tracks.elm +++ b/src/Library/Tracks.elm @@ -242,11 +242,25 @@ makeTrack sourceId ( path, tags ) = } +matchesAutoGeneratedPlaylist : Playlist -> Track -> Bool +matchesAutoGeneratedPlaylist playlist track = + track.path + |> String.split "/" + |> List.head + |> (==) (Just playlist.name) + |> (&&) playlist.autoGenerated + + missingAlbumPlaceholder : String missingAlbumPlaceholder = "⌁" +missingId : String +missingId = + "" + + pathParts : Track -> { filename : String, parentDirectory : String } pathParts { path } = let @@ -354,11 +368,6 @@ removeFromPlaylist tracks playlist = |> (\( t, _ ) -> { playlist | tracks = t }) -missingId : String -missingId = - "" - - shouldRenderGroup : Identifiers -> Bool shouldRenderGroup identifiers = identifiers.group diff --git a/src/Library/Tracks/Collection/Internal/Harvest.elm b/src/Library/Tracks/Collection/Internal/Harvest.elm index ba56bed6..36ee8fcc 100644 --- a/src/Library/Tracks/Collection/Internal/Harvest.elm +++ b/src/Library/Tracks/Collection/Internal/Harvest.elm @@ -44,11 +44,7 @@ harvest ( deps, collection ) = Just playlist -> if playlist.autoGenerated then \( _, t ) -> - t.path - |> String.split "/" - |> List.head - |> Maybe.withDefault "" - |> (==) playlist.name + Tracks.matchesAutoGeneratedPlaylist playlist t else \( i, _ ) -> -- knotmirror 0.0.1