Added playlists view. Added messaging service. Added logic for adding and deleting playlists.
This commit is contained in:
65
Harmonia.WinUI/ViewModels/PlaylistsViewModel.cs
Normal file
65
Harmonia.WinUI/ViewModels/PlaylistsViewModel.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Harmonia.Core.Playlists;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Harmonia.WinUI.ViewModels;
|
||||
|
||||
public partial class PlaylistsViewModel : ViewModelBase
|
||||
{
|
||||
private readonly IPlaylistManager _playlistManager;
|
||||
|
||||
private ObservableCollection<Playlist> _playlists = [];
|
||||
public ObservableCollection<Playlist> Playlists
|
||||
{
|
||||
get
|
||||
{
|
||||
return _playlists;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _playlists, value);
|
||||
}
|
||||
}
|
||||
|
||||
private Playlist? _selectedPlaylist = null;
|
||||
public Playlist? SelectedPlaylist
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selectedPlaylist;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _selectedPlaylist, value))
|
||||
{
|
||||
_playlistManager.CurrentPlaylist = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PlaylistsViewModel(IPlaylistManager playlistManager)
|
||||
{
|
||||
_playlistManager = playlistManager;
|
||||
_playlistManager.PlaylistAdded += OnPlaylistAdded;
|
||||
_playlistManager.PlaylistRemoved += OnPlaylistRemoved;
|
||||
_playlistManager.CurrentPlaylistChanged += OnCurrentPlaylistChanged;
|
||||
|
||||
_playlists = new(_playlistManager.Playlists);
|
||||
_selectedPlaylist = _playlistManager.CurrentPlaylist;
|
||||
}
|
||||
|
||||
private void OnCurrentPlaylistChanged(object? sender, EventArgs e)
|
||||
{
|
||||
SelectedPlaylist = _playlistManager.CurrentPlaylist;
|
||||
}
|
||||
|
||||
private void OnPlaylistAdded(object? sender, PlaylistAddedEventArgs e)
|
||||
{
|
||||
Playlists.Add(e.Playlist);
|
||||
}
|
||||
|
||||
private void OnPlaylistRemoved(object? sender, PlaylistRemovedEventArgs e)
|
||||
{
|
||||
Playlists.Remove(e.Playlist);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user