Added in more locking/unlocking logic.
This commit is contained in:
@@ -16,6 +16,9 @@ public class Playlist
|
|||||||
|
|
||||||
public void Lock()
|
public void Lock()
|
||||||
{
|
{
|
||||||
|
if (IsLocked)
|
||||||
|
return;
|
||||||
|
|
||||||
IsLocked = true;
|
IsLocked = true;
|
||||||
|
|
||||||
PlaylistUpdatedEventArgs eventArgs = new()
|
PlaylistUpdatedEventArgs eventArgs = new()
|
||||||
@@ -31,6 +34,9 @@ public class Playlist
|
|||||||
|
|
||||||
public void Unlock()
|
public void Unlock()
|
||||||
{
|
{
|
||||||
|
if (IsLocked == false)
|
||||||
|
return;
|
||||||
|
|
||||||
IsLocked = false;
|
IsLocked = false;
|
||||||
|
|
||||||
PlaylistUpdatedEventArgs eventArgs = new()
|
PlaylistUpdatedEventArgs eventArgs = new()
|
||||||
|
|||||||
38
Harmonia.WinUI/Converters/BooleanToVisibilityConverter.cs
Normal file
38
Harmonia.WinUI/Converters/BooleanToVisibilityConverter.cs
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 PlaySongCommand { get; }
|
||||||
public IAsyncRelayCommand NewPlaylistCommand { get; }
|
public IAsyncRelayCommand NewPlaylistCommand { get; }
|
||||||
public IAsyncRelayCommand AddFilesCommand { get; }
|
public IAsyncRelayCommand AddFilesCommand { get; }
|
||||||
@@ -151,7 +158,8 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
|||||||
public IRelayCommand RandomizeSelectedCommand { get; }
|
public IRelayCommand RandomizeSelectedCommand { get; }
|
||||||
public IRelayCommand ReverseAllCommand { get; }
|
public IRelayCommand ReverseAllCommand { get; }
|
||||||
public IRelayCommand ReverseSelectedCommand { get; }
|
public IRelayCommand ReverseSelectedCommand { get; }
|
||||||
public IRelayCommand ToggleLockCommand { get; }
|
public IRelayCommand LockPlaylistCommand { get; }
|
||||||
|
public IRelayCommand UnlockPlaylistCommand { get; }
|
||||||
|
|
||||||
public bool IsUserUpdating { get; set; }
|
public bool IsUserUpdating { get; set; }
|
||||||
private bool _isUserInitiatingSongChange;
|
private bool _isUserInitiatingSongChange;
|
||||||
@@ -204,7 +212,8 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
|||||||
RandomizeSelectedCommand = new RelayCommand(RandomizeSelectedSongs, AreMultipleSongsSelected);
|
RandomizeSelectedCommand = new RelayCommand(RandomizeSelectedSongs, AreMultipleSongsSelected);
|
||||||
ReverseAllCommand = new RelayCommand(ReverseAllSongs);
|
ReverseAllCommand = new RelayCommand(ReverseAllSongs);
|
||||||
ReverseSelectedCommand = new RelayCommand(ReverseSelectedSongs, AreMultipleSongsSelected);
|
ReverseSelectedCommand = new RelayCommand(ReverseSelectedSongs, AreMultipleSongsSelected);
|
||||||
ToggleLockCommand = new RelayCommand(ToggleLock);
|
LockPlaylistCommand = new RelayCommand(LockPlaylist);
|
||||||
|
UnlockPlaylistCommand = new RelayCommand(UnlockPlaylist);
|
||||||
|
|
||||||
FilteredPlaylistSongs.CollectionChanged += OnFilteredPlaylistSongsCollectionChanged;
|
FilteredPlaylistSongs.CollectionChanged += OnFilteredPlaylistSongsCollectionChanged;
|
||||||
|
|
||||||
@@ -267,6 +276,8 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
|||||||
Playlist = _playlistManager.CurrentPlaylist;
|
Playlist = _playlistManager.CurrentPlaylist;
|
||||||
Playlist?.PlaylistUpdated += OnPlaylistUpdated;
|
Playlist?.PlaylistUpdated += OnPlaylistUpdated;
|
||||||
|
|
||||||
|
IsPlaylistLocked = Playlist?.IsLocked ?? false;
|
||||||
|
|
||||||
UpdateFilteredSongs();
|
UpdateFilteredSongs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,6 +297,10 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
|||||||
case PlaylistUpdateAction.Reset:
|
case PlaylistUpdateAction.Reset:
|
||||||
_dispatcherQueue.TryEnqueue(() => ApplyReorderedSongs(e.Songs));
|
_dispatcherQueue.TryEnqueue(() => ApplyReorderedSongs(e.Songs));
|
||||||
break;
|
break;
|
||||||
|
case PlaylistUpdateAction.Lock:
|
||||||
|
case PlaylistUpdateAction.Unlock:
|
||||||
|
IsPlaylistLocked = Playlist?.IsLocked ?? false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -737,19 +752,14 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
|||||||
RestoreSelectedSongs(selectedPlaylistSongIds);
|
RestoreSelectedSongs(selectedPlaylistSongIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ToggleLock()
|
private void LockPlaylist()
|
||||||
{
|
{
|
||||||
if (Playlist == null)
|
Playlist?.Lock();
|
||||||
return;
|
}
|
||||||
|
|
||||||
if (Playlist.IsLocked)
|
private void UnlockPlaylist()
|
||||||
{
|
{
|
||||||
Playlist.Unlock();
|
Playlist?.Unlock();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Playlist.Lock();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:local="using:Harmonia.WinUI.Views"
|
xmlns:local="using:Harmonia.WinUI.Views"
|
||||||
xmlns:vm="using:Harmonia.WinUI.ViewModels"
|
xmlns:vm="using:Harmonia.WinUI.ViewModels"
|
||||||
|
xmlns:converter="using:Harmonia.WinUI.Converters"
|
||||||
xmlns:playlists="using:Harmonia.Core.Playlists"
|
xmlns:playlists="using:Harmonia.Core.Playlists"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
@@ -11,6 +12,9 @@
|
|||||||
d:DataContext="{d:DesignInstance Type=vm:PlaylistDetailViewModel, IsDesignTimeCreatable=True}"
|
d:DataContext="{d:DesignInstance Type=vm:PlaylistDetailViewModel, IsDesignTimeCreatable=True}"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<UserControl.Resources>
|
<UserControl.Resources>
|
||||||
|
<converter:BooleanToVisibilityConverter x:Key="BoolToVis" />
|
||||||
|
<converter:BooleanToVisibilityConverter x:Key="InverseBoolToVis" TrueValue="Collapsed" FalseValue="Visible"/>
|
||||||
|
|
||||||
<!--<SolidColorBrush x:Key="PlaylistBackground" Color="#393a45"/>-->
|
<!--<SolidColorBrush x:Key="PlaylistBackground" Color="#393a45"/>-->
|
||||||
<SolidColorBrush x:Key="PlaylistBackground" Color="#292a35"/>
|
<SolidColorBrush x:Key="PlaylistBackground" Color="#292a35"/>
|
||||||
<SolidColorBrush x:Key="PlaylistItemHighlightColor" Color="#494a55"/>
|
<SolidColorBrush x:Key="PlaylistItemHighlightColor" Color="#494a55"/>
|
||||||
@@ -168,8 +172,11 @@
|
|||||||
<MenuFlyoutItem Text="Remove Missing" Command="{Binding RemoveMissingSongsCommand}">
|
<MenuFlyoutItem Text="Remove Missing" Command="{Binding RemoveMissingSongsCommand}">
|
||||||
</MenuFlyoutItem>
|
</MenuFlyoutItem>
|
||||||
|
|
||||||
<ToggleMenuFlyoutItem Text="Lock Playlist" IsChecked="{Binding Playlist.IsLocked}">
|
<MenuFlyoutItem Text="Lock Playlist" Command="{Binding LockPlaylistCommand}" Visibility="{Binding IsPlaylistLocked, Converter={StaticResource InverseBoolToVis}}">
|
||||||
</ToggleMenuFlyoutItem>
|
</MenuFlyoutItem>
|
||||||
|
|
||||||
|
<MenuFlyoutItem Text="Unlock Playlist" Command="{Binding UnlockPlaylistCommand}" Visibility="{Binding IsPlaylistLocked, Converter={StaticResource BoolToVis}}">
|
||||||
|
</MenuFlyoutItem>
|
||||||
|
|
||||||
<MenuFlyoutSeparator></MenuFlyoutSeparator>
|
<MenuFlyoutSeparator></MenuFlyoutSeparator>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user