Adding initial playback bar logic.
This commit is contained in:
@@ -13,9 +13,12 @@ public abstract class FileRepository<TObject> : IRepository<TObject> where TObje
|
||||
|
||||
public FileRepository()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(DirectoryName) || Directory.Exists(DirectoryName) == false)
|
||||
if (string.IsNullOrWhiteSpace(DirectoryName))
|
||||
return;
|
||||
|
||||
if (Directory.Exists(DirectoryName) == false)
|
||||
Directory.CreateDirectory(DirectoryName);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Extension))
|
||||
return;
|
||||
|
||||
@@ -30,7 +33,7 @@ public abstract class FileRepository<TObject> : IRepository<TObject> where TObje
|
||||
|
||||
var fileInfoList = directoryInfo.EnumerateFiles("*." + Extension, SearchOption.TopDirectoryOnly).Where(x => x.Attributes.HasFlag(FileAttributes.Hidden) == false);
|
||||
|
||||
return fileInfoList.Select(fileInfo => fileInfo.FullName).ToList();
|
||||
return [.. fileInfoList.Select(fileInfo => fileInfo.FullName)];
|
||||
}
|
||||
|
||||
private void LoadFileNamesIntoMap(List<string> fileNames)
|
||||
|
||||
@@ -74,12 +74,17 @@ public class AudioImageExtractor : IAudioImageExtractor
|
||||
|
||||
private string? GetImagePath(string path)
|
||||
{
|
||||
string? directoryName = Path.GetDirectoryName(path);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(directoryName))
|
||||
return null;
|
||||
|
||||
string[] fileNames;
|
||||
string extension;
|
||||
|
||||
foreach (string searchPattern in _searchPatterns)
|
||||
{
|
||||
fileNames = GetFilesFromDirectory(path, searchPattern);
|
||||
fileNames = GetFilesFromDirectory(directoryName, searchPattern);
|
||||
|
||||
foreach (string fileName in fileNames)
|
||||
{
|
||||
|
||||
@@ -5,4 +5,9 @@ namespace Harmonia.Core.Playlists;
|
||||
public interface IPlaylistRepository : IRepository<Playlist>
|
||||
{
|
||||
Playlist? GetPlaylist(PlaylistSong playlistSong);
|
||||
void AddPlaylist();
|
||||
void RemovePlaylist(Playlist playlist);
|
||||
|
||||
event EventHandler<PlaylistAddedEventArgs> PlaylistAdded;
|
||||
event EventHandler<PlaylistRemovedEventArgs> PlaylistRemoved;
|
||||
}
|
||||
@@ -7,7 +7,7 @@ public class Playlist
|
||||
{
|
||||
public string UID { get; init; } = Guid.NewGuid().ToString();
|
||||
public string? Name { get; set; }
|
||||
public List<PlaylistSong> Songs { get; } = [];
|
||||
public List<PlaylistSong> Songs { get; init; } = []; // TODO: Change to "private init" once deserialization is fixed
|
||||
public List<GroupOption> GroupOptions { get; set; } = [];
|
||||
public List<SortOption> SortOptions { get; set; } = [];
|
||||
public bool IsLocked { get; set; }
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using Harmonia.Core.Data;
|
||||
namespace Harmonia.Core.Playlists;
|
||||
|
||||
namespace Harmonia.Core.Playlists;
|
||||
|
||||
public class PlaylistManager(IRepository<Playlist> playlistRepository) : IPlaylistManager
|
||||
public class PlaylistManager(IPlaylistRepository playlistRepository) : IPlaylistManager
|
||||
{
|
||||
private Playlist? _currentPlaylist;
|
||||
public Playlist? CurrentPlaylist
|
||||
|
||||
@@ -4,7 +4,26 @@ namespace Harmonia.Core.Playlists;
|
||||
|
||||
public class PlaylistRepository : JsonFileRepository<Playlist>, IPlaylistRepository
|
||||
{
|
||||
protected override string DirectoryName => string.Empty;
|
||||
protected override string DirectoryName => Path.Combine("Playlists");
|
||||
|
||||
public PlaylistRepository()
|
||||
{
|
||||
List<Playlist> playlists = Get();
|
||||
|
||||
foreach (Playlist playlist in playlists)
|
||||
{
|
||||
playlist.PlaylistUpdated += OnPlaylistUpdated;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlaylistUpdated(object? sender, PlaylistUpdatedEventArgs e)
|
||||
{
|
||||
if (sender is not Playlist playlist)
|
||||
return;
|
||||
|
||||
Save(playlist);
|
||||
//PlaylistUpdated?.Invoke(sender, e);
|
||||
}
|
||||
|
||||
public Playlist? GetPlaylist(PlaylistSong playlistSong)
|
||||
{
|
||||
@@ -24,4 +43,29 @@ public class PlaylistRepository : JsonFileRepository<Playlist>, IPlaylistReposit
|
||||
|
||||
throw new Exception("Unable to determine new fileName");
|
||||
}
|
||||
|
||||
public event EventHandler<PlaylistAddedEventArgs>? PlaylistAdded;
|
||||
//public event EventHandler<PlaylistUpdatedEventArgs>? PlaylistUpdated;
|
||||
public event EventHandler<PlaylistRemovedEventArgs>? PlaylistRemoved;
|
||||
|
||||
public void AddPlaylist()
|
||||
{
|
||||
Playlist playlist = new()
|
||||
{
|
||||
Name = "New Playlist"
|
||||
};
|
||||
|
||||
playlist.PlaylistUpdated += OnPlaylistUpdated;
|
||||
|
||||
Save(playlist);
|
||||
PlaylistAdded?.Invoke(this, new(playlist));
|
||||
}
|
||||
|
||||
public void RemovePlaylist(Playlist playlist)
|
||||
{
|
||||
playlist.PlaylistUpdated -= OnPlaylistUpdated;
|
||||
|
||||
Delete(playlist);
|
||||
PlaylistRemoved?.Invoke(this, new(playlist));
|
||||
}
|
||||
}
|
||||
@@ -5,5 +5,5 @@ namespace Harmonia.Core.Playlists;
|
||||
public class PlaylistSong(Song song)
|
||||
{
|
||||
public string UID { get; } = Guid.NewGuid().ToString();
|
||||
public Song Song { get; } = song;
|
||||
public Song Song { get; init; } = song;
|
||||
}
|
||||
Reference in New Issue
Block a user