playlist search - switch from lists to observabledictionary
This commit is contained in:
@@ -174,6 +174,9 @@
|
||||
<data name="FilterWindow.Title" xml:space="preserve">
|
||||
<value>Filter</value>
|
||||
</data>
|
||||
<data name="HiddenTextBlock.Text" xml:space="preserve">
|
||||
<value>Hidden: </value>
|
||||
</data>
|
||||
<data name="MediaOptionsHeader.Text" xml:space="preserve">
|
||||
<value>Media options</value>
|
||||
</data>
|
||||
|
||||
@@ -14,6 +14,7 @@ using VDownload.Models;
|
||||
using VDownload.Services.Data.Settings;
|
||||
using VDownload.Services.UI.StoragePicker;
|
||||
using VDownload.Sources.Twitch.Configuration.Models;
|
||||
using SimpleToolkit.MVVM;
|
||||
|
||||
namespace VDownload.Core.ViewModels.Home
|
||||
{
|
||||
@@ -34,7 +35,7 @@ namespace VDownload.Core.ViewModels.Home
|
||||
|
||||
protected Playlist _playlist;
|
||||
|
||||
protected Dictionary<VideoViewModel, bool> _allVideos;
|
||||
protected List<VideoViewModel> _removedVideos;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -46,11 +47,17 @@ namespace VDownload.Core.ViewModels.Home
|
||||
protected string _name;
|
||||
|
||||
[ObservableProperty]
|
||||
protected ObservableCollection<VideoViewModel> _videos;
|
||||
protected ObservableDictionary<VideoViewModel, bool> _videos;
|
||||
|
||||
[ObservableProperty]
|
||||
protected int _removedCount;
|
||||
|
||||
[ObservableProperty]
|
||||
protected int _hiddenCount;
|
||||
|
||||
[ObservableProperty]
|
||||
protected bool _isSomethingHidden;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -63,8 +70,9 @@ namespace VDownload.Core.ViewModels.Home
|
||||
_settingsService = settingsService;
|
||||
_storagePickerService = storagePickerService;
|
||||
|
||||
_allVideos = new Dictionary<VideoViewModel, bool>();
|
||||
_videos = new ObservableCollection<VideoViewModel>();
|
||||
_removedVideos = new List<VideoViewModel>();
|
||||
|
||||
_videos = new ObservableDictionary<VideoViewModel, bool>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -77,15 +85,15 @@ namespace VDownload.Core.ViewModels.Home
|
||||
{
|
||||
_playlist = playlist;
|
||||
|
||||
_allVideos.Clear();
|
||||
foreach (Video video in playlist)
|
||||
{
|
||||
_allVideos.Add(new VideoViewModel(video, _settingsService, _storagePickerService), false);
|
||||
}
|
||||
_removedVideos.Clear();
|
||||
|
||||
Name = _playlist.Name;
|
||||
Videos = new ObservableCollection<VideoViewModel>(_allVideos.Keys);
|
||||
RemovedCount = 0;
|
||||
Videos.Clear();
|
||||
foreach (Video video in playlist)
|
||||
{
|
||||
Videos.Add(new VideoViewModel(video, _settingsService, _storagePickerService), true);
|
||||
}
|
||||
UpdateCounters();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -100,7 +108,7 @@ namespace VDownload.Core.ViewModels.Home
|
||||
string? newDirectory = await _storagePickerService.OpenDirectory();
|
||||
if (newDirectory is not null)
|
||||
{
|
||||
foreach (VideoViewModel video in _allVideos.Keys)
|
||||
foreach (VideoViewModel video in Videos.Keys)
|
||||
{
|
||||
video.DirectoryPath = newDirectory;
|
||||
}
|
||||
@@ -110,22 +118,23 @@ namespace VDownload.Core.ViewModels.Home
|
||||
[RelayCommand]
|
||||
public void RemoveVideo(VideoViewModel video)
|
||||
{
|
||||
_allVideos[video] = true;
|
||||
Videos[video] = false;
|
||||
|
||||
Videos.Remove(video);
|
||||
_removedVideos.Add(video);
|
||||
|
||||
RemovedCount = _allVideos.Where(x => x.Value).Count();
|
||||
UpdateCounters();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void RestoreRemovedVideos()
|
||||
{
|
||||
foreach(VideoViewModel video in _allVideos.Where(x => x.Value == true).Select(x => x.Key))
|
||||
foreach(VideoViewModel video in _removedVideos)
|
||||
{
|
||||
_allVideos[video] = false;
|
||||
Videos.Add(video);
|
||||
Videos[video] = true;
|
||||
}
|
||||
RemovedCount = _allVideos.Where(x => x.Value).Count();
|
||||
_removedVideos.Clear();
|
||||
|
||||
UpdateCounters();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -142,7 +151,7 @@ namespace VDownload.Core.ViewModels.Home
|
||||
|
||||
protected void CreateTasks(bool download)
|
||||
{
|
||||
foreach (VideoViewModel video in Videos)
|
||||
foreach (VideoViewModel video in Videos.Keys)
|
||||
{
|
||||
DownloadTask task = _tasksManager.AddTask(video.Video, video.BuildDownloadOptions());
|
||||
if (download)
|
||||
@@ -153,6 +162,13 @@ namespace VDownload.Core.ViewModels.Home
|
||||
CloseRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected void UpdateCounters()
|
||||
{
|
||||
RemovedCount = _removedVideos.Count;
|
||||
HiddenCount = Videos.Values.Where(x => !x).Count();
|
||||
IsSomethingHidden = HiddenCount > 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240227000" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
|
||||
<PackageReference Include="SimpleToolkit.UI.Models" Version="1.6.1" />
|
||||
<PackageReference Include="SimpleToolkit.MVVM" Version="1.7.1" />
|
||||
<PackageReference Include="SimpleToolkit.UI.Models" Version="1.7.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -37,7 +37,12 @@
|
||||
TextWrapping="WrapWholeWords"/>
|
||||
<StackPanel Grid.Column="1"
|
||||
Orientation="Horizontal"
|
||||
Margin="-5">
|
||||
Margin="-5"
|
||||
Spacing="10">
|
||||
<TextBlock VerticalAlignment="Center"
|
||||
Visibility="{Binding IsSomethingHidden, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<Run x:Uid="/VDownload.Core.Strings/HomePlaylistViewResources/HiddenTextBlock"/><Run Text="{Binding HiddenCount}"/>
|
||||
</TextBlock>
|
||||
<AppBarToggleButton x:Name="FilterButton"
|
||||
Icon="Filter"
|
||||
Width="40"
|
||||
@@ -165,7 +170,8 @@
|
||||
<Expander HorizontalAlignment="Stretch"
|
||||
Margin="0,0,0,10"
|
||||
CornerRadius="10"
|
||||
HorizontalContentAlignment="Stretch">
|
||||
HorizontalContentAlignment="Stretch"
|
||||
Visibility="{Binding Value, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<Expander.Header>
|
||||
<Grid Padding="-16,0,-16,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
@@ -174,7 +180,7 @@
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image Grid.Column="0"
|
||||
Source="{Binding ThumbnailUrl, TargetNullValue={StaticResource ImageOtherThumbnail}}"
|
||||
Source="{Binding Key.ThumbnailUrl, TargetNullValue={StaticResource ImageOtherThumbnail}}"
|
||||
Height="100"/>
|
||||
<Grid Grid.Column="1"
|
||||
Margin="10"
|
||||
@@ -185,7 +191,7 @@
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Grid.Row="0"
|
||||
FontSize="16"
|
||||
Text="{Binding Title}"
|
||||
Text="{Binding Key.Title}"
|
||||
FontWeight="SemiBold"
|
||||
TextTrimming="CharacterEllipsis"/>
|
||||
<Grid Grid.Row="1"
|
||||
@@ -214,7 +220,7 @@
|
||||
Grid.Row="0"
|
||||
FontSize="{StaticResource FontSize}"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding Author}"/>
|
||||
Text="{Binding Key.Author}"/>
|
||||
<Image Grid.Column="0"
|
||||
Grid.Row="1"
|
||||
VerticalAlignment="Center"
|
||||
@@ -224,7 +230,7 @@
|
||||
Grid.Row="1"
|
||||
FontSize="{StaticResource FontSize}"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding PublishDate}"/>
|
||||
Text="{Binding Key.PublishDate}"/>
|
||||
<Image Grid.Column="2"
|
||||
Grid.Row="0"
|
||||
VerticalAlignment="Center"
|
||||
@@ -234,7 +240,7 @@
|
||||
Grid.Row="0"
|
||||
FontSize="{StaticResource FontSize}"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding Duration}"/>
|
||||
Text="{Binding Key.Duration}"/>
|
||||
<Image Grid.Column="2"
|
||||
Grid.Row="1"
|
||||
VerticalAlignment="Center"
|
||||
@@ -244,7 +250,7 @@
|
||||
Grid.Row="1"
|
||||
FontSize="{StaticResource FontSize}"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding Views}"/>
|
||||
Text="{Binding Key.Views}"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<AppBarButton Grid.Column="2"
|
||||
@@ -253,7 +259,7 @@
|
||||
Icon="Delete"
|
||||
VerticalAlignment="Center"
|
||||
Command="{Binding ElementName=Root, Path=DataContext.RemoveVideoCommand}"
|
||||
CommandParameter="{Binding}"/>
|
||||
CommandParameter="{Binding Key}"/>
|
||||
</Grid>
|
||||
</Expander.Header>
|
||||
<Expander.Content>
|
||||
@@ -267,8 +273,8 @@
|
||||
<BitmapIcon ShowAsMonochrome="False"
|
||||
UriSource="{ThemeResource ImageHomePlaylistViewMedia}"/>
|
||||
</ctc:SettingsCard.HeaderIcon>
|
||||
<ComboBox ItemsSource="{Binding Streams}"
|
||||
SelectedItem="{Binding SelectedStream, Mode=TwoWay}"/>
|
||||
<ComboBox ItemsSource="{Binding Key.Streams}"
|
||||
SelectedItem="{Binding Key.SelectedStream, Mode=TwoWay}"/>
|
||||
</ctc:SettingsCard>
|
||||
<ctc:SettingsCard x:Uid="/VDownload.Core.Strings/HomePlaylistViewResources/MediaTypeSettingsCard">
|
||||
<ctc:SettingsCard.HeaderIcon>
|
||||
@@ -276,7 +282,7 @@
|
||||
UriSource="{ThemeResource ImageHomePlaylistViewMedia}"/>
|
||||
</ctc:SettingsCard.HeaderIcon>
|
||||
<ComboBox ItemsSource="{ct:EnumValues Type=m:MediaType}"
|
||||
SelectedItem="{Binding MediaType, Mode=TwoWay}">
|
||||
SelectedItem="{Binding Key.MediaType, Mode=TwoWay}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ctuc:SwitchPresenter Value="{Binding Converter={StaticResource ObjectToStringConverter}}">
|
||||
@@ -301,13 +307,13 @@
|
||||
</ctc:SettingsExpander.HeaderIcon>
|
||||
<ctc:SettingsExpander.Items>
|
||||
<ctc:SettingsCard x:Uid="/VDownload.Core.Strings/HomePlaylistViewResources/TrimStartSettingsCard">
|
||||
<c:TimeSpanControl Value="{Binding TrimStart, Mode=TwoWay}"
|
||||
Maximum="{Binding TrimEnd, Mode=OneWay}"/>
|
||||
<c:TimeSpanControl Value="{Binding Key.TrimStart, Mode=TwoWay}"
|
||||
Maximum="{Binding Key.TrimEnd, Mode=OneWay}"/>
|
||||
</ctc:SettingsCard>
|
||||
<ctc:SettingsCard x:Uid="/VDownload.Core.Strings/HomePlaylistViewResources/TrimEndSettingsCard">
|
||||
<c:TimeSpanControl Minimum="{Binding TrimStart, Mode=OneWay}"
|
||||
Value="{Binding TrimEnd, Mode=TwoWay}"
|
||||
Maximum="{Binding Duration, Mode=OneWay}"/>
|
||||
<c:TimeSpanControl Minimum="{Binding Key.TrimStart, Mode=OneWay}"
|
||||
Value="{Binding Key.TrimEnd, Mode=TwoWay}"
|
||||
Maximum="{Binding Key.Duration, Mode=OneWay}"/>
|
||||
</ctc:SettingsCard>
|
||||
</ctc:SettingsExpander.Items>
|
||||
</ctc:SettingsExpander>
|
||||
@@ -317,20 +323,20 @@
|
||||
FontWeight="Bold"
|
||||
FontSize="15"/>
|
||||
<ctc:SettingsCard x:Uid="/VDownload.Core.Strings/HomePlaylistViewResources/DirectorySettingsCard"
|
||||
Description="{Binding DirectoryPath}">
|
||||
Description="{Binding Key.DirectoryPath}">
|
||||
<ctc:SettingsCard.HeaderIcon>
|
||||
<BitmapIcon ShowAsMonochrome="False"
|
||||
UriSource="{ThemeResource ImageHomePlaylistViewDirectory}"/>
|
||||
</ctc:SettingsCard.HeaderIcon>
|
||||
<Button x:Uid="/VDownload.Core.Strings/HomePlaylistViewResources/DirectorySettingsCardButton"
|
||||
Command="{Binding BrowseCommand}"/>
|
||||
Command="{Binding Key.BrowseCommand}"/>
|
||||
</ctc:SettingsCard>
|
||||
<ctc:SettingsCard x:Uid="/VDownload.Core.Strings/HomePlaylistViewResources/FilenameSettingsCard">
|
||||
<ctc:SettingsCard.HeaderIcon>
|
||||
<BitmapIcon ShowAsMonochrome="False"
|
||||
UriSource="{ThemeResource ImageHomePlaylistViewFilename}"/>
|
||||
</ctc:SettingsCard.HeaderIcon>
|
||||
<TextBox Text="{Binding Filename, Mode=TwoWay}"/>
|
||||
<TextBox Text="{Binding Key.Filename, Mode=TwoWay}"/>
|
||||
</ctc:SettingsCard>
|
||||
<ctc:SettingsCard x:Uid="/VDownload.Core.Strings/HomePlaylistViewResources/FileTypeSettingsCard">
|
||||
<ctc:SettingsCard.HeaderIcon>
|
||||
@@ -338,13 +344,13 @@
|
||||
UriSource="{ThemeResource ImageHomePlaylistViewExtension}"/>
|
||||
</ctc:SettingsCard.HeaderIcon>
|
||||
<i:Interaction.Behaviors>
|
||||
<ic:DataTriggerBehavior Binding="{Binding MediaType, Converter={StaticResource ObjectToStringConverter}}"
|
||||
<ic:DataTriggerBehavior Binding="{Binding Key.MediaType, Converter={StaticResource ObjectToStringConverter}}"
|
||||
ComparisonCondition="Equal"
|
||||
Value="OnlyAudio">
|
||||
<ic:ChangePropertyAction PropertyName="Content">
|
||||
<ic:ChangePropertyAction.Value>
|
||||
<ComboBox ItemsSource="{ct:EnumValues Type=m:AudioExtension}"
|
||||
SelectedItem="{Binding AudioExtension, Mode=TwoWay}">
|
||||
SelectedItem="{Binding Key.AudioExtension, Mode=TwoWay}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding}"/>
|
||||
@@ -354,13 +360,13 @@
|
||||
</ic:ChangePropertyAction.Value>
|
||||
</ic:ChangePropertyAction>
|
||||
</ic:DataTriggerBehavior>
|
||||
<ic:DataTriggerBehavior Binding="{Binding MediaType, Converter={StaticResource ObjectToStringConverter}}"
|
||||
<ic:DataTriggerBehavior Binding="{Binding Key.MediaType, Converter={StaticResource ObjectToStringConverter}}"
|
||||
ComparisonCondition="NotEqual"
|
||||
Value="OnlyAudio">
|
||||
<ic:ChangePropertyAction PropertyName="Content">
|
||||
<ic:ChangePropertyAction.Value>
|
||||
<ComboBox ItemsSource="{ct:EnumValues Type=m:VideoExtension}"
|
||||
SelectedItem="{Binding VideoExtension, Mode=TwoWay}">
|
||||
SelectedItem="{Binding Key.VideoExtension, Mode=TwoWay}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding}"/>
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240227000" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
|
||||
<PackageReference Include="SimpleToolkit.UI.WinUI.Behaviors" Version="1.6.1" />
|
||||
<PackageReference Include="SimpleToolkit.UI.WinUI.Controls" Version="1.6.1" />
|
||||
<PackageReference Include="SimpleToolkit.UI.WinUI.Behaviors" Version="1.7.1" />
|
||||
<PackageReference Include="SimpleToolkit.UI.WinUI.Controls" Version="1.7.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240227000" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
|
||||
<PackageReference Include="SimpleToolkit.UI.WinUI.Converters" Version="1.6.1" />
|
||||
<PackageReference Include="SimpleToolkit.UI.WinUI.Converters" Version="1.7.1" />
|
||||
<Manifest Include="$(ApplicationManifest)" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user