65 lines
1.6 KiB
C#
65 lines
1.6 KiB
C#
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);
|
|
}
|
|
} |