From 0d575b85a0f149775f46b13a082f7040242785cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Sun, 1 Jan 2017 21:36:51 +0100 Subject: [PATCH] Fixed a bug in the Artists sorting --- .../ViewModels/CollectionArtistsViewModel.cs | 12 +++---- .../Database/Repositories/ArtistRepository.cs | 34 +++++++++++++------ .../Interfaces/IArtistRepository.cs | 2 +- Dopamine.Common/Database/Utils.cs | 27 --------------- Dopamine/Changelog.txt | 5 +-- Dopamine/Dopamine.wxs | 2 +- Dopamine/SharedAssemblyInfo.cs | 8 ++--- 7 files changed, 38 insertions(+), 52 deletions(-) diff --git a/Dopamine.CollectionModule/ViewModels/CollectionArtistsViewModel.cs b/Dopamine.CollectionModule/ViewModels/CollectionArtistsViewModel.cs index 94eb25bdf..afae87dfb 100644 --- a/Dopamine.CollectionModule/ViewModels/CollectionArtistsViewModel.cs +++ b/Dopamine.CollectionModule/ViewModels/CollectionArtistsViewModel.cs @@ -267,10 +267,7 @@ private async Task GetArtistsAsync(ArtistOrder artistOrder) try { // Get all artists from the database - IList artists = await this.artistRepository.GetArtistsAsync(); - - // Order the incoming Artists - List orderedArtists = await Common.Database.Utils.OrderArtistsAsync(artists, artistOrder); + IList artists = await this.artistRepository.GetArtistsAsync(artistOrder); // Create new ObservableCollection ObservableCollection artistViewModels = new ObservableCollection(); @@ -279,9 +276,10 @@ await Task.Run(() => { List tempArtistViewModels = new List(); - tempArtistViewModels.AddRange(orderedArtists.Select(art => new ArtistViewModel { Artist = art, IsHeader = false }).Where(avm => avm.Header.Equals("#"))); - tempArtistViewModels.AddRange(orderedArtists.Select(art => new ArtistViewModel { Artist = art, IsHeader = false }).Where(avm => !avm.Header.Equals("#"))); - + // Workaround to make sure the "#" GroupHeader is shown at the top of the list + tempArtistViewModels.AddRange(artists.Select(art => new ArtistViewModel { Artist = art, IsHeader = false }).Where(avm => avm.Header.Equals("#"))); + tempArtistViewModels.AddRange(artists.Select(art => new ArtistViewModel { Artist = art, IsHeader = false }).Where(avm => !avm.Header.Equals("#"))); + foreach (ArtistViewModel avm in tempArtistViewModels) { artistViewModels.Add(avm); diff --git a/Dopamine.Common/Database/Repositories/ArtistRepository.cs b/Dopamine.Common/Database/Repositories/ArtistRepository.cs index d50875356..0b7a35d0a 100644 --- a/Dopamine.Common/Database/Repositories/ArtistRepository.cs +++ b/Dopamine.Common/Database/Repositories/ArtistRepository.cs @@ -22,7 +22,7 @@ public ArtistRepository() #endregion #region IArtistRepository - public async Task> GetArtistsAsync() + public async Task> GetArtistsAsync(ArtistOrder artistOrder) { var artists = new List(); @@ -34,26 +34,40 @@ await Task.Run(() => { try { + var trackArtists = new List(); var albumArtists = new List(); // Get the Track Artists - artists = conn.Query("SELECT DISTINCT art.ArtistID, art.ArtistName FROM Artist art" + - " INNER JOIN Track tra ON art.ArtistID=tra.ArtistID" + - " INNER JOIN Folder fol ON tra.FolderID=fol.FolderID" + - " WHERE fol.ShowInCollection=1"); + trackArtists = conn.Query("SELECT DISTINCT art.ArtistID, art.ArtistName FROM Artist art" + + " INNER JOIN Track tra ON art.ArtistID=tra.ArtistID" + + " INNER JOIN Folder fol ON tra.FolderID=fol.FolderID" + + " WHERE fol.ShowInCollection=1"); // Get the Album Artists - albumArtists = conn.Query("SELECT DISTINCT alb.AlbumID, alb.AlbumTitle, alb.AlbumArtist, alb.Year, alb.ArtworkID, alb.DateLastSynced, alb.DateAdded FROM Album alb" + + var albums = conn.Query("SELECT DISTINCT alb.AlbumID, alb.AlbumTitle, alb.AlbumArtist, alb.Year, alb.ArtworkID, alb.DateLastSynced, alb.DateAdded FROM Album alb" + " INNER JOIN Track tra ON alb.AlbumID=tra.AlbumID" + " INNER JOIN Folder fol ON tra.FolderID=fol.FolderID" + " INNER JOIN Artist art ON tra.ArtistID=art.ArtistID" + - " WHERE tra.AlbumID=alb.AlbumID AND tra.ArtistID=tra.ArtistID AND fol.ShowInCollection=1").ToList().Select((a) => a.AlbumArtist).ToList(); + " WHERE tra.AlbumID=alb.AlbumID AND tra.ArtistID=tra.ArtistID AND fol.ShowInCollection=1"); - foreach (string albumArtist in albumArtists) + albumArtists = albums.Select((a) => a.AlbumArtist).ToList(); + + if (artistOrder == ArtistOrder.All | artistOrder == ArtistOrder.Track) + { + foreach (Artist trackArtist in trackArtists) + { + artists.Add(trackArtist); + } + } + + if (artistOrder == ArtistOrder.All | artistOrder == ArtistOrder.Album) { - if (!artists.Select((art) => art.ArtistName).Contains(albumArtist)) + foreach (string albumArtist in albumArtists) { - artists.Add(new Artist { ArtistID = -1, ArtistName = albumArtist }); + if (!artists.Select((art) => art.ArtistName).Contains(albumArtist)) + { + artists.Add(new Artist { ArtistName = albumArtist }); + } } } } diff --git a/Dopamine.Common/Database/Repositories/Interfaces/IArtistRepository.cs b/Dopamine.Common/Database/Repositories/Interfaces/IArtistRepository.cs index 9ba7c8ba7..ebc2ad549 100644 --- a/Dopamine.Common/Database/Repositories/Interfaces/IArtistRepository.cs +++ b/Dopamine.Common/Database/Repositories/Interfaces/IArtistRepository.cs @@ -6,7 +6,7 @@ namespace Dopamine.Common.Database.Repositories.Interfaces { public interface IArtistRepository { - Task> GetArtistsAsync(); + Task> GetArtistsAsync(ArtistOrder artistOrder); Task GetArtistAsync(string artistName); Task AddArtistAsync(Artist artist); Task DeleteOrphanedArtistsAsync(); diff --git a/Dopamine.Common/Database/Utils.cs b/Dopamine.Common/Database/Utils.cs index 7d01509dc..bccb6ef2f 100644 --- a/Dopamine.Common/Database/Utils.cs +++ b/Dopamine.Common/Database/Utils.cs @@ -81,33 +81,6 @@ public static string GetSortableString(string originalString, bool removePrefix return returnString; } - public static async Task> OrderArtistsAsync(IList artists, ArtistOrder artistOrder) - { - var orderedArtists = new List(); - - await Task.Run(() => - { - switch (artistOrder) - { - case ArtistOrder.All: - orderedArtists = artists.OrderBy((a) => Utils.GetSortableString(a.ArtistName, true)).ToList(); - break; - case ArtistOrder.Track: - orderedArtists = artists.Where((a) => a.ArtistID != -1).OrderBy((a) => Utils.GetSortableString(a.ArtistName, true)).ToList(); - break; - case ArtistOrder.Album: - orderedArtists = artists.Where((a) => a.ArtistID == -1).OrderBy((a) => Utils.GetSortableString(a.ArtistName, true)).ToList(); - break; - default: - // All - orderedArtists = artists.OrderBy((a) => Utils.GetSortableString(a.ArtistName, true)).ToList(); - break; - } - }); - - return orderedArtists; - } - public static async Task> OrderGenresAsync(IList genres, GenreOrder genreOrder) { var orderedGenres = new List(); diff --git a/Dopamine/Changelog.txt b/Dopamine/Changelog.txt index 8ff2ec52c..8cfcb4976 100644 --- a/Dopamine/Changelog.txt +++ b/Dopamine/Changelog.txt @@ -1,7 +1,8 @@ -2017-01-01: Dopamine 1.2.3 Build 858 (Release) +2017-01-01: Dopamine 1.2.3 Build 859 (Release) ---------------------------------------------- -- [Fixed] Instability on 32-bit Windows versions. +- [Fixed] Instability on 32-bit Windows versions +- [Fixed] Fixed a bug in the Artists sorting 2016-12-30: Dopamine 1.2.2 Build 857 (Release) diff --git a/Dopamine/Dopamine.wxs b/Dopamine/Dopamine.wxs index 1877dde94..a5c72fe22 100644 --- a/Dopamine/Dopamine.wxs +++ b/Dopamine/Dopamine.wxs @@ -1,5 +1,5 @@ - + diff --git a/Dopamine/SharedAssemblyInfo.cs b/Dopamine/SharedAssemblyInfo.cs index a28e7aa5e..550a6b34e 100644 --- a/Dopamine/SharedAssemblyInfo.cs +++ b/Dopamine/SharedAssemblyInfo.cs @@ -2,11 +2,11 @@ [assembly: AssemblyCompany("Digimezzo")] [assembly: AssemblyCopyright("Copyright Digimezzo © 2014 - 2017")] -[assembly: AssemblyVersion("1.2.858.3")] -[assembly: AssemblyFileVersion("1.2.858.3")] +[assembly: AssemblyVersion("1.2.859.3")] +[assembly: AssemblyFileVersion("1.2.859.3")] #if DEBUG -[assembly: AssemblyInformationalVersion("1.2.858.3 Preview")] +[assembly: AssemblyInformationalVersion("1.2.859.3 Preview")] #else -[assembly: AssemblyInformationalVersion("1.2.858.3")] +[assembly: AssemblyInformationalVersion("1.2.859.3")] #endif