diff --git a/src/Applications/UI/Common/State.elm b/src/Applications/UI/Common/State.elm index 0562370a..d218076f 100644 --- a/src/Applications/UI/Common/State.elm +++ b/src/Applications/UI/Common/State.elm @@ -10,9 +10,11 @@ import Notifications exposing (Notification) import Return exposing (return) import Return.Ext as Return import Task +import Tracks import UI.Notifications import UI.Page as Page exposing (Page) import UI.Playlists.Directory +import UI.Tracks.Scene.Covers import UI.Tracks.Scene.List import UI.Types as UI exposing (Manager, Msg) @@ -37,10 +39,19 @@ dismissNotification options model = forceTracksRerender : Manager -forceTracksRerender = - Browser.Dom.setViewportOf UI.Tracks.Scene.List.containerId 0 1 +forceTracksRerender model = + let + containerId = + case model.scene of + Tracks.Covers -> + UI.Tracks.Scene.Covers.containerId + + Tracks.List -> + UI.Tracks.Scene.List.containerId + in + Browser.Dom.setViewportOf containerId 0 1 |> Task.attempt (always UI.Bypass) - |> Return.communicate + |> return model generateDirectoryPlaylists : Manager diff --git a/src/Applications/UI/Tracks/Scene/Covers.elm b/src/Applications/UI/Tracks/Scene/Covers.elm index 9b27cf9a..4b15b733 100644 --- a/src/Applications/UI/Tracks/Scene/Covers.elm +++ b/src/Applications/UI/Tracks/Scene/Covers.elm @@ -42,10 +42,12 @@ type alias Dependencies = , cachedCovers : Maybe (Dict String String) , covers : List Cover , darkMode : Bool + , favouritesOnly : Bool , infiniteList : InfiniteList.Model , isVisible : Bool , nowPlaying : Maybe Queue.Item , selectedCover : Maybe Cover + , selectedTrackIndexes : List Int , sortBy : SortBy , sortDirection : SortDirection , viewportHeight : Float @@ -210,15 +212,13 @@ singleCoverView cover deps = -- , headerButton - [ cover.tracks - |> List.head - |> Maybe.withDefault cover.identifiedTrackCover - |> Queue.InjectFirstAndPlay + [ { inFront = False, tracks = cover.tracks } + |> Queue.AddTracks |> QueueMsg |> E.onClick ] { active = True - , label = text "Play" + , label = text "Add to queue" } ] @@ -238,15 +238,17 @@ singleCoverView cover deps = [ C.flex_auto , C.ml_5 , C.select_none + , C.subpixel_antialiased ] (List.indexedMap (UI.Tracks.Scene.List.defaultItemView { derivedColors = derivedColors - , favouritesOnly = False + , favouritesOnly = deps.favouritesOnly , nowPlaying = deps.nowPlaying - , selectedTrackIndexes = [] + , roundedCorners = True + , selectedTrackIndexes = deps.selectedTrackIndexes , showAlbum = False - , showArtist = False + , showArtist = not cover.sameArtist , showGroup = False } 0 @@ -426,19 +428,14 @@ rowView itemDeps _ idx row = itemView : ItemDependencies -> Cover -> Html Msg itemView deps cover = brick - -- [ cover.identifiedTrack - -- |> Queue.InjectFirstAndPlay - -- |> QueueMsg - -- |> Decode.succeed - -- |> E.on "dbltap" - -- ] [ cover |> SelectCover |> TracksMsg |> Decode.succeed |> E.on "tap" ] - [ C.font_semibold + [ C.flex_shrink_0 + , C.font_semibold , C.mb_5 , C.w_1_div_4 ] diff --git a/src/Applications/UI/Tracks/Scene/List.elm b/src/Applications/UI/Tracks/Scene/List.elm index 3bd825bd..aa20f4d1 100644 --- a/src/Applications/UI/Tracks/Scene/List.elm +++ b/src/Applications/UI/Tracks/Scene/List.elm @@ -161,6 +161,9 @@ viewAttributes = header : Bool -> Bool -> SortBy -> SortDirection -> Html Msg header isPlaylist showAlbum sortBy sortDirection = let + showArtist = + True + sortIcon = (if sortDirection == Desc then Icons.expand_less @@ -214,10 +217,15 @@ header isPlaylist showAlbum sortBy sortDirection = , headerColumn "Album" 29.0 (maybeSortIcon Album) (TracksMsg <| SortBy Album) ] + else if not showArtist then + [ headerColumn "" 5.75 Nothing Bypass + , headerColumn "Title" 94.25 (maybeSortIcon Title) (TracksMsg <| SortBy Title) + ] + else - [ headerColumn "" 4.5 Nothing Bypass - , headerColumn "Title" 52 (maybeSortIcon Title) (TracksMsg <| SortBy Title) - , headerColumn "Artist" 43.5 (maybeSortIcon Artist) (TracksMsg <| SortBy Artist) + [ headerColumn "" 5.75 Nothing Bypass + , headerColumn "Title" 51.25 (maybeSortIcon Title) (TracksMsg <| SortBy Title) + , headerColumn "Artist" 43 (maybeSortIcon Artist) (TracksMsg <| SortBy Artist) ] ) @@ -309,6 +317,7 @@ infiniteListView deps harvest infiniteList favouritesOnly searchTerm ( nowPlayin { derivedColors = derivedColors , favouritesOnly = favouritesOnly , nowPlaying = nowPlaying + , roundedCorners = False , selectedTrackIndexes = selectedTrackIndexes , showAlbum = deps.showAlbum , showArtist = True @@ -399,6 +408,7 @@ defaultItemView : { derivedColors : DerivedColors , favouritesOnly : Bool , nowPlaying : Maybe Queue.Item + , roundedCorners : Bool , selectedTrackIndexes : List Int , showAlbum : Bool , showArtist : Bool @@ -410,7 +420,7 @@ defaultItemView : -> Html Msg defaultItemView args _ idx identifiedTrack = let - { derivedColors, favouritesOnly, nowPlaying, selectedTrackIndexes, showAlbum, showArtist, showGroup } = + { derivedColors, favouritesOnly, nowPlaying, roundedCorners, selectedTrackIndexes, showAlbum, showArtist, showGroup } = args ( identifiers, track ) = @@ -474,6 +484,7 @@ defaultItemView args _ idx identifiedTrack = -- , ifThenElse identifiers.isMissing "" C.cursor_pointer , ifThenElse isSelected C.font_semibold "" + , ifThenElse roundedCorners C.rounded_l "" -- , ifThenElse @@ -505,13 +516,13 @@ defaultItemView args _ idx identifiedTrack = else if not showArtist then [ favouriteColumn "5.75%" favouritesOnly favIdentifiers derivedColors - , otherColumn "80%" False track.tags.title + , otherColumn "94.25%" False track.tags.title ] else - [ favouriteColumn defFavColWidth favouritesOnly favIdentifiers derivedColors - , otherColumn "52%" False track.tags.title - , otherColumn "43.5%" False track.tags.artist + [ favouriteColumn "5.75%" favouritesOnly favIdentifiers derivedColors + , otherColumn "51.25%" False track.tags.title + , otherColumn "43%" False track.tags.artist ] ) ] diff --git a/src/Applications/UI/Tracks/State.elm b/src/Applications/UI/Tracks/State.elm index a9019bc0..56193ce3 100644 --- a/src/Applications/UI/Tracks/State.elm +++ b/src/Applications/UI/Tracks/State.elm @@ -192,6 +192,7 @@ changeScene scene model = Cmd.none ) |> return { model | scene = scene, selectedCover = Nothing } + |> andThen Common.forceTracksRerender |> andThen User.saveEnclosedUserData @@ -220,7 +221,7 @@ clearSearch model = deselectCover : Manager deselectCover model = - Return.singleton { model | selectedCover = Nothing } + Common.forceTracksRerender { model | selectedCover = Nothing } download : String -> List Track -> Manager @@ -324,14 +325,35 @@ generateCovers model = |> List.map (\( firstIdentifiedTrack, identifiedTracks ) -> let + firstArtist = + firstIdentifiedTrack + |> Tuple.second + |> .tags + |> .artist + allIdentifiedTracks = firstIdentifiedTrack :: identifiedTracks + ( tracksWithCoverKeys, sameArtist ) = + List.foldl + (\( i, t ) ( acc, sa ) -> + ( ( coverKey t, ( i, t ) ) :: acc + , if sa then + t.tags.artist == firstArtist + + else + False + ) + ) + ( [] + , True + ) + allIdentifiedTracks + -- Group the tracks by their `coverKey`, -- and pick a track from the biggest group. ( identifiers, track ) = - allIdentifiedTracks - |> List.map (\( i, t ) -> ( coverKey t, ( i, t ) )) + tracksWithCoverKeys |> List.sortBy Tuple.first |> List.groupWhile (\( a, _ ) ( b, _ ) -> a == b) |> List.sortBy (Tuple.second >> List.length) @@ -355,6 +377,9 @@ generateCovers model = _ -> "album" + -- + , sameArtist = sameArtist + -- , trackFilename = track.path @@ -367,8 +392,17 @@ generateCovers model = , tracks = allIdentifiedTracks } ) - |> (\covers -> { model | covers = covers }) + |> (\covers -> + { model + | covers = covers + , selectedCover = + Maybe.andThen + (\sc -> List.find (.key >> (==) sc.key) covers) + model.selectedCover + } + ) |> Return.communicate (Ports.loadAlbumCovers ()) + |> andThen Common.forceTracksRerender gotCachedCover : Json.Value -> Manager diff --git a/src/Applications/UI/Tracks/View.elm b/src/Applications/UI/Tracks/View.elm index 9aeb5fa9..4a1d2e69 100644 --- a/src/Applications/UI/Tracks/View.elm +++ b/src/Applications/UI/Tracks/View.elm @@ -73,10 +73,12 @@ view model = , cachedCovers = model.cachedCovers , covers = model.covers , darkMode = model.darkMode + , favouritesOnly = model.favouritesOnly , infiniteList = model.infiniteList , isVisible = isOnIndexPage , nowPlaying = model.nowPlaying , selectedCover = model.selectedCover + , selectedTrackIndexes = model.selectedTrackIndexes , sortBy = model.sortBy , sortDirection = model.sortDirection , viewportHeight = model.viewport.height diff --git a/src/Library/Tracks.elm b/src/Library/Tracks.elm index eef26589..0cbd3248 100644 --- a/src/Library/Tracks.elm +++ b/src/Library/Tracks.elm @@ -49,6 +49,7 @@ type alias Cover = { focus : String , identifiedTrackCover : IdentifiedTrack , key : String + , sameArtist : Bool , trackFilename : String , trackIds : List String , tracks : List IdentifiedTrack