Something went wrong. Try again.
A music player that connects to your cloud/distributed storage. forked from tokono.ma/diffuse
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378module UI.Tracks.ContextMenu exposing (cacheAction, trackMenu, viewMenu)
import Conditional exposing (ifThenElse)import ContextMenu exposing (..)import Coordinates exposing (Coordinates)import Material.Icons.Round as Iconsimport Maybe.Extra as Maybeimport Playlists exposing (Playlist)import Queueimport Sources exposing (Source)import Timeimport Tracks exposing (Grouping(..), IdentifiedTrack)import UI.Queue.Types as Queueimport UI.Tracks.Types as Tracksimport UI.Types exposing (Msg(..))
-- TRACK MENU
trackMenu : { cached : List String , cachingInProgress : List String , currentTime : Time.Posix , lastModifiedPlaylistName : Maybe { collection : Bool, name : String } , selectedPlaylist : Maybe Playlist , showAlternativeMenu : Bool , sources : List Source } -> List IdentifiedTrack -> Coordinates -> ContextMenu MsgtrackMenu { cached, cachingInProgress, currentTime, selectedPlaylist, lastModifiedPlaylistName, showAlternativeMenu, sources } tracks = if showAlternativeMenu then [ alternativeMenuActions currentTime sources tracks ] |> List.concat |> ContextMenu
else [ queueActions tracks
-- , playlistActions { selectedPlaylist = selectedPlaylist , lastModifiedPlaylistName = lastModifiedPlaylistName } tracks
-- , cacheAction { cached = cached , cachingInProgress = cachingInProgress } tracks |> List.singleton ] |> List.concat |> ContextMenu
alternativeMenuActions : Time.Posix -> List Source -> List IdentifiedTrack -> List (ContextMenu.Item Msg)alternativeMenuActions timestamp sources tracks = case tracks of [ ( _, t ) ] -> [ Item { icon = Icons.link , label = "Copy temporary url" , msg = CopyToClipboard (Queue.makeTrackUrl timestamp sources t) , active = False }
-- , Item { icon = Icons.sync , label = "Sync tags" , msg = TracksMsg (Tracks.SyncTags [ t ]) , active = False } ]
_ -> []
cacheAction : { cached : List String, cachingInProgress : List String } -> List IdentifiedTrack -> ContextMenu.Item MsgcacheAction { cached, cachingInProgress } tracks = case tracks of [ ( _, t ) ] -> if List.member t.id cached then Item { icon = Icons.offline_bolt , label = "Remove from cache" , msg = tracks |> List.map Tuple.second |> Tracks.RemoveFromCache |> TracksMsg
-- , active = False }
else if List.member t.id cachingInProgress then Item { icon = Icons.offline_bolt , label = "Downloading ..." , msg = Bypass , active = True }
else Item { icon = Icons.offline_bolt , label = "Store in cache" , msg = tracks |> List.map Tuple.second |> Tracks.StoreInCache |> TracksMsg
-- , active = False }
_ -> Item { icon = Icons.offline_bolt , label = "Store in cache" , msg = tracks |> List.map Tuple.second |> Tracks.StoreInCache |> TracksMsg
-- , active = False }
playlistActions : { selectedPlaylist : Maybe Playlist , lastModifiedPlaylistName : Maybe { collection : Bool, name : String } } -> List IdentifiedTrack -> List (ContextMenu.Item Msg)playlistActions { selectedPlaylist, lastModifiedPlaylistName } tracks = let maybeCustomPlaylist = Maybe.andThen (\p -> case p.autoGenerated of Just _ -> Nothing
Nothing -> Just p ) selectedPlaylist
maybeAddToLastModifiedPlaylist { collection } = Maybe.andThen (\l -> if Maybe.map .name selectedPlaylist /= Just l.name && l.collection == collection then justAnItem { icon = Icons.waves , label = "Add to \"" ++ l.name ++ "\"" , msg = AddTracksToPlaylist { collection = collection , playlistName = l.name , tracks = Tracks.toPlaylistTracks tracks }
-- , active = False }
else Nothing ) lastModifiedPlaylistName in case maybeCustomPlaylist of ----------------------------------------- -- In a custom playlist ----------------------------------------- Just playlist -> Maybe.values [ maybeAddToLastModifiedPlaylist { collection = True } , justAnItem { icon = Icons.waves , label = if playlist.collection then "Remove from collection"
else "Remove from playlist" , msg = RemoveTracksFromPlaylist playlist tracks
-- , active = False } , justAnItem { icon = Icons.waves , label = if playlist.collection then "Add to another collection"
else "Add to collection" , msg = AssistWithAddingTracksToCollection tracks
-- , active = False } , maybeAddToLastModifiedPlaylist { collection = False } , justAnItem { icon = Icons.waves , label = if playlist.collection then "Add to playlist"
else "Add to another playlist" , msg = AssistWithAddingTracksToPlaylist tracks
-- , active = False } ]
----------------------------------------- -- Otherwise ----------------------------------------- _ -> Maybe.values [ maybeAddToLastModifiedPlaylist { collection = True } , justAnItem { icon = Icons.waves , label = "Add to collection" , msg = AssistWithAddingTracksToCollection tracks , active = False } , maybeAddToLastModifiedPlaylist { collection = False } , justAnItem { icon = Icons.waves , label = "Add to playlist" , msg = AssistWithAddingTracksToPlaylist tracks , active = False } ]
queueActions : List IdentifiedTrack -> List (ContextMenu.Item Msg)queueActions identifiedTracks = [ Item { icon = Icons.update , label = "Play next" , msg = { inFront = True, tracks = identifiedTracks } |> Queue.AddTracks |> QueueMsg
-- , active = False } , Item { icon = Icons.update , label = "Add to queue" , msg = { inFront = False, tracks = identifiedTracks } |> Queue.AddTracks |> QueueMsg
-- , active = False } ]
-- VIEW MENU
viewMenu : Bool -> Maybe Grouping -> Coordinates -> ContextMenu MsgviewMenu onlyCachedTracks maybeGrouping = ContextMenu [ groupByDirectory (maybeGrouping == Just Directory) , groupByFirstAlphaCharacter (maybeGrouping == Just FirstAlphaCharacter) , groupByProcessingDate (maybeGrouping == Just AddedOn) , groupByTrackYear (maybeGrouping == Just TrackYear)
-- , Item { icon = Icons.filter_list , label = "Cached tracks only" , active = onlyCachedTracks , msg = TracksMsg Tracks.ToggleCachedOnly } ]
groupByDirectory isActive = Item { icon = ifThenElse isActive Icons.clear Icons.library_music , label = "Group by directory" , active = isActive
-- , msg = if isActive then TracksMsg Tracks.DisableGrouping
else TracksMsg (Tracks.GroupBy Directory) }
groupByFirstAlphaCharacter isActive = Item { icon = ifThenElse isActive Icons.clear Icons.library_music , label = "Group by first letter" , active = isActive
-- , msg = if isActive then TracksMsg Tracks.DisableGrouping
else TracksMsg (Tracks.GroupBy FirstAlphaCharacter) }
groupByProcessingDate isActive = Item { icon = ifThenElse isActive Icons.clear Icons.library_music , label = "Group by processing date" , active = isActive
-- , msg = if isActive then TracksMsg Tracks.DisableGrouping
else TracksMsg (Tracks.GroupBy AddedOn) }
groupByTrackYear isActive = Item { icon = ifThenElse isActive Icons.clear Icons.library_music , label = "Group by track year" , active = isActive
-- , msg = if isActive then TracksMsg Tracks.DisableGrouping
else TracksMsg (Tracks.GroupBy TrackYear) }