refactored favorites to mostplayed

Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
Matt Bruce 2016-09-05 19:18:41 -05:00
parent 6923b5f73a
commit e2d1859a8f
3 changed files with 23 additions and 23 deletions

View File

@ -39,9 +39,9 @@ namespace KaraokePlayer.Classes
{ {
get { return string.Format("controllers/{0}/player/queue/0/", this.Id); } get { return string.Format("controllers/{0}/player/queue/0/", this.Id); }
} }
private string FavoritesPath private string MostPlayedPath
{ {
get { return string.Format("controllers/{0}/favorites/", this.Id); } get { return string.Format("controllers/{0}/mostPlayed/", this.Id); }
} }
public string Id { get; set; } public string Id { get; set; }
@ -119,7 +119,7 @@ namespace KaraokePlayer.Classes
{ {
CurrentSong = item.Song; CurrentSong = item.Song;
_songChanged(new ControllerSongChangedEventArgs(item.Song)); _songChanged(new ControllerSongChangedEventArgs(item.Song));
UpdateFavorites(item.Song); UpdateMostPlayed(item.Song);
} }
} }
@ -134,33 +134,33 @@ namespace KaraokePlayer.Classes
_stateChanged(new ControllerStateChangedEventArgs(newstate)); _stateChanged(new ControllerStateChangedEventArgs(newstate));
} }
private void UpdateFavorites(Song song) private void UpdateMostPlayed(Song song)
{ {
//get favorites //get MostPlayed
FavoriteSong favorite = null; MostPlayedSong mostPlayed = null;
List<FavoriteSong> favorites = _client.Get(FavoritesPath).ResultAs<List<FavoriteSong>>(); List<MostPlayedSong> mostPlays = _client.Get(MostPlayedPath).ResultAs<List<MostPlayedSong>>();
if (favorites == null) favorites = new List<FavoriteSong>(); if (mostPlays == null) mostPlays = new List<MostPlayedSong>();
//unique song is based on the path //unique song is based on the path
favorite = favorites.SingleOrDefault(f => f.Path == song.Path); mostPlayed = mostPlays.SingleOrDefault(f => f.Path == song.Path);
if (favorite == null) if (mostPlayed == null)
{ {
favorite = new FavoriteSong(); mostPlayed = new MostPlayedSong();
favorite.Artist = song.Artist; mostPlayed.Artist = song.Artist;
favorite.Title = song.Title; mostPlayed.Title = song.Title;
favorite.Genre = song.Genre; mostPlayed.Genre = song.Genre;
favorite.Path = song.Path; mostPlayed.Path = song.Path;
favorite.Year = song.Year; mostPlayed.Year = song.Year;
favorite.Count = 1; mostPlayed.Count = 1;
favorites.Add(favorite); mostPlays.Add(mostPlayed);
} }
else { else {
favorite.Count += 1; mostPlayed.Count += 1;
} }
//take the top 100 songs //take the top 100 songs
var top100 = favorites.OrderByDescending(f => f.Count).Take(100); var top100 = mostPlays.OrderByDescending(f => f.Count).Take(100);
_client.Set(FavoritesPath, top100); _client.Set(MostPlayedPath, top100);
} }
} }

View File

@ -44,7 +44,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="FavoriteSong.cs" /> <Compile Include="MostPlayedSong.cs" />
<Compile Include="FileType.cs" /> <Compile Include="FileType.cs" />
<Compile Include="PlayerState.cs" /> <Compile Include="PlayerState.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Herse.Models namespace Herse.Models
{ {
public class FavoriteSong : Song public class MostPlayedSong : Song
{ {
[JsonProperty("count")] [JsonProperty("count")]
public int Count { get; set; } public int Count { get; set; }