Allow to add/remove multiple playlists from settings window

This commit is contained in:
2024-10-23 14:37:54 +03:00
parent 6d09c2699c
commit 7cbda8a6b9
7 changed files with 127 additions and 30 deletions
+36 -5
View File
@@ -80,7 +80,38 @@ c-0.781-0.781-0.788-2.047-0.007-2.828L51.438,14.43c1.754-1.755,1.753-4.61-0.001-
</Setter> </Setter>
</Style> </Style>
<Style x:Key="ButtonAdd" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="Green" Height="50" Width="50" CornerRadius="300">
<Path Fill="#FFF4F4F5" HorizontalAlignment="Center" Height="35" Stroke="Black" Stretch="Fill" VerticalAlignment="Center" Width="30">
<Path.Data>
<PathGeometry Figures="M23.531502,6.7801739 L23.553471,20.766701 7.225951,21.044638 7.1408542,25.087499 23.177883,25.087499 23.051064,42.665812 28.15887,42.751559 28.194953,25.087499 43.923114,25.087499 43.984694,20.800105 28.242605,20.852246 28.284472,6.737454 z"/>
</Path.Data>
</Path>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ButtonRemove" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="Red" Height="50" Width="50" CornerRadius="300">
<Path Fill="#FFF4F4F5" HorizontalAlignment="Center" Height="35" Stroke="Black" Stretch="Fill" VerticalAlignment="Center" Width="30">
<Path.Data>
<PathGeometry Figures="M7.225951,21.044638 L7.1408542,25.087499 43.923114,25.087499 43.984694,20.800105 z"/>
</Path.Data>
</Path>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ButtonUp" TargetType="{x:Type Button}"> <Style x:Key="ButtonUp" TargetType="{x:Type Button}">
<Setter Property="Template"> <Setter Property="Template">
@@ -248,17 +279,17 @@ c-0.781-0.781-0.788-2.047-0.007-2.828L51.438,14.43c1.754-1.755,1.753-4.61-0.001-
Content="{TemplateBinding Property=ContentControl.Content}" Content="{TemplateBinding Property=ContentControl.Content}"
/> />
</Border> </Border>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<LinearGradientBrush x:Key="YellowGradient" > <LinearGradientBrush x:Key="YellowGradient" >
<GradientStop Offset="0" Color="LightGray"/> <GradientStop Offset="0" Color="LightGray"/>
<GradientStop Offset="1" Color="Gray"/> <GradientStop Offset="1" Color="Gray"/>
</LinearGradientBrush> </LinearGradientBrush>
<Style x:Key="{x:Type CheckBox}" TargetType="CheckBox"> <Style x:Key="{x:Type CheckBox}" TargetType="CheckBox">
<Setter Property="SnapsToDevicePixels" Value="true"/> <Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="Background" Value="{StaticResource YellowGradient}" /> <Setter Property="Background" Value="{StaticResource YellowGradient}" />
@@ -297,7 +328,7 @@ c-0.781-0.781-0.788-2.047-0.007-2.828L51.438,14.43c1.754-1.755,1.753-4.61-0.001-
</Border> </Border>
</Border> </Border>
<Path x:Name="CheckMark" SnapsToDevicePixels="False" Data="F1M1,14.489C1,14.489 4.963,10.525 4.963,10.525 4.963,10.525 11.328,16.89 11.328,16.89 11.328,16.89 27.034,1.183 27.034,1.183 27.034,1.183 31,5.146 31,5.146 31,5.146 11.328,24.817 11.328,24.817 11.328,24.817 1,14.489 1,14.489z" Fill="#FFFFFFFF" Height="26" Canvas.Left="0" Canvas.Top="0" Width="32"/> <Path x:Name="CheckMark" SnapsToDevicePixels="False" Data="F1M1,14.489C1,14.489 4.963,10.525 4.963,10.525 4.963,10.525 11.328,16.89 11.328,16.89 11.328,16.89 27.034,1.183 27.034,1.183 27.034,1.183 31,5.146 31,5.146 31,5.146 11.328,24.817 11.328,24.817 11.328,24.817 1,14.489 1,14.489z" Fill="#FFFFFFFF" Height="26" Canvas.Left="0" Canvas.Top="0" Width="32"/>
</Grid> </Grid>
</BulletDecorator.Bullet> </BulletDecorator.Bullet>
<ContentPresenter Margin="4,0,0,0" TextBlock.Foreground="{TemplateBinding Foreground}" <ContentPresenter Margin="4,0,0,0" TextBlock.Foreground="{TemplateBinding Foreground}"
+6
View File
@@ -17,5 +17,11 @@ namespace TV_Player
viewModel.OnKeyDownCommand.Execute(e); viewModel.OnKeyDownCommand.Execute(e);
} }
} }
protected override void OnManipulationBoundaryFeedback(ManipulationBoundaryFeedbackEventArgs e)
{
e.Handled = true;
}
} }
} }
+4 -4
View File
@@ -35,13 +35,13 @@ namespace TV_Player
} }
} }
private void ListView_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) private void ListView_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{ {
_isDragging = true; _isDragging = true;
_mousePosition = e.GetPosition(null); _mousePosition = e.GetPosition(null);
} }
private void ListView_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) private void ListView_MouseMove(object sender, MouseEventArgs e)
{ {
if (e.LeftButton == MouseButtonState.Pressed) if (e.LeftButton == MouseButtonState.Pressed)
{ {
@@ -66,8 +66,8 @@ namespace TV_Player
} }
} }
} }
} }
private void ListView_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) private void ListView_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{ {
_isDragging = false; _isDragging = false;
+40 -16
View File
@@ -3,21 +3,45 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:tv_player="clr-namespace:TV_Player" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:tv_player="clr-namespace:TV_Player"
mc:Ignorable="d" mc:Ignorable="d">
d:DesignHeight="450" d:DesignWidth="800"> <Viewbox>
<StackPanel x:Name="groupsGrid" VerticalAlignment="Center"> <StackPanel x:Name="groupsGrid" VerticalAlignment="Center">
<!--<StackPanel x:Name="AddPlayList" Visibility="Collapsed">--> <Button HorizontalAlignment="Center" Height="70" Width="70" Style="{DynamicResource ButtonAdd}" Click="OpenAddPlayList_Click" />
<Label Margin="10" Foreground="White" FontSize="25" FontWeight="Bold" FontFamily="Arial">Адрес плейлиста</Label> <ListView Height="250" ItemsSource="{Binding Playlists}" Background="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<TextBox Margin="10" Style="{StaticResource TextBox}" HorizontalAlignment="Stretch" Text="{Binding PlaylistURL}"></TextBox> <ListView.ItemTemplate>
<Label Margin="10" Foreground="White" FontSize="25" FontWeight="Bold" FontFamily="Arial">Название</Label> <DataTemplate>
<TextBox Margin="10" Style="{StaticResource TextBox}" HorizontalAlignment="Stretch" Text="{Binding PlaylistName}"></TextBox> <Grid HorizontalAlignment="Stretch" Height="80">
<Button Grid.Column="1" Height="70" Width="70" Margin="10,0,50,0" Style="{DynamicResource ButtonConfirm}" Command="{Binding BackCommand}" /> <Grid.ColumnDefinitions>
<!--</StackPanel>--> <ColumnDefinition Width="200"/>
<CheckBox Margin="10" Foreground="White" FontSize="25" IsChecked="{Binding StartFullScreen}">Откывать во весь экран</CheckBox> <ColumnDefinition Width="*"/>
<CheckBox Margin="10" Foreground="White" FontSize="25" IsChecked="{Binding StartLastScreen}">Запоминать последний выбор</CheckBox> <ColumnDefinition Width="100"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center"> </Grid.ColumnDefinitions>
<Button Grid.Column="1" Height="70" Width="70" Margin="10,0,50,0" Style="{DynamicResource ButtonBack}" Command="{Binding BackCommand}" /> <TextBlock Foreground="White" VerticalAlignment="Center" FontSize="25" FontWeight="Bold" Text="{Binding Key}" />
<Button HorizontalAlignment="Center" Height="70" Width="70" Style="{DynamicResource ButtonConfirm}" Command="{Binding SaveCommand}" /> <TextBlock Grid.Column="1" Foreground="White" VerticalAlignment="Center" FontSize="25" FontWeight="Bold" Text="{Binding Value}" />
<Button Grid.Column="2" Height="70" Width="70" Style="{DynamicResource ButtonRemove}" CommandParameter="{Binding}"
Command="{Binding DataContext.PlaylistDeleteCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
<StackPanel x:Name="AddPlayList" Visibility="Collapsed">
<Label Margin="10" Foreground="White" FontSize="25" FontWeight="Bold" FontFamily="Arial">Адрес плейлиста</Label>
<TextBox Margin="10" Style="{StaticResource TextBox}" HorizontalAlignment="Stretch" Text="{Binding PlaylistURL}"></TextBox>
<Label Margin="10" Foreground="White" FontSize="25" FontWeight="Bold" FontFamily="Arial">Название</Label>
<TextBox Margin="10" Style="{StaticResource TextBox}" HorizontalAlignment="Stretch" Text="{Binding PlaylistName}"></TextBox>
<Button Grid.Column="1" Height="70" Width="70" Margin="10,0,50,0" Style="{DynamicResource ButtonConfirm}" Click="AddPlayList_Click" Command="{Binding AddPlaylistCommand}" />
</StackPanel>
<CheckBox Margin="10" Foreground="White" FontSize="25" IsChecked="{Binding StartFullScreen}">Откывать во весь экран</CheckBox>
<CheckBox Margin="10" Foreground="White" FontSize="25" IsChecked="{Binding StartLastScreen}">Запоминать последний выбор</CheckBox>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Grid.Column="1" Height="70" Width="70" Margin="10,0,50,0" Style="{DynamicResource ButtonBack}" Command="{Binding BackCommand}" />
<Button HorizontalAlignment="Center" Height="70" Width="70" Style="{DynamicResource ButtonConfirm}" Command="{Binding SaveCommand}" />
</StackPanel>
</StackPanel> </StackPanel>
</StackPanel> </Viewbox>
</UserControl> </UserControl>
+5
View File
@@ -1,4 +1,5 @@
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows;
namespace TV_Player namespace TV_Player
{ {
@@ -11,5 +12,9 @@ namespace TV_Player
{ {
InitializeComponent(); InitializeComponent();
} }
private void OpenAddPlayList_Click(object sender, System.Windows.RoutedEventArgs e) => AddPlayList.Visibility = Visibility.Visible;
private void AddPlayList_Click(object sender, RoutedEventArgs e) => AddPlayList.Visibility = Visibility.Collapsed;
} }
} }
+34 -4
View File
@@ -1,10 +1,18 @@
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using System.Collections.ObjectModel;
using System.Windows.Input; using System.Windows.Input;
namespace TV_Player.ViewModels namespace TV_Player.ViewModels
{ {
internal class SettingsViewModel : ObservableViewModelBase internal class SettingsViewModel : ObservableViewModelBase
{ {
private string _playlistName;
public string PlaylistName
{
get => _playlistName;
set => SetProperty(ref _playlistName, value);
}
private string _playlistURL; private string _playlistURL;
public string PlaylistURL public string PlaylistURL
{ {
@@ -12,6 +20,13 @@ namespace TV_Player.ViewModels
set => SetProperty(ref _playlistURL, value); set => SetProperty(ref _playlistURL, value);
} }
private ObservableCollection<KeyValuePair<string, string>> _playlists;
public ObservableCollection<KeyValuePair<string, string>> Playlists
{
get => _playlists;
set => SetProperty(ref _playlists, value);
}
private bool _startFullScreen; private bool _startFullScreen;
public bool StartFullScreen public bool StartFullScreen
{ {
@@ -27,7 +42,9 @@ namespace TV_Player.ViewModels
} }
public ICommand SaveCommand { get; } public ICommand SaveCommand { get; }
public ICommand PlaylistDeleteCommand { get; }
public ICommand BackCommand { get; } public ICommand BackCommand { get; }
public ICommand AddPlaylistCommand { get; }
public SettingsViewModel() public SettingsViewModel()
{ {
@@ -35,12 +52,25 @@ namespace TV_Player.ViewModels
SaveCommand = new RelayCommand(OnSaveSettings); SaveCommand = new RelayCommand(OnSaveSettings);
BackCommand = new RelayCommand(OnBackCommand); BackCommand = new RelayCommand(OnBackCommand);
AddPlaylistCommand = new RelayCommand(OnAddPlaylistCommand);
PlaylistDeleteCommand = new RelayCommand<KeyValuePair<string, string>>(OnPlaylistDeleteCommand);
StartFullScreen = SettingsModel.StartFullScreen; StartFullScreen = SettingsModel.StartFullScreen;
StartLastScreen = SettingsModel.StartFromLastScreen; StartLastScreen = SettingsModel.StartFromLastScreen;
// PlaylistURL = SettingsModel.PlaylistURL; Playlists = new ObservableCollection<KeyValuePair<string, string>>(SettingsModel.Playlists);
} }
private void OnAddPlaylistCommand()
{
Playlists.Add(new KeyValuePair<string, string>(PlaylistName, PlaylistURL));
}
private void OnPlaylistDeleteCommand(KeyValuePair<string, string> pair)
{
Playlists.Remove(pair);
}
private void OnBackCommand() private void OnBackCommand()
{ {
TVPlayerViewModel.Instance.SelectScreen(); TVPlayerViewModel.Instance.SelectScreen();
@@ -50,10 +80,10 @@ namespace TV_Player.ViewModels
{ {
SettingsModel.StartFullScreen = StartFullScreen; SettingsModel.StartFullScreen = StartFullScreen;
SettingsModel.StartFromLastScreen = StartLastScreen; SettingsModel.StartFromLastScreen = StartLastScreen;
//SettingsModel.PlaylistURL = PlaylistURL; SettingsModel.Playlists.Clear();
SettingsModel.Playlists = Playlists.ToDictionary<string, string>();
SettingsModel.SaveSetttings(); SettingsModel.SaveSetttings();
TVPlayerViewModel.Instance.InitializeTVWithData(); TVPlayerViewModel.Instance.InitializeTVWithData();
} }
} }
} }
@@ -44,7 +44,8 @@ namespace TV_Player.ViewModels
{ {
if (SettingsModel.Playlists!=null && SettingsModel.Playlists.Any()) if (SettingsModel.Playlists!=null && SettingsModel.Playlists.Any())
{ {
foreach(var playlist in SettingsModel.Playlists) PlayListsData.Clear();
foreach (var playlist in SettingsModel.Playlists)
{ {
PlayListsData.Add(playlist.Key, new ProgramsData(playlist.Key,playlist.Value)); PlayListsData.Add(playlist.Key, new ProgramsData(playlist.Key,playlist.Value));
} }