Added playlists view. Added messaging service. Added logic for adding and deleting playlists.
This commit is contained in:
@@ -7,6 +7,7 @@ using Harmonia.Core.Player;
|
||||
using Harmonia.Core.Playlists;
|
||||
using Harmonia.Core.Scanner;
|
||||
using Harmonia.WinUI.Caching;
|
||||
using Harmonia.WinUI.Messaging;
|
||||
using Harmonia.WinUI.Storage;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using System;
|
||||
@@ -36,6 +37,7 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
private readonly IAudioFileScanner _audioFileScanner;
|
||||
private readonly IAudioEngine _audioEngine;
|
||||
private readonly IStorageProvider _storageProvider;
|
||||
private readonly IMessageService _messageService;
|
||||
private readonly DispatcherQueue _dispatcherQueue;
|
||||
private readonly ConcurrentDictionary<int, CancellationTokenSource> _imageCancellationTokens = [];
|
||||
|
||||
@@ -100,6 +102,7 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
}
|
||||
|
||||
public ICommand PlaySongCommand => new AsyncRelayCommand(PlaySongAsync, AreSongsSelected);
|
||||
public ICommand NewPlaylistCommand => new AsyncRelayCommand(NewPlaylistAsync);
|
||||
public ICommand AddFilesCommand => new AsyncRelayCommand(AddFilesAsync);
|
||||
public ICommand AddFolderCommand => new AsyncRelayCommand(AddFolderAsync);
|
||||
public ICommand RemoveSongsCommand => new RelayCommand(RemoveSongs, AreSongsSelected);
|
||||
@@ -110,6 +113,7 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
public ICommand RefreshTagsCommand => new RelayCommand(RefreshTags);
|
||||
public ICommand RemoveMissingSongsCommand => new RelayCommand(RemoveMissingSongs);
|
||||
public ICommand RemoveDuplicateSongsCommand => new RelayCommand(RemoveDuplicateSongs);
|
||||
public ICommand DeletePlaylistCommand => new AsyncRelayCommand(DeletePlaylistAsync);
|
||||
|
||||
public bool IsUserUpdating { get; set; }
|
||||
private bool _isUserInitiatingSongChange;
|
||||
@@ -125,10 +129,11 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
IAudioFileScanner audioFileScanner,
|
||||
IAudioEngine audioEngine,
|
||||
IStorageProvider storageProvider,
|
||||
IPlaylistManager playlistManager)
|
||||
IPlaylistManager playlistManager,
|
||||
IMessageService messageService)
|
||||
{
|
||||
_playlistManager = playlistManager;
|
||||
//_playlistManager.CurrentPlaylistChanged += OnPlaylistChanged;
|
||||
_playlistManager.CurrentPlaylistChanged += OnPlaylistChanged;
|
||||
|
||||
_audioPlayer = audioPlayer;
|
||||
_audioPlayer.PlaylistChanged += OnPlaylistChanged;
|
||||
@@ -139,6 +144,7 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
_audioFileScanner = audioFileScanner;
|
||||
_audioEngine = audioEngine;
|
||||
_storageProvider = storageProvider;
|
||||
_messageService = messageService;
|
||||
_dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
||||
|
||||
FilteredPlaylistSongs.CollectionChanged += OnFilteredPlaylistSongsCollectionChanged;
|
||||
@@ -185,7 +191,8 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
private void OnPlaylistChanged(object? sender, EventArgs e)
|
||||
{
|
||||
Playlist?.PlaylistUpdated -= OnPlaylistUpdated;
|
||||
Playlist = _audioPlayer.Playlist;
|
||||
//Playlist = _audioPlayer.Playlist;
|
||||
Playlist = _playlistManager.CurrentPlaylist;
|
||||
Playlist?.PlaylistUpdated += OnPlaylistUpdated;
|
||||
|
||||
UpdateFilteredSongs();
|
||||
@@ -369,6 +376,12 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
return SelectedPlaylistSongs.Count > 0;
|
||||
}
|
||||
|
||||
private async Task NewPlaylistAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
Playlist playlist = await _playlistManager.AddPlaylistAsync();
|
||||
_playlistManager.CurrentPlaylist = playlist;
|
||||
}
|
||||
|
||||
private async Task AddFilesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (Playlist == null)
|
||||
@@ -535,5 +548,30 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
Playlist?.RemoveDuplicateSongs();
|
||||
}
|
||||
|
||||
private async Task DeletePlaylistAsync()
|
||||
{
|
||||
if (Playlist == null)
|
||||
return;
|
||||
|
||||
bool confirmed = await _messageService.ConfirmAsync($"Delete Playlist - {Playlist.Name}", "Are you sure you want to delete this playlist?");
|
||||
|
||||
if (!confirmed)
|
||||
return;
|
||||
|
||||
_playlistManager.RemovePlaylist(Playlist);
|
||||
|
||||
if (_playlistManager.CurrentPlaylist == Playlist)
|
||||
{
|
||||
if (_playlistManager.Playlists.Count > 0)
|
||||
{
|
||||
_playlistManager.CurrentPlaylist = _playlistManager.Playlists.ElementAt(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
_playlistManager.CurrentPlaylist = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user