Highlight active playlist. Various optimizations and fixes.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Harmonia.Core.Player;
|
||||
using Harmonia.Core.Playlists;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -9,6 +9,7 @@ namespace Harmonia.WinUI.ViewModels;
|
||||
public partial class PlaylistsViewModel : ViewModelBase
|
||||
{
|
||||
private readonly IPlaylistManager _playlistManager;
|
||||
private readonly IAudioPlayer _audioPlayer;
|
||||
|
||||
private ObservableCollection<PlaylistItemViewModel> _playlists = [];
|
||||
public ObservableCollection<PlaylistItemViewModel> Playlists
|
||||
@@ -39,13 +40,29 @@ public partial class PlaylistsViewModel : ViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
public PlaylistsViewModel(IPlaylistManager playlistManager)
|
||||
private PlaylistItemViewModel? _activePlaylist = null;
|
||||
public PlaylistItemViewModel? ActivePlaylist
|
||||
{
|
||||
get
|
||||
{
|
||||
return _activePlaylist;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _activePlaylist, value);
|
||||
}
|
||||
}
|
||||
|
||||
public PlaylistsViewModel(IPlaylistManager playlistManager, IAudioPlayer audioPlayer)
|
||||
{
|
||||
_playlistManager = playlistManager;
|
||||
_playlistManager.PlaylistAdded += OnPlaylistAdded;
|
||||
_playlistManager.PlaylistRemoved += OnPlaylistRemoved;
|
||||
_playlistManager.CurrentPlaylistChanged += OnCurrentPlaylistChanged;
|
||||
|
||||
_audioPlayer = audioPlayer;
|
||||
_audioPlayer.PlayingSongChanged += OnPlayingSongChanged;
|
||||
|
||||
_playlists = new ObservableCollection<PlaylistItemViewModel>(_playlistManager.Playlists.Select(p => new PlaylistItemViewModel(p)));
|
||||
_selectedPlaylist = _playlists.FirstOrDefault(pv => pv.Playlist == _playlistManager.CurrentPlaylist);
|
||||
}
|
||||
@@ -70,4 +87,9 @@ public partial class PlaylistsViewModel : ViewModelBase
|
||||
Playlists.Remove(playlistView);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayingSongChanged(object? sender, EventArgs e)
|
||||
{
|
||||
ActivePlaylist = Playlists.FirstOrDefault(pv => pv.Playlist == _audioPlayer.Playlist);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user