Skip to content

Commit

Permalink
Fixed a bug in the Artists sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
raphgodart committed Jan 1, 2017
1 parent 29206ed commit 0d575b8
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,7 @@ private async Task GetArtistsAsync(ArtistOrder artistOrder)
try
{
// Get all artists from the database
IList<Artist> artists = await this.artistRepository.GetArtistsAsync();

// Order the incoming Artists
List<Artist> orderedArtists = await Common.Database.Utils.OrderArtistsAsync(artists, artistOrder);
IList<Artist> artists = await this.artistRepository.GetArtistsAsync(artistOrder);

// Create new ObservableCollection
ObservableCollection<ArtistViewModel> artistViewModels = new ObservableCollection<ArtistViewModel>();
Expand All @@ -279,9 +276,10 @@ await Task.Run(() =>
{
List<ArtistViewModel> tempArtistViewModels = new List<ArtistViewModel>();

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);
Expand Down
34 changes: 24 additions & 10 deletions Dopamine.Common/Database/Repositories/ArtistRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ArtistRepository()
#endregion

#region IArtistRepository
public async Task<List<Artist>> GetArtistsAsync()
public async Task<List<Artist>> GetArtistsAsync(ArtistOrder artistOrder)
{
var artists = new List<Artist>();

Expand All @@ -34,26 +34,40 @@ await Task.Run(() =>
{
try
{
var trackArtists = new List<Artist>();
var albumArtists = new List<string>();

// Get the Track Artists
artists = conn.Query<Artist>("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<Artist>("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<Album>("SELECT DISTINCT alb.AlbumID, alb.AlbumTitle, alb.AlbumArtist, alb.Year, alb.ArtworkID, alb.DateLastSynced, alb.DateAdded FROM Album alb" +
var albums = conn.Query<Album>("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 });
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Dopamine.Common.Database.Repositories.Interfaces
{
public interface IArtistRepository
{
Task<List<Artist>> GetArtistsAsync();
Task<List<Artist>> GetArtistsAsync(ArtistOrder artistOrder);
Task<Artist> GetArtistAsync(string artistName);
Task<Artist> AddArtistAsync(Artist artist);
Task DeleteOrphanedArtistsAsync();
Expand Down
27 changes: 0 additions & 27 deletions Dopamine.Common/Database/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,6 @@ public static string GetSortableString(string originalString, bool removePrefix
return returnString;
}

public static async Task<List<Artist>> OrderArtistsAsync(IList<Artist> artists, ArtistOrder artistOrder)
{
var orderedArtists = new List<Artist>();

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<List<Genre>> OrderGenresAsync(IList<Genre> genres, GenreOrder genreOrder)
{
var orderedGenres = new List<Genre>();
Expand Down
5 changes: 3 additions & 2 deletions Dopamine/Changelog.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Dopamine/Dopamine.wxs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<?define Version="1.2.858.3" ?>
<?define Version="1.2.859.3" ?>
<?define Manufacturer="Digimezzo" ?>
<?define Product="Dopamine" ?>
<?define ProductCab="Dopamine.cab" ?>
Expand Down
8 changes: 4 additions & 4 deletions Dopamine/SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0d575b8

Please sign in to comment.