Made repository methods asynchronous. Simplified playlist repository. Use playlist manager in the app, and left playlist repository to only be used by the playlist manager.

This commit is contained in:
2026-07-24 09:49:58 -04:00
parent 0acbab1215
commit 63938b0139
14 changed files with 181 additions and 96 deletions

View File

@@ -30,6 +30,7 @@ namespace Harmonia.WinUI.ViewModels;
public partial class PlaylistViewModel : ViewModelBase
{
private readonly IPlaylistManager _playlistManager;
private readonly IAudioPlayer _audioPlayer;
private readonly IAudioImageCache _audioImageCache;
private readonly IAudioBitmapImageCache _audioBitmapImageCache;
@@ -133,8 +134,11 @@ public partial class PlaylistViewModel : ViewModelBase
IAudioFileScanner audioFileScanner,
IAudioEngine audioEngine,
IStorageProvider storageProvider,
IPlaylistRepository playlistRepository)
IPlaylistManager playlistManager)
{
_playlistManager = playlistManager;
//_playlistManager.CurrentPlaylistChanged += OnPlaylistChanged;
_audioPlayer = audioPlayer;
_audioPlayer.PlaylistChanged += OnPlaylistChanged;
_audioPlayer.PlayingSongChanged += OnPlayingSongChanged;
@@ -148,8 +152,11 @@ public partial class PlaylistViewModel : ViewModelBase
FilteredPlaylistSongs.CollectionChanged += OnFilteredPlaylistSongsCollectionChanged;
Playlist = _playlistManager.CurrentPlaylist; // Testing
UpdatePlaylistSongs(Playlist);
// Testing
Task.Run(() => PlayDemoSong(playlistRepository));
//Task.Run(() => PlayDemoSong(playlistRepository));
}
private void OnFilteredPlaylistSongsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
@@ -160,17 +167,25 @@ public partial class PlaylistViewModel : ViewModelBase
int x = 1;
}
private async Task PlayDemoSong(IPlaylistRepository playlistRepository)
//private async Task PlayDemoSong(IPlaylistRepository playlistRepository)
//{
// if (playlistRepository.Get().Count == 0)
// {
// playlistRepository.AddPlaylist();
// }
// Playlist playlist = playlistRepository.Get().First();
// if (playlist.Songs.Count > 0)
// await _audioPlayer.LoadAsync(playlist.Songs[0], PlaybackMode.LoadOnly);
//}
private void UpdatePlaylistSongs(Playlist? playlist)
{
if (playlistRepository.Get().Count == 0)
{
playlistRepository.AddPlaylist();
}
PlaylistSong[] playlistSongs = playlist?.Songs.ToArray() ?? [];
Playlist playlist = playlistRepository.Get().First();
if (playlist.Songs.Count > 0)
await _audioPlayer.LoadAsync(playlist.Songs[0], PlaybackMode.LoadOnly);
PlaylistSongs = [.. playlistSongs];
UpdateFilteredSongs();
}
private void OnPlaylistChanged(object? sender, EventArgs e)