From de16ac6240050593fc9229f86073dfa299e79526 Mon Sep 17 00:00:00 2001 From: Brian Bicknell Date: Mon, 3 Aug 2026 22:57:40 -0400 Subject: [PATCH] Added in more locking/unlocking logic. --- Harmonia.Core/Playlists/Playlist.cs | 6 +++ .../BooleanToVisibilityConverter.cs | 38 +++++++++++++++++++ .../ViewModels/PlaylistDetailViewModel.cs | 36 +++++++++++------- Harmonia.WinUI/Views/PlaylistDetailView.xaml | 13 +++++-- 4 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 Harmonia.WinUI/Converters/BooleanToVisibilityConverter.cs diff --git a/Harmonia.Core/Playlists/Playlist.cs b/Harmonia.Core/Playlists/Playlist.cs index c7f290a..2f6cc8e 100644 --- a/Harmonia.Core/Playlists/Playlist.cs +++ b/Harmonia.Core/Playlists/Playlist.cs @@ -16,6 +16,9 @@ public class Playlist public void Lock() { + if (IsLocked) + return; + IsLocked = true; PlaylistUpdatedEventArgs eventArgs = new() @@ -31,6 +34,9 @@ public class Playlist public void Unlock() { + if (IsLocked == false) + return; + IsLocked = false; PlaylistUpdatedEventArgs eventArgs = new() diff --git a/Harmonia.WinUI/Converters/BooleanToVisibilityConverter.cs b/Harmonia.WinUI/Converters/BooleanToVisibilityConverter.cs new file mode 100644 index 0000000..fdbe132 --- /dev/null +++ b/Harmonia.WinUI/Converters/BooleanToVisibilityConverter.cs @@ -0,0 +1,38 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Data; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Harmonia.WinUI.Converters; + +public class BooleanToVisibilityConverter : IValueConverter +{ + public Visibility TrueValue { get; set; } + public Visibility FalseValue { get; set; } + + public BooleanToVisibilityConverter() + { + TrueValue = Visibility.Visible; + FalseValue = Visibility.Collapsed; + } + + public object? Convert(object value, Type targetType, object parameter, string language) + { + if (!(value is bool)) + return null; + + return (bool)value ? TrueValue : FalseValue; + } + + public object? ConvertBack(object value, Type targetType, object parameter, string language) + { + if (Equals(value, TrueValue)) + return true; + + if (Equals(value, FalseValue)) + return false; + + return null; + } +} \ No newline at end of file diff --git a/Harmonia.WinUI/ViewModels/PlaylistDetailViewModel.cs b/Harmonia.WinUI/ViewModels/PlaylistDetailViewModel.cs index 55b1a2c..6c6cdaa 100644 --- a/Harmonia.WinUI/ViewModels/PlaylistDetailViewModel.cs +++ b/Harmonia.WinUI/ViewModels/PlaylistDetailViewModel.cs @@ -132,6 +132,13 @@ public partial class PlaylistDetailViewModel : ViewModelBase } ]; + private bool _isPlaylistLocked; + public bool IsPlaylistLocked + { + get => _isPlaylistLocked; + private set => SetProperty(ref _isPlaylistLocked, value); + } + public IAsyncRelayCommand PlaySongCommand { get; } public IAsyncRelayCommand NewPlaylistCommand { get; } public IAsyncRelayCommand AddFilesCommand { get; } @@ -151,7 +158,8 @@ public partial class PlaylistDetailViewModel : ViewModelBase public IRelayCommand RandomizeSelectedCommand { get; } public IRelayCommand ReverseAllCommand { get; } public IRelayCommand ReverseSelectedCommand { get; } - public IRelayCommand ToggleLockCommand { get; } + public IRelayCommand LockPlaylistCommand { get; } + public IRelayCommand UnlockPlaylistCommand { get; } public bool IsUserUpdating { get; set; } private bool _isUserInitiatingSongChange; @@ -204,7 +212,8 @@ public partial class PlaylistDetailViewModel : ViewModelBase RandomizeSelectedCommand = new RelayCommand(RandomizeSelectedSongs, AreMultipleSongsSelected); ReverseAllCommand = new RelayCommand(ReverseAllSongs); ReverseSelectedCommand = new RelayCommand(ReverseSelectedSongs, AreMultipleSongsSelected); - ToggleLockCommand = new RelayCommand(ToggleLock); + LockPlaylistCommand = new RelayCommand(LockPlaylist); + UnlockPlaylistCommand = new RelayCommand(UnlockPlaylist); FilteredPlaylistSongs.CollectionChanged += OnFilteredPlaylistSongsCollectionChanged; @@ -267,6 +276,8 @@ public partial class PlaylistDetailViewModel : ViewModelBase Playlist = _playlistManager.CurrentPlaylist; Playlist?.PlaylistUpdated += OnPlaylistUpdated; + IsPlaylistLocked = Playlist?.IsLocked ?? false; + UpdateFilteredSongs(); } @@ -286,6 +297,10 @@ public partial class PlaylistDetailViewModel : ViewModelBase case PlaylistUpdateAction.Reset: _dispatcherQueue.TryEnqueue(() => ApplyReorderedSongs(e.Songs)); break; + case PlaylistUpdateAction.Lock: + case PlaylistUpdateAction.Unlock: + IsPlaylistLocked = Playlist?.IsLocked ?? false; + break; } } @@ -737,19 +752,14 @@ public partial class PlaylistDetailViewModel : ViewModelBase RestoreSelectedSongs(selectedPlaylistSongIds); } - private void ToggleLock() + private void LockPlaylist() { - if (Playlist == null) - return; + Playlist?.Lock(); + } - if (Playlist.IsLocked) - { - Playlist.Unlock(); - } - else - { - Playlist.Lock(); - } + private void UnlockPlaylist() + { + Playlist?.Unlock(); } #endregion diff --git a/Harmonia.WinUI/Views/PlaylistDetailView.xaml b/Harmonia.WinUI/Views/PlaylistDetailView.xaml index c035570..e9259ea 100644 --- a/Harmonia.WinUI/Views/PlaylistDetailView.xaml +++ b/Harmonia.WinUI/Views/PlaylistDetailView.xaml @@ -4,6 +4,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Harmonia.WinUI.Views" xmlns:vm="using:Harmonia.WinUI.ViewModels" + xmlns:converter="using:Harmonia.WinUI.Converters" xmlns:playlists="using:Harmonia.Core.Playlists" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" @@ -11,6 +12,9 @@ d:DataContext="{d:DesignInstance Type=vm:PlaylistDetailViewModel, IsDesignTimeCreatable=True}" mc:Ignorable="d"> + + + @@ -168,9 +172,12 @@ - - - + + + + + +