Skip to content

Commit

Permalink
(#85) keep track of both album and albumsort
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue committed Mar 28, 2024
1 parent ac82f89 commit 3359fee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions Sources/Stylophone.Common/ViewModels/Bases/LibraryViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@

namespace Stylophone.Common.ViewModels
{

public abstract partial class LibraryViewModelBase : ViewModelBase
{
private record Album
{
public string Name { get; set; }
public string SortName { get; set; }
}

private INavigationService _navigationService;
private MPDConnectionService _mpdService;
private AlbumViewModelFactory _albumVmFactory;
Expand All @@ -40,9 +47,13 @@ public async Task LoadDataAsync()
FilteredSource.CollectionChanged += (s, e) => OnPropertyChanged(nameof(IsSourceEmpty));

Source.Clear();
var response = await _mpdService.SafelySendCommandAsync(new ListCommand(MpdTags.AlbumSort));
var albumList = await _mpdService.SafelySendCommandAsync(new ListCommand(MpdTags.Album));
var albumSortList = await _mpdService.SafelySendCommandAsync(new ListCommand(MpdTags.AlbumSort));

// Create a list of tuples
var response = albumList.Zip(albumSortList, (album, albumSort) => new Album{ Name = album, SortName = albumSort });

if (response != null)
if (albumSortList != null)
GroupAlbumsByName(response);

if (Source.Count > 0)
Expand All @@ -63,10 +74,10 @@ public void FilterLibrary(string text)
AddBack(filtered);
}

public void GroupAlbumsByName(List<string> albums)
private void GroupAlbumsByName(IEnumerable<Album> albums)
{
var query = from item in albums
group item by GetGroupHeader(item) into g
group item by GetGroupHeader(item.SortName) into g
orderby g.Key
select new { GroupName = g.Key, Items = g };

Expand All @@ -76,9 +87,9 @@ orderby g.Key
//GroupInfosList info = new GroupInfosList();
//info.Key = g.GroupName + " (" + g.Items.Count() + ")";

foreach (var item in g.Items.OrderBy(s => s.ToLower()))
foreach (var item in g.Items.OrderBy(s => s.SortName.ToLower()))
{
Source.Add(_albumVmFactory.GetAlbumViewModel(item));
Source.Add(_albumVmFactory.GetAlbumViewModel(item.Name));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Stylophone/Stylophone.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
<PackageReference Include="Microsoft.UI.Xaml" Version="2.7.3" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed" Version="2.0.1" />
<PackageReference Include="MpcNET" Version="1.5.0" />
<PackageReference Include="SkiaSharp.Views" Version="2.88.1" />
<PackageReference Include="SkiaSharp.Views" Version="2.88.5" />
<PackageReference Include="VideoLAN.LibVLC.UWP" Version="3.3.2" />
<PackageReference Include="WindowsStateTriggers">
<Version>1.1.0</Version>
Expand Down

0 comments on commit 3359fee

Please sign in to comment.