Fixed PlaylistDetailViewModels's "Playlist" object not properly synchronizing (events, locking) to the playlist manager's current playlist at constructor time.
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Harmonia.Core.Player;
|
||||
|
||||
public class PlaylistChangedEventArgs(Playlist? oldPlaylist, Playlist? newPlaylist) : EventArgs
|
||||
{
|
||||
public Playlist? OldPlaylist { get; } = oldPlaylist;
|
||||
public Playlist? NewPlaylist { get; } = newPlaylist;
|
||||
}
|
||||
//public class PlaylistChangedEventArgs(Playlist? oldPlaylist, Playlist? newPlaylist) : EventArgs
|
||||
//{
|
||||
// public Playlist? OldPlaylist { get; } = oldPlaylist;
|
||||
// public Playlist? NewPlaylist { get; } = newPlaylist;
|
||||
//}
|
||||
@@ -11,7 +11,7 @@ public interface IPlaylistManager
|
||||
Playlist? FindPlaylistContaining(PlaylistSong playlistSong);
|
||||
Playlist? FindPlaylistContaining(string playlistSongUID);
|
||||
|
||||
event EventHandler? CurrentPlaylistChanged;
|
||||
event EventHandler<PlaylistChangedEventArgs>? CurrentPlaylistChanged;
|
||||
event EventHandler<PlaylistAddedEventArgs> PlaylistAdded;
|
||||
event EventHandler<PlaylistRemovedEventArgs> PlaylistRemoved;
|
||||
event EventHandler<PlaylistSaveFailedEventArgs>? PlaylistSaveFailed;
|
||||
|
||||
7
Harmonia.Core/Playlists/PlaylistChangedEventArgs.cs
Normal file
7
Harmonia.Core/Playlists/PlaylistChangedEventArgs.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Harmonia.Core.Playlists;
|
||||
|
||||
public class PlaylistChangedEventArgs(Playlist? oldPlaylist, Playlist? newPlaylist) : EventArgs
|
||||
{
|
||||
public readonly Playlist? OldPlaylist = oldPlaylist;
|
||||
public readonly Playlist? NewPlaylist = newPlaylist;
|
||||
}
|
||||
@@ -17,12 +17,14 @@ public class PlaylistManager : IPlaylistManager
|
||||
}
|
||||
set
|
||||
{
|
||||
Playlist? oldPlaylist = _currentPlaylist;
|
||||
_currentPlaylist = value;
|
||||
CurrentPlaylistChanged?.Invoke(this, new());
|
||||
|
||||
CurrentPlaylistChanged?.Invoke(this, new(oldPlaylist, _currentPlaylist));
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler? CurrentPlaylistChanged;
|
||||
public event EventHandler<PlaylistChangedEventArgs>? CurrentPlaylistChanged;
|
||||
public event EventHandler<PlaylistAddedEventArgs>? PlaylistAdded;
|
||||
public event EventHandler<PlaylistRemovedEventArgs>? PlaylistRemoved;
|
||||
public event EventHandler<PlaylistSaveFailedEventArgs>? PlaylistSaveFailed;
|
||||
|
||||
@@ -47,7 +47,16 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
public Playlist? Playlist
|
||||
{
|
||||
get => _playlist;
|
||||
private set => SetProperty(ref _playlist, value);
|
||||
private set
|
||||
{
|
||||
_playlist?.PlaylistUpdated -= OnPlaylistUpdated;
|
||||
_playlist = _playlistManager.CurrentPlaylist;
|
||||
_playlist?.PlaylistUpdated += OnPlaylistUpdated;
|
||||
|
||||
IsPlaylistLocked = Playlist?.IsLocked ?? false;
|
||||
|
||||
SetProperty(ref _playlist, value);
|
||||
}
|
||||
}
|
||||
|
||||
private PlaylistSong? _playingSong;
|
||||
@@ -273,14 +282,9 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
Playlist.MoveSong(oldIndex, newIndex);
|
||||
}
|
||||
|
||||
private void OnPlaylistChanged(object? sender, EventArgs e)
|
||||
private void OnPlaylistChanged(object? sender, PlaylistChangedEventArgs e)
|
||||
{
|
||||
Playlist?.PlaylistUpdated -= OnPlaylistUpdated;
|
||||
Playlist = _playlistManager.CurrentPlaylist;
|
||||
Playlist?.PlaylistUpdated += OnPlaylistUpdated;
|
||||
|
||||
IsPlaylistLocked = Playlist?.IsLocked ?? false;
|
||||
|
||||
Playlist = e.NewPlaylist;
|
||||
UpdateFilteredSongs();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user