Added audio player logic and tests.
This commit is contained in:
@@ -5,11 +5,9 @@ namespace Harmonia.Core.Playlists;
|
||||
|
||||
public class Playlist
|
||||
{
|
||||
private readonly List<PlaylistSong> _songs = [];
|
||||
|
||||
public string UID { get; init; } = Guid.NewGuid().ToString();
|
||||
public string? Name { get; set; }
|
||||
public IReadOnlyList<PlaylistSong> Songs => _songs;
|
||||
public List<PlaylistSong> Songs { get; } = [];
|
||||
public List<GroupOption> GroupOptions { get; set; } = [];
|
||||
public List<SortOption> SortOptions { get; set; } = [];
|
||||
public bool IsLocked { get; set; }
|
||||
@@ -35,7 +33,7 @@ public class Playlist
|
||||
|
||||
int insertIndex = index ?? Songs.Count;
|
||||
|
||||
_songs.InsertRange(insertIndex, playlistSongs);
|
||||
Songs.InsertRange(insertIndex, playlistSongs);
|
||||
|
||||
PlaylistUpdatedEventArgs eventArgs = new()
|
||||
{
|
||||
@@ -50,7 +48,7 @@ public class Playlist
|
||||
|
||||
public void MoveSong(PlaylistSong playlistSong, int newIndex)
|
||||
{
|
||||
int currentIndex = _songs.IndexOf(playlistSong);
|
||||
int currentIndex = Songs.IndexOf(playlistSong);
|
||||
|
||||
MoveSong(currentIndex, newIndex);
|
||||
}
|
||||
@@ -65,8 +63,8 @@ public class Playlist
|
||||
|
||||
PlaylistSong playlistSong = Songs[oldIndex];
|
||||
|
||||
_songs.Remove(playlistSong);
|
||||
_songs.Insert(newIndex, playlistSong);
|
||||
Songs.Remove(playlistSong);
|
||||
Songs.Insert(newIndex, playlistSong);
|
||||
|
||||
PlaylistUpdatedEventArgs eventArgs = new()
|
||||
{
|
||||
@@ -83,8 +81,8 @@ public class Playlist
|
||||
public void SortSongs(PlaylistSong[] playlistSongs, SortOption[] sortOptions)
|
||||
{
|
||||
Dictionary<int, PlaylistSong> oldPlaylistSongs = playlistSongs
|
||||
.OrderBy(_songs.IndexOf)
|
||||
.ToDictionary(_songs.IndexOf, playlistSong => playlistSong);
|
||||
.OrderBy(Songs.IndexOf)
|
||||
.ToDictionary(Songs.IndexOf, playlistSong => playlistSong);
|
||||
|
||||
Song[] songs = playlistSongs.Select(playlistSong => playlistSong.Song).ToArray();
|
||||
Song[] sortedSongs = [.. songs.SortBy(sortOptions)];
|
||||
@@ -100,8 +98,8 @@ public class Playlist
|
||||
if (newPlaylistSong == playlistSong)
|
||||
continue;
|
||||
|
||||
_songs.RemoveAt(index);
|
||||
_songs.Insert(index, newPlaylistSong);
|
||||
Songs.RemoveAt(index);
|
||||
Songs.Insert(index, newPlaylistSong);
|
||||
}
|
||||
|
||||
PlaylistUpdatedEventArgs eventArgs = new()
|
||||
@@ -122,7 +120,7 @@ public class Playlist
|
||||
|
||||
public void RemoveSongs(int index, int count)
|
||||
{
|
||||
PlaylistSong[] playlistSongs = [.. _songs.GetRange(index, count)];
|
||||
PlaylistSong[] playlistSongs = [.. Songs.GetRange(index, count)];
|
||||
|
||||
RemoveSongs(playlistSongs);
|
||||
}
|
||||
@@ -141,7 +139,7 @@ public class Playlist
|
||||
|
||||
foreach (PlaylistSong playlistSong in playlistSongs)
|
||||
{
|
||||
if (_songs.Remove(playlistSong))
|
||||
if (Songs.Remove(playlistSong))
|
||||
{
|
||||
removedSongs.Add(playlistSong);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user